1
|
/**
|
2
|
* Copyright (C) 2018 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.ext.registration.messages.redmine;
|
10
|
|
11
|
import static org.junit.Assert.assertEquals;
|
12
|
import static org.junit.Assert.assertNotNull;
|
13
|
import static org.junit.Assert.assertNull;
|
14
|
import static org.junit.Assert.assertTrue;
|
15
|
|
16
|
import java.io.FileNotFoundException;
|
17
|
import java.util.Arrays;
|
18
|
import java.util.HashMap;
|
19
|
import java.util.List;
|
20
|
import java.util.Map;
|
21
|
|
22
|
import org.junit.Before;
|
23
|
import org.junit.Test;
|
24
|
import org.junit.runner.RunWith;
|
25
|
import org.unitils.AlternativeUnitilsJUnit4TestClassRunner;
|
26
|
import org.unitils.dbunit.annotation.DataSet;
|
27
|
import org.unitils.spring.annotation.SpringBeanByType;
|
28
|
|
29
|
import com.taskadapter.redmineapi.RedmineException;
|
30
|
import com.taskadapter.redmineapi.bean.Issue;
|
31
|
import com.taskadapter.redmineapi.internal.ResultsWrapper;
|
32
|
|
33
|
import eu.etaxonomy.cdm.SpringProxyBeanHelper;
|
34
|
import eu.etaxonomy.cdm.api.service.INameService;
|
35
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
36
|
import eu.etaxonomy.cdm.api.service.IRegistrationService;
|
37
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
38
|
import eu.etaxonomy.cdm.api.service.IUserService;
|
39
|
import eu.etaxonomy.cdm.ext.common.ExternalServiceException;
|
40
|
import eu.etaxonomy.cdm.ext.registration.messages.IRegistrationMessageService;
|
41
|
import eu.etaxonomy.cdm.ext.registration.messages.Message;
|
42
|
import eu.etaxonomy.cdm.model.agent.Team;
|
43
|
import eu.etaxonomy.cdm.model.common.Extension;
|
44
|
import eu.etaxonomy.cdm.model.common.User;
|
45
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
46
|
import eu.etaxonomy.cdm.model.name.Rank;
|
47
|
import eu.etaxonomy.cdm.model.name.Registration;
|
48
|
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
|
49
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
50
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
51
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
52
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
53
|
|
54
|
/**
|
55
|
* @author a.kohlbecker
|
56
|
* @since Feb 16, 2018
|
57
|
*
|
58
|
*/
|
59
|
@RunWith(AlternativeUnitilsJUnit4TestClassRunner.class)
|
60
|
public class RedmineRegistrationMessageServiceTest extends CdmTransactionalIntegrationTest {
|
61
|
|
62
|
private static final String CURATOR = "curator";
|
63
|
|
64
|
private static final String SUBMITTER = "submitter";
|
65
|
|
66
|
private static final String EMAIL_DOMAIN = "@localhost.bgbm.fu-berlin.de";
|
67
|
|
68
|
|
69
|
private static final int REGISTRATION_1_ID = 5000;
|
70
|
private static final int REGISTRATION_2_ID = 5001;
|
71
|
|
72
|
@SpringBeanByType
|
73
|
IUserService userService;
|
74
|
|
75
|
@SpringBeanByType
|
76
|
ITermService termService;
|
77
|
|
78
|
@SpringBeanByType
|
79
|
IReferenceService referenceService;
|
80
|
|
81
|
@SpringBeanByType
|
82
|
IRegistrationService registrationService;
|
83
|
|
84
|
@SpringBeanByType
|
85
|
INameService nameService;
|
86
|
|
87
|
private RedmineRegistrationMessageService messageService;
|
88
|
|
89
|
@SpringBeanByType
|
90
|
public void setIRegistrationMessageService(IRegistrationMessageService messageService) throws Exception {
|
91
|
|
92
|
this.messageService = SpringProxyBeanHelper.getTargetObject(messageService, RedmineRegistrationMessageService.class);
|
93
|
|
94
|
}
|
95
|
|
96
|
|
97
|
private final String[] includeTableNames_create = new String[]{
|
98
|
"TAXONNAME", "REFERENCE", "AGENTBASE", "HOMOTYPICALGROUP", "REGISTRATION",
|
99
|
"USERACCOUNT",
|
100
|
"HIBERNATE_SEQUENCES"};
|
101
|
|
102
|
@Before
|
103
|
public void cleanupRedmine() throws RedmineException{
|
104
|
|
105
|
nameService.getSession().clear();
|
106
|
|
107
|
for(com.taskadapter.redmineapi.bean.User user: messageService.redmineManager().getUserManager().getUsers()){
|
108
|
if(user.getLogin().equals(SUBMITTER) || user.getLogin().equals(CURATOR)){
|
109
|
messageService.redmineManager().getUserManager().deleteUser(user.getId());
|
110
|
}
|
111
|
}
|
112
|
Map<String,String> params = new HashMap<>();
|
113
|
params.put("offset", "0");
|
114
|
params.put("limit", "100");
|
115
|
params.put("status_id", "*"); // * to get open and closed issues
|
116
|
while(true){
|
117
|
ResultsWrapper<Issue> result = messageService.redmineManager().getIssueManager().getIssues(params);
|
118
|
if(result.getResultsNumber() == 0){
|
119
|
break;
|
120
|
}
|
121
|
for(Issue issue : result.getResults()){
|
122
|
messageService.redmineManager().getIssueManager().deleteIssue(issue.getId());
|
123
|
}
|
124
|
}
|
125
|
}
|
126
|
|
127
|
@Test
|
128
|
@DataSet
|
129
|
public void testCreateUser() throws RedmineException, ExternalServiceException{
|
130
|
|
131
|
User submitter = (User) userService.loadUserByUsername(SUBMITTER);
|
132
|
|
133
|
com.taskadapter.redmineapi.bean.User createdUser = null;
|
134
|
|
135
|
createdUser = messageService.createUser(submitter);
|
136
|
|
137
|
assertNotNull(createdUser);
|
138
|
assertEquals(submitter.getUsername(), createdUser.getLogin());
|
139
|
assertNotNull(createdUser.getId());
|
140
|
|
141
|
User submitterReloaded = userService.load(submitter.getUuid(), Arrays.asList("person.extensions.$"));
|
142
|
assertEquals(1, submitterReloaded.getPerson().getExtensions().size());
|
143
|
Extension extension = submitterReloaded.getPerson().getExtensions().iterator().next();
|
144
|
assertEquals(RedmineRegistrationMessageService.EXTTYPE_REGMESG_REDMINEUID_UUID, extension.getType().getUuid());
|
145
|
assertEquals(createdUser.getId(), Integer.valueOf(extension.getValue()));
|
146
|
|
147
|
}
|
148
|
|
149
|
/**
|
150
|
* For this to work the workflow needs to be
|
151
|
* configured https://dev.e-taxonomy.eu/redmine/attachments/download/1177/picture68-1.png
|
152
|
*
|
153
|
* @throws RedmineException
|
154
|
* @throws ExternalServiceException
|
155
|
*/
|
156
|
@Test
|
157
|
@DataSet
|
158
|
public void testUpdateRegistrationStatus() throws RedmineException, ExternalServiceException{
|
159
|
|
160
|
Issue issue = null;
|
161
|
|
162
|
User submitter = (User) userService.loadUserByUsername(SUBMITTER);
|
163
|
|
164
|
User curator = (User) userService.loadUserByUsername(CURATOR);
|
165
|
|
166
|
if(!(submitter.getEmailAddress().equals(SUBMITTER + EMAIL_DOMAIN) && curator.getEmailAddress().equals(CURATOR + EMAIL_DOMAIN ))){
|
167
|
throw new AssertionError("Email adresses must be '" + SUBMITTER + EMAIL_DOMAIN + "' and '" + CURATOR + EMAIL_DOMAIN + "',"
|
168
|
+ " for futher information please refer to https://dev.e-taxonomy.eu/redmine/issues/7280");
|
169
|
}
|
170
|
|
171
|
|
172
|
Registration reg = registrationService.load(REGISTRATION_1_ID, Arrays.asList("$"));
|
173
|
issue = messageService.createIssue(reg);
|
174
|
reg.setStatus(RegistrationStatus.READY);
|
175
|
messageService.updateIssueStatus(reg);
|
176
|
issue = messageService.findIssue(reg, false);
|
177
|
assertEquals("ready", issue.getStatusName());
|
178
|
|
179
|
|
180
|
}
|
181
|
|
182
|
@Test
|
183
|
@DataSet
|
184
|
public void testMessageWorkflow() throws RedmineException, ExternalServiceException{
|
185
|
|
186
|
User submitter = (User) userService.loadUserByUsername(SUBMITTER);
|
187
|
|
188
|
User curator = (User) userService.loadUserByUsername(CURATOR);
|
189
|
|
190
|
Registration reg1 = registrationService.load(REGISTRATION_1_ID, Arrays.asList("$"));
|
191
|
|
192
|
assertNotNull(reg1.getIdentifier());
|
193
|
assertNotNull(reg1.getSubmitter());
|
194
|
|
195
|
Registration reg2 = registrationService.load(REGISTRATION_2_ID, Arrays.asList("$"));
|
196
|
assertNotNull(reg2.getIdentifier());
|
197
|
assertNotNull(reg2.getSubmitter());
|
198
|
|
199
|
Issue issue = null;
|
200
|
com.taskadapter.redmineapi.bean.User redmineCurator = null;
|
201
|
com.taskadapter.redmineapi.bean.User redmineSubmitter = null;
|
202
|
|
203
|
assertEquals(0, messageService.countActiveMessagesFor(reg1, curator));
|
204
|
assertEquals(0, messageService.countActiveMessagesFor(reg1, submitter));
|
205
|
|
206
|
// post a message, this will create an issue and will add a comment
|
207
|
String messageText1 = "hey submitter how is life in a test environment?";
|
208
|
messageService.postMessage(reg1, messageText1, curator, submitter);
|
209
|
issue = messageService.findIssue(reg1, false);
|
210
|
assertTrue(issue.isPrivateIssue());
|
211
|
redmineCurator = messageService.findUser(curator);
|
212
|
redmineSubmitter = messageService.findUser(submitter);
|
213
|
assertEquals(redmineSubmitter.getId(), issue.getAssigneeId());
|
214
|
assertEquals(redmineCurator.getId(), Integer.valueOf(issue.getCustomFieldByName("Curator").getValue()));
|
215
|
|
216
|
assertEquals(1, messageService.countActiveMessagesFor(reg1, submitter));
|
217
|
|
218
|
// now post a message for another registration
|
219
|
String messageText0 = "hey submitter this registration is so excellent that I am in complete admiration of your work.";
|
220
|
messageService.postMessage(reg2, messageText0, curator, submitter);
|
221
|
issue = messageService.findIssue(reg2, false);
|
222
|
assertEquals(reg2.getIdentifier(), issue.getCustomFieldById(1).getValue());
|
223
|
|
224
|
// 2. post a message back to curator
|
225
|
String messageText2 = "pretty boring in here. It is horrible. If you know a way out of here, please help!";
|
226
|
messageService.postMessage(reg1, messageText2, submitter, curator);
|
227
|
issue = messageService.findIssue(reg1, false);
|
228
|
assertEquals(redmineCurator.getId(), issue.getAssigneeId());
|
229
|
assertEquals(1, messageService.countActiveMessagesFor(reg1, curator));
|
230
|
assertEquals(0, messageService.countActiveMessagesFor(reg1, submitter));
|
231
|
|
232
|
// 3. post a message back submitter
|
233
|
String messageText3 = "Dear Submitter, the only solution it to end this test, hold on, just a millisec ...";
|
234
|
messageService.postMessage(reg1, messageText3, curator, submitter);
|
235
|
issue = messageService.findIssue(reg1, false);
|
236
|
assertEquals(redmineSubmitter.getId(), issue.getAssigneeId());
|
237
|
assertEquals(0, messageService.countActiveMessagesFor(reg1, curator));
|
238
|
assertEquals(2, messageService.countActiveMessagesFor(reg1, submitter));
|
239
|
|
240
|
// 4. inactivate messages
|
241
|
messageService.inactivateMessages(reg1);
|
242
|
issue = messageService.findIssue(reg1, false);
|
243
|
assertNull(issue.getAssigneeName());
|
244
|
assertEquals(0, messageService.countActiveMessagesFor(reg1, curator));
|
245
|
assertEquals(0, messageService.countActiveMessagesFor(reg1, submitter));
|
246
|
|
247
|
List<Message> messages = messageService.listMessages(reg1);
|
248
|
assertEquals(3, messages.size());
|
249
|
|
250
|
// 5. registration becomes rejected
|
251
|
reg1.setStatus(RegistrationStatus.REJECTED);
|
252
|
messageService.updateIssueStatus(reg1);
|
253
|
issue = messageService.findIssue(reg1, false);
|
254
|
assertEquals("rejected", issue.getStatusName());
|
255
|
|
256
|
// 6. check all the messages in this issue
|
257
|
assertEquals(messageText1, messages.get(0).getText());
|
258
|
assertEquals(curator, messages.get(0).getFrom());
|
259
|
|
260
|
assertEquals(messageText2, messages.get(1).getText());
|
261
|
assertEquals(submitter, messages.get(1).getFrom());
|
262
|
|
263
|
assertEquals(messageText3, messages.get(2).getText());
|
264
|
assertEquals(curator, messages.get(2).getFrom());
|
265
|
|
266
|
|
267
|
}
|
268
|
|
269
|
|
270
|
|
271
|
/**
|
272
|
* {@inheritDoc}
|
273
|
*/
|
274
|
@Override
|
275
|
// @Test
|
276
|
public void createTestDataSet() throws FileNotFoundException {
|
277
|
|
278
|
User submitter = User.NewInstance("Submitter", SUBMITTER, "geheim");
|
279
|
submitter.setEmailAddress(SUBMITTER + EMAIL_DOMAIN);
|
280
|
|
281
|
User curator = User.NewInstance("Curator", CURATOR, "geheim");
|
282
|
curator.setEmailAddress(CURATOR + EMAIL_DOMAIN);
|
283
|
|
284
|
submitter = userService.save(submitter);
|
285
|
userService.save(curator);
|
286
|
|
287
|
|
288
|
Team team = Team.NewTitledInstance("Novis, Braidwood & Kilroy", "Novis, Braidwood & Kilroy");
|
289
|
Reference nomRef = ReferenceFactory.newArticle();
|
290
|
nomRef = referenceService.save(nomRef);
|
291
|
nomRef.setAuthorship(team);
|
292
|
nomRef.setTitle("P.M. Novis, J. Braidwood & C. Kilroy, Small diatoms (Bacillariophyta) in cultures from the Styx River, New Zealand, including descriptions of three new species in Phytotaxa 64");
|
293
|
TaxonName name = TaxonName.NewInstance(NomenclaturalCode.ICNAFP, Rank.SPECIES(), "Planothidium", null, "victori", null, null, nomRef, "11-45", null);
|
294
|
name = nameService.save(name);
|
295
|
|
296
|
Team team2 = Team.NewTitledInstance("H.U.Ling & Seppelt", "H.U.Ling & Seppelt");
|
297
|
Reference nomRef2 = ReferenceFactory.newArticle();
|
298
|
nomRef2 = referenceService.save(nomRef2);
|
299
|
nomRef2.setAuthorship(team2);
|
300
|
nomRef2.setTitle("H.U.Ling & Seppelt in Algol. Stud. 89");
|
301
|
TaxonName name2 = TaxonName.NewInstance(NomenclaturalCode.ICNAFP, Rank.SPECIES(), "Apodochloris", null, "irregularis", null, null, nomRef2, "55", null);
|
302
|
name2 = nameService.save(name2);
|
303
|
|
304
|
Registration reg = Registration.NewInstance();
|
305
|
reg.setName(name);
|
306
|
reg.setSubmitter(submitter);
|
307
|
reg.setIdentifier("http://phycotest.com/10815");
|
308
|
reg = registrationService.save(reg);
|
309
|
|
310
|
|
311
|
Registration reg2 = Registration.NewInstance();
|
312
|
reg2.setName(name2);
|
313
|
reg2.setSubmitter(submitter);
|
314
|
reg2.setIdentifier("http://phycotest.com/10999");
|
315
|
reg2 = registrationService.save(reg2);
|
316
|
|
317
|
//printDataSetWithNull(System.err, includeTableNames_create);
|
318
|
|
319
|
commit();
|
320
|
|
321
|
writeDbUnitDataSetFile(includeTableNames_create);
|
322
|
|
323
|
}
|
324
|
|
325
|
}
|