1
|
/**
|
2
|
* Copyright (C) 2019 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.api.service;
|
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.Collection;
|
19
|
import java.util.HashSet;
|
20
|
import java.util.List;
|
21
|
import java.util.UUID;
|
22
|
|
23
|
import org.junit.Test;
|
24
|
import org.springframework.beans.factory.annotation.Qualifier;
|
25
|
import org.unitils.dbunit.annotation.DataSet;
|
26
|
import org.unitils.spring.annotation.SpringBeanByType;
|
27
|
|
28
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
29
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
30
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
31
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
|
32
|
import eu.etaxonomy.cdm.model.name.Rank;
|
33
|
import eu.etaxonomy.cdm.model.name.Registration;
|
34
|
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
|
35
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
36
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
|
37
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
38
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
39
|
import eu.etaxonomy.cdm.model.permission.User;
|
40
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
41
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
42
|
import eu.etaxonomy.cdm.persistence.permission.Role;
|
43
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
44
|
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
|
45
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTestWithSecurity;
|
46
|
|
47
|
/**
|
48
|
* @author a.kohlbecker
|
49
|
* @since Jun 28, 2019
|
50
|
*/
|
51
|
public class RegistrationServiceTest extends CdmTransactionalIntegrationTestWithSecurity {
|
52
|
|
53
|
public static final UUID USER2_UUID = UUID.fromString("669f582c-e97f-425b-97f6-bc3b0c08f2a5");
|
54
|
|
55
|
public static final UUID USER1_UUID = UUID.fromString("68033f81-9947-4b61-b33b-3d05bd438579");
|
56
|
|
57
|
public static final UUID NDT1_UUID = UUID.fromString("be66964a-ea2b-480e-9dcf-0ee1dd7313eb");
|
58
|
|
59
|
public static final UUID STD2_UUID = UUID.fromString("8cd056fb-259a-45aa-ab4f-b34033eef2e9");
|
60
|
|
61
|
public static final UUID STD1_UUID = UUID.fromString("1c29e80a-2611-4be4-9b2f-15bbd15066bf");
|
62
|
|
63
|
public static final UUID NAME1_UUID = UUID.fromString("6ffa3217-f520-43d9-99d7-755b8c11d049");
|
64
|
|
65
|
public static final UUID NAME2_UUID = UUID.fromString("c739163e-c1fa-4ea6-b992-78fe050a6d2c");
|
66
|
|
67
|
public static final UUID NAME3_UUID = UUID.fromString("fdcaf5a8-aa6d-4f5c-86e5-6e3d93dc0c72");
|
68
|
|
69
|
@SpringBeanByType
|
70
|
@Qualifier("CdmRepository")
|
71
|
private ICdmRepository repo;
|
72
|
|
73
|
@Test
|
74
|
@DataSet
|
75
|
public void testPageWithPatternFilters(){
|
76
|
|
77
|
OrderHint orderBySpecificIdentifier = new OrderHint("specificIdentifier", SortOrder.ASCENDING);
|
78
|
// OrderHint orderById = new OrderHint("id", SortOrder.ASCENDING);
|
79
|
|
80
|
repo.authenticate("user1", "00000");
|
81
|
|
82
|
Pager<Registration> pager;
|
83
|
|
84
|
pager = repo.getRegistrationService().page((UUID)null, null, null, null, null, null, null, null, null, null);
|
85
|
assertEquals(pager.getRecords().size(), pager.getCount().intValue());
|
86
|
assertEquals("with authenticated user expecting all 4 Registrations", 4l, pager.getCount().longValue());
|
87
|
|
88
|
pager = repo.getRegistrationService().page(USER1_UUID, null, null, null, null, null, null, null, null, null);
|
89
|
assertEquals(2l, pager.getCount().longValue());
|
90
|
|
91
|
pager = repo.getRegistrationService().page(USER2_UUID, null, null, null, null, null, null, null, null, null);
|
92
|
assertEquals(2l, pager.getCount().longValue());
|
93
|
|
94
|
// status filter
|
95
|
pager = repo.getRegistrationService().page((UUID)null, Arrays.asList(RegistrationStatus.PREPARATION), null, null, null, null, null, null, null, null);
|
96
|
assertEquals(1l, pager.getCount().longValue());
|
97
|
assertEquals(RegistrationStatus.PREPARATION, pager.getRecords().get(0).getStatus());
|
98
|
|
99
|
pager = repo.getRegistrationService().page((UUID)null, Arrays.asList(RegistrationStatus.PREPARATION, RegistrationStatus.PUBLISHED), null, null, null, null, null, null, null, null);
|
100
|
assertEquals(2l, pager.getCount().longValue());
|
101
|
|
102
|
// status filter with submitter
|
103
|
pager = repo.getRegistrationService().page(USER1_UUID, Arrays.asList(RegistrationStatus.PREPARATION, RegistrationStatus.PUBLISHED), null, null, null, null, null, null, null, null);
|
104
|
assertEquals(2l, pager.getCount().longValue());
|
105
|
|
106
|
pager = repo.getRegistrationService().page(USER2_UUID, Arrays.asList(RegistrationStatus.PREPARATION, RegistrationStatus.PUBLISHED), null, null, null, null, null, null, null, null);
|
107
|
assertEquals(0l, pager.getCount().longValue());
|
108
|
|
109
|
pager = repo.getRegistrationService().page(USER2_UUID, Arrays.asList(RegistrationStatus.CURATION), null, null, null, null, null, null, null, null);
|
110
|
assertEquals(1l, pager.getCount().longValue());
|
111
|
|
112
|
// identifier filter
|
113
|
pager = repo.getRegistrationService().page((UUID)null, null, "100", null, null, null, null, null, null, null);
|
114
|
assertEquals(4l, pager.getCount().longValue());
|
115
|
|
116
|
pager = repo.getRegistrationService().page((UUID)null, null, "test/1001", null, null, null, null, null, null, null);
|
117
|
assertEquals(1l, pager.getCount().longValue());
|
118
|
|
119
|
// identifier filter with submitter
|
120
|
pager = repo.getRegistrationService().page(USER1_UUID, null, "100", null, null, null, null, null, null, null);
|
121
|
assertEquals(2l, pager.getCount().longValue());
|
122
|
|
123
|
pager = repo.getRegistrationService().page(USER2_UUID, null, "1002", null, null, null, null, null, null, null);
|
124
|
assertEquals(1l, pager.getCount().longValue());
|
125
|
|
126
|
// taxon name filter
|
127
|
pager = repo.getRegistrationService().page((UUID)null, null, null, "Digitalus", null, null, null, null, null, null);
|
128
|
assertEquals(4l, pager.getCount().longValue());
|
129
|
|
130
|
pager = repo.getRegistrationService().page((UUID)null, null, null, "Dig*lus", null, null, null, null, null, null);
|
131
|
assertEquals(4l, pager.getCount().longValue());
|
132
|
|
133
|
pager = repo.getRegistrationService().page((UUID)null, null, null, "Digitalus prim", null, null, null, null, null, null);
|
134
|
assertEquals(1l, pager.getCount().longValue());
|
135
|
|
136
|
pager = repo.getRegistrationService().page((UUID)null, null, null, "Digitalus secundus", null, null, null, null, Arrays.asList(orderBySpecificIdentifier), null);
|
137
|
assertEquals(2l, pager.getCount().longValue());
|
138
|
|
139
|
assertEquals("test/1001", pager.getRecords().get(0).getIdentifier());
|
140
|
assertNotNull("expecting registration test/1001 to be with name", pager.getRecords().get(0).getName());
|
141
|
assertTrue("expecting registration test/1001 to be witout type designation", pager.getRecords().get(0).getTypeDesignations().isEmpty());
|
142
|
|
143
|
assertEquals("test/1003", pager.getRecords().get(1).getIdentifier());
|
144
|
assertNull("Expecting the registration test/1003 to be without name", pager.getRecords().get(1).getName());
|
145
|
assertEquals(STD2_UUID, pager.getRecords().get(1).getTypeDesignations().iterator().next().getUuid());
|
146
|
|
147
|
pager = repo.getRegistrationService().page((UUID)null, null, null, "Digita*", null, null, null, null, null, null);
|
148
|
assertEquals(4l, pager.getCount().longValue());
|
149
|
|
150
|
pager = repo.getRegistrationService().page((UUID)null, null, null, "*imus", null, null, null, null, null, null);
|
151
|
assertEquals(1l, pager.getCount().longValue());
|
152
|
|
153
|
// taxon name filter with user
|
154
|
pager = repo.getRegistrationService().page(USER2_UUID, null, null, "Digitalus", null, null, null, null, null, null);
|
155
|
assertEquals(2l, pager.getCount().longValue());
|
156
|
|
157
|
// taxon name filter with user and status
|
158
|
pager = repo.getRegistrationService().page(USER1_UUID, Arrays.asList(RegistrationStatus.PREPARATION), null, "Digitalus", null, null, null, null, null, null);
|
159
|
assertEquals(1l, pager.getCount().longValue());
|
160
|
|
161
|
pager = repo.getRegistrationService().page(USER1_UUID, Arrays.asList(RegistrationStatus.PREPARATION, RegistrationStatus.PUBLISHED), "1001", "Digitalus", null, null, null, null, null, null);
|
162
|
assertEquals(1l, pager.getCount().longValue());
|
163
|
|
164
|
// type designation status
|
165
|
|
166
|
// assure the terms are loaded
|
167
|
assertNotNull(SpecimenTypeDesignationStatus.HOLOTYPE());
|
168
|
assertNotNull(NameTypeDesignationStatus.TAUTONYMY());
|
169
|
|
170
|
pager = repo.getRegistrationService().page((UUID)null, null, null, null, null,
|
171
|
Arrays.asList(SpecimenTypeDesignationStatus.HOLOTYPE().getUuid()), null, null, null, null);
|
172
|
assertEquals(1l, pager.getCount().longValue());
|
173
|
assertEquals(STD1_UUID, pager.getRecords().get(0).getTypeDesignations().iterator().next().getUuid());
|
174
|
|
175
|
pager = repo.getRegistrationService().page((UUID)null, null, null, null, null,
|
176
|
Arrays.asList(NameTypeDesignationStatus.TAUTONYMY().getUuid()), null, null, Arrays.asList(orderBySpecificIdentifier), null);
|
177
|
assertEquals(1l, pager.getCount().longValue());
|
178
|
assertEquals(NDT1_UUID, pager.getRecords().get(0).getTypeDesignations().iterator().next().getUuid());
|
179
|
|
180
|
pager = repo.getRegistrationService().page((UUID)null, null, null, null, null,
|
181
|
Arrays.asList(SpecimenTypeDesignationStatus.HOLOTYPE().getUuid(), NameTypeDesignationStatus.TAUTONYMY().getUuid()), null, null, Arrays.asList(orderBySpecificIdentifier), null);
|
182
|
assertEquals(2l, pager.getCount().longValue());
|
183
|
assertEquals("test/1000", pager.getRecords().get(0).getIdentifier());
|
184
|
assertEquals(STD1_UUID, pager.getRecords().get(0).getTypeDesignations().iterator().next().getUuid());
|
185
|
assertEquals("test/1002", pager.getRecords().get(1).getIdentifier());
|
186
|
assertEquals(NDT1_UUID, pager.getRecords().get(1).getTypeDesignations().iterator().next().getUuid());
|
187
|
|
188
|
// type designation status with user
|
189
|
pager = repo.getRegistrationService().page(USER2_UUID, null, null, null, null,
|
190
|
Arrays.asList(SpecimenTypeDesignationStatus.HOLOTYPE().getUuid(), NameTypeDesignationStatus.TAUTONYMY().getUuid()), null, null, null, null);
|
191
|
assertEquals(1l, pager.getCount().longValue());
|
192
|
assertEquals(NDT1_UUID, pager.getRecords().get(0).getTypeDesignations().iterator().next().getUuid());
|
193
|
|
194
|
// type designation status with name
|
195
|
pager = repo.getRegistrationService().page((UUID)null, null, null, "Digital",
|
196
|
null,
|
197
|
Arrays.asList(SpecimenTypeDesignationStatus.HOLOTYPE().getUuid(), NameTypeDesignationStatus.TAUTONYMY().getUuid()), null, null, Arrays.asList(orderBySpecificIdentifier), null);
|
198
|
assertEquals(2l, pager.getCount().longValue());
|
199
|
assertEquals(STD1_UUID, pager.getRecords().get(0).getTypeDesignations().iterator().next().getUuid());
|
200
|
assertEquals(NDT1_UUID, pager.getRecords().get(1).getTypeDesignations().iterator().next().getUuid());
|
201
|
|
202
|
// reference
|
203
|
pager = repo.getRegistrationService().page((UUID)null, null, null, null,
|
204
|
"book1", null, null, null, Arrays.asList(orderBySpecificIdentifier), null);
|
205
|
assertEquals(2l, pager.getCount().longValue());
|
206
|
|
207
|
pager = repo.getRegistrationService().page((UUID)null, null, null, null,
|
208
|
"book*", null, null, null, Arrays.asList(orderBySpecificIdentifier), null);
|
209
|
assertEquals(4l, pager.getCount().longValue());
|
210
|
}
|
211
|
|
212
|
@Test
|
213
|
@DataSet
|
214
|
public void testPageByNameUUID(){
|
215
|
|
216
|
OrderHint orderBySpecificIdentifier = new OrderHint("specificIdentifier", SortOrder.ASCENDING);
|
217
|
OrderHint orderById = new OrderHint("id", SortOrder.ASCENDING);
|
218
|
|
219
|
repo.authenticate("user1", "00000");
|
220
|
|
221
|
Pager<Registration> pager;
|
222
|
|
223
|
List<UUID> nameUuids = Arrays.asList(NAME2_UUID);
|
224
|
|
225
|
pager = repo.getRegistrationService().page((UUID)null, null, nameUuids, null, null, Arrays.asList(orderBySpecificIdentifier), null);
|
226
|
assertEquals(2l, pager.getCount().longValue());
|
227
|
assertEquals("test/1001", pager.getRecords().get(0).getIdentifier());
|
228
|
assertEquals("test/1003", pager.getRecords().get(1).getIdentifier());
|
229
|
}
|
230
|
|
231
|
@Test
|
232
|
public void testPageByNameUUID_unautheticated(){
|
233
|
Collection<UUID> nameUuids = null;
|
234
|
Pager<Registration> pager = repo.getRegistrationService().page((UUID)null, null, nameUuids , null, null, null, null);
|
235
|
assertEquals(pager.getRecords().size(), pager.getCount().intValue());
|
236
|
assertEquals("expecting no Registration, since the user is not authenticated", 0l, pager.getCount().longValue());
|
237
|
}
|
238
|
|
239
|
|
240
|
@Test
|
241
|
public void testPageWithPatternFilters_unautheticated(){
|
242
|
Pager<Registration> pager = repo.getRegistrationService().page((UUID)null, null, null, null, null, null, null, null, null, null);
|
243
|
assertEquals(pager.getRecords().size(), pager.getCount().intValue());
|
244
|
assertEquals("expecting only the PUBLISHED Registration, since the user is not authenticated", 1l, pager.getCount().longValue());
|
245
|
}
|
246
|
|
247
|
@Override
|
248
|
// @Test
|
249
|
public void createTestDataSet() throws FileNotFoundException {
|
250
|
|
251
|
User user1 = User.NewInstance("user1", "00000");
|
252
|
User user2 = User.NewInstance("user2", "00000");
|
253
|
// granted authorities are irrelevant for the test but are required to allow creating the test data
|
254
|
user1.getAuthorities().add(Role.ROLE_ADMIN);
|
255
|
user2.getAuthorities().add(Role.ROLE_ADMIN);
|
256
|
user1.setUuid(USER1_UUID);
|
257
|
user2.setUuid(USER2_UUID);
|
258
|
repo.getUserService().save(user1);
|
259
|
repo.getUserService().save(user2);
|
260
|
|
261
|
Reference book1 = ReferenceFactory.newBook();
|
262
|
book1.setTitle("book1");
|
263
|
Reference book2 = ReferenceFactory.newBook();
|
264
|
book2.setTitle("book2");
|
265
|
repo.getReferenceService().save(book1);
|
266
|
repo.getReferenceService().save(book2);
|
267
|
|
268
|
TaxonName species1 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES(), "Digitalus", null, "primus", null, null, book1, "11", null);
|
269
|
species1.setUuid(NAME1_UUID);
|
270
|
TaxonName species2 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES(), "Digitalus", null, "secundus", null, null, book2, "22", null);
|
271
|
species2.setUuid(NAME2_UUID);
|
272
|
TaxonName genus = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS(), "Digitalus", null, null, null, null, book1, "33", null);
|
273
|
genus.setUuid(NAME2_UUID);
|
274
|
repo.getNameService().save(Arrays.asList(species1, species2, genus));
|
275
|
|
276
|
SpecimenTypeDesignation std1 = SpecimenTypeDesignation.NewInstance();
|
277
|
std1.setCitation(book1);
|
278
|
std1.setUuid(STD1_UUID);
|
279
|
std1.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
|
280
|
|
281
|
SpecimenTypeDesignation std2 = SpecimenTypeDesignation.NewInstance();
|
282
|
std2.setCitation(book2);
|
283
|
std2.setUuid(STD2_UUID);
|
284
|
std2.setTypeStatus(SpecimenTypeDesignationStatus.EPITYPE());
|
285
|
|
286
|
NameTypeDesignation ntd1 = NameTypeDesignation.NewInstance();
|
287
|
ntd1.setCitation(book1);
|
288
|
ntd1.setTypeName(species1);
|
289
|
ntd1.setUuid(NDT1_UUID);
|
290
|
ntd1.setTypeStatus(NameTypeDesignationStatus.TAUTONYMY());
|
291
|
|
292
|
genus.addTypeDesignation(ntd1, false);
|
293
|
species1.addTypeDesignation(std1, false);
|
294
|
species2.addTypeDesignation(std2, false);
|
295
|
|
296
|
repo.getNameService().saveOrUpdate(Arrays.asList(species1, species2, genus));
|
297
|
|
298
|
repo.authenticate("user1", "00000");
|
299
|
Registration reg1 = Registration.NewInstance("test/1000", "1000", species1, new HashSet(Arrays.asList(std1))); // --> book1
|
300
|
reg1.setStatus(RegistrationStatus.PUBLISHED);
|
301
|
// the authenticated user will be set as submitter in new Registrations
|
302
|
// see RegistrationServiceImpl.prepareForSave(Registration reg)
|
303
|
repo.getRegistrationService().save(reg1);
|
304
|
|
305
|
// the authenticated user will be set as submitter in new Registrations
|
306
|
// see RegistrationServiceImpl.prepareForSave(Registration reg)
|
307
|
Registration reg2 = Registration.NewInstance("test/1001", "1001", species2, null); // --> book2
|
308
|
reg2.setStatus(RegistrationStatus.PREPARATION);
|
309
|
repo.getRegistrationService().save(reg2);
|
310
|
|
311
|
repo.authenticate("user2", "00000");
|
312
|
// the authenticated user will be set as submitter in new Registrations
|
313
|
// see RegistrationServiceImpl.prepareForSave(Registration reg)
|
314
|
Registration reg3 = Registration.NewInstance("test/1002", "1002", genus, new HashSet(Arrays.asList(ntd1))); // --> book1
|
315
|
repo.getRegistrationService().save(reg3);
|
316
|
reg3.setStatus(RegistrationStatus.CURATION);
|
317
|
|
318
|
Registration reg4 = Registration.NewInstance("test/1003", "1003", null, new HashSet(Arrays.asList(std2))); // --> book2
|
319
|
repo.getRegistrationService().save(reg4);
|
320
|
reg4.setStatus(RegistrationStatus.READY);
|
321
|
|
322
|
// 2. end the transaction so that all data is actually written to the db
|
323
|
setComplete();
|
324
|
endTransaction();
|
325
|
|
326
|
// use the fileNameAppendix if you are creating a data set file which need to be named differently
|
327
|
// from the standard name. For example if a single test method needs different data then the other
|
328
|
// methods the test class you may want to set the fileNameAppendix when creating the data for this method.
|
329
|
String fileNameAppendix = null;
|
330
|
|
331
|
// 3.
|
332
|
writeDbUnitDataSetFile(new String[] {
|
333
|
"UserAccount",
|
334
|
"REFERENCE",
|
335
|
"Registration", "Registration_TypeDesignationBase",
|
336
|
"TaxonName", "TaxonName_TypeDesignationBase",
|
337
|
"TypeDesignationBase",
|
338
|
"AGENTBASE", "HOMOTYPICALGROUP",
|
339
|
"OriginalSourceBase",
|
340
|
"HIBERNATE_SEQUENCES" // IMPORTANT!!!
|
341
|
},
|
342
|
fileNameAppendix, true );
|
343
|
}
|
344
|
}
|