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.HashSet;
|
19
|
import java.util.List;
|
20
|
import java.util.UUID;
|
21
|
|
22
|
import org.junit.Test;
|
23
|
import org.springframework.beans.factory.annotation.Qualifier;
|
24
|
import org.unitils.dbunit.annotation.DataSet;
|
25
|
import org.unitils.spring.annotation.SpringBeanByType;
|
26
|
|
27
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
28
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
29
|
import eu.etaxonomy.cdm.model.common.User;
|
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.reference.Reference;
|
40
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
41
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
|
42
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
43
|
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
|
44
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTestWithSecurity;
|
45
|
|
46
|
/**
|
47
|
* @author a.kohlbecker
|
48
|
* @since Jun 28, 2019
|
49
|
*
|
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
|
|
232
|
@Test
|
233
|
public void PageWithPatternFilters_unautheticated(){
|
234
|
Pager<Registration> pager = repo.getRegistrationService().page((UUID)null, null, null, null, null, null, null, null, null, null);
|
235
|
assertEquals(pager.getRecords().size(), pager.getCount().intValue());
|
236
|
assertEquals("expecting only the PUBLISHED Registration, since the user is not authenticated", 1l, pager.getCount().longValue());
|
237
|
}
|
238
|
|
239
|
@Override
|
240
|
// @Test
|
241
|
public void createTestDataSet() throws FileNotFoundException {
|
242
|
|
243
|
User user1 = User.NewInstance("user1", "00000");
|
244
|
User user2 = User.NewInstance("user2", "00000");
|
245
|
// granted authorities are irrelevant for the test but are required to allow creating the test data
|
246
|
user1.getAuthorities().add(Role.ROLE_ADMIN);
|
247
|
user2.getAuthorities().add(Role.ROLE_ADMIN);
|
248
|
user1.setUuid(USER1_UUID);
|
249
|
user2.setUuid(USER2_UUID);
|
250
|
repo.getUserService().save(user1);
|
251
|
repo.getUserService().save(user2);
|
252
|
|
253
|
Reference book1 = ReferenceFactory.newBook();
|
254
|
book1.setTitle("book1");
|
255
|
Reference book2 = ReferenceFactory.newBook();
|
256
|
book2.setTitle("book2");
|
257
|
repo.getReferenceService().save(book1);
|
258
|
repo.getReferenceService().save(book2);
|
259
|
|
260
|
TaxonName species1 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES(), "Digitalus", null, "primus", null, null, book1, "11", null);
|
261
|
species1.setUuid(NAME1_UUID);
|
262
|
TaxonName species2 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES(), "Digitalus", null, "secundus", null, null, book2, "22", null);
|
263
|
species2.setUuid(NAME2_UUID);
|
264
|
TaxonName genus = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS(), "Digitalus", null, null, null, null, book1, "33", null);
|
265
|
genus.setUuid(NAME2_UUID);
|
266
|
repo.getNameService().save(Arrays.asList(species1, species2, genus));
|
267
|
|
268
|
SpecimenTypeDesignation std1 = SpecimenTypeDesignation.NewInstance();
|
269
|
std1.setCitation(book1);
|
270
|
std1.setUuid(STD1_UUID);
|
271
|
std1.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
|
272
|
|
273
|
SpecimenTypeDesignation std2 = SpecimenTypeDesignation.NewInstance();
|
274
|
std2.setCitation(book2);
|
275
|
std2.setUuid(STD2_UUID);
|
276
|
std2.setTypeStatus(SpecimenTypeDesignationStatus.EPITYPE());
|
277
|
|
278
|
NameTypeDesignation ntd1 = NameTypeDesignation.NewInstance();
|
279
|
ntd1.setCitation(book1);
|
280
|
ntd1.setTypeName(species1);
|
281
|
ntd1.setUuid(NDT1_UUID);
|
282
|
ntd1.setTypeStatus(NameTypeDesignationStatus.TAUTONYMY());
|
283
|
|
284
|
genus.addTypeDesignation(ntd1, false);
|
285
|
species1.addTypeDesignation(std1, false);
|
286
|
species2.addTypeDesignation(std2, false);
|
287
|
|
288
|
repo.getNameService().saveOrUpdate(Arrays.asList(species1, species2, genus));
|
289
|
|
290
|
repo.authenticate("user1", "00000");
|
291
|
Registration reg1 = Registration.NewInstance("test/1000", "1000", species1, new HashSet(Arrays.asList(std1))); // --> book1
|
292
|
reg1.setStatus(RegistrationStatus.PUBLISHED);
|
293
|
// the authenticated user will be set as submitter in new Registrations
|
294
|
// see RegistrationServiceImpl.prepareForSave(Registration reg)
|
295
|
repo.getRegistrationService().save(reg1);
|
296
|
|
297
|
// the authenticated user will be set as submitter in new Registrations
|
298
|
// see RegistrationServiceImpl.prepareForSave(Registration reg)
|
299
|
Registration reg2 = Registration.NewInstance("test/1001", "1001", species2, null); // --> book2
|
300
|
reg2.setStatus(RegistrationStatus.PREPARATION);
|
301
|
repo.getRegistrationService().save(reg2);
|
302
|
|
303
|
repo.authenticate("user2", "00000");
|
304
|
// the authenticated user will be set as submitter in new Registrations
|
305
|
// see RegistrationServiceImpl.prepareForSave(Registration reg)
|
306
|
Registration reg3 = Registration.NewInstance("test/1002", "1002", genus, new HashSet(Arrays.asList(ntd1))); // --> book1
|
307
|
repo.getRegistrationService().save(reg3);
|
308
|
reg3.setStatus(RegistrationStatus.CURATION);
|
309
|
|
310
|
Registration reg4 = Registration.NewInstance("test/1003", "1003", null, new HashSet(Arrays.asList(std2))); // --> book2
|
311
|
repo.getRegistrationService().save(reg4);
|
312
|
reg4.setStatus(RegistrationStatus.READY);
|
313
|
|
314
|
// 2. end the transaction so that all data is actually written to the db
|
315
|
setComplete();
|
316
|
endTransaction();
|
317
|
|
318
|
// use the fileNameAppendix if you are creating a data set file which need to be named differently
|
319
|
// from the standard name. For example if a single test method needs different data then the other
|
320
|
// methods the test class you may want to set the fileNameAppendix when creating the data for this method.
|
321
|
String fileNameAppendix = null;
|
322
|
|
323
|
// 3.
|
324
|
writeDbUnitDataSetFile(new String[] {
|
325
|
"UserAccount",
|
326
|
"REFERENCE",
|
327
|
"Registration", "Registration_TypeDesignationBase",
|
328
|
"TaxonName", "TaxonName_TypeDesignationBase",
|
329
|
"TypeDesignationBase",
|
330
|
"AGENTBASE", "HOMOTYPICALGROUP",
|
331
|
"HIBERNATE_SEQUENCES" // IMPORTANT!!!
|
332
|
},
|
333
|
fileNameAppendix, true );
|
334
|
}
|
335
|
}
|