1
|
/**
|
2
|
* Copyright (C) 2009 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 java.io.FileNotFoundException;
|
12
|
import java.util.Set;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.junit.Assert;
|
17
|
import org.junit.Ignore;
|
18
|
import org.junit.Test;
|
19
|
import org.unitils.dbunit.annotation.DataSet;
|
20
|
import org.unitils.spring.annotation.SpringBeanByType;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
|
23
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
24
|
import eu.etaxonomy.cdm.model.common.Language;
|
25
|
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
|
26
|
import eu.etaxonomy.cdm.model.description.Feature;
|
27
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
28
|
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
|
29
|
import eu.etaxonomy.cdm.model.description.TextData;
|
30
|
import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
|
31
|
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
|
32
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
33
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
|
34
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
35
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
36
|
import eu.etaxonomy.cdm.model.name.Rank;
|
37
|
import eu.etaxonomy.cdm.model.name.Registration;
|
38
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
39
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
|
40
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
41
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
42
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
43
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
44
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
45
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
46
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
47
|
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
|
48
|
|
49
|
/**
|
50
|
* @author a.mueller
|
51
|
*
|
52
|
*/
|
53
|
public class NameServiceImplTest extends CdmTransactionalIntegrationTest {
|
54
|
private static final Logger logger = Logger.getLogger(NameServiceImplTest.class);
|
55
|
|
56
|
@SpringBeanByType
|
57
|
private INameService nameService;
|
58
|
|
59
|
@SpringBeanByType
|
60
|
private IOccurrenceService occurrenceService;
|
61
|
|
62
|
@SpringBeanByType
|
63
|
private IRegistrationService registrationService;
|
64
|
|
65
|
@SpringBeanByType
|
66
|
private ITaxonService taxonService;
|
67
|
|
68
|
@SpringBeanByType
|
69
|
private ITermService termService;
|
70
|
|
71
|
|
72
|
/* ******************** TESTS ********************************************/
|
73
|
|
74
|
/**
|
75
|
* Test method for {@link eu.etaxonomy.cdm.api.service.NameServiceImpl#setDao(eu.etaxonomy.cdm.persistence.dao.name.ITaxonNameDao)}.
|
76
|
*/
|
77
|
@Test
|
78
|
public void testSetDao() {
|
79
|
// Assert.assertNotNull(((NameServiceImpl)nameService).dao);
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* Test method for {@link eu.etaxonomy.cdm.api.service.NameServiceImpl#setVocabularyDao(eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao)}.
|
84
|
*/
|
85
|
@Test
|
86
|
public void testSetVocabularyDao() {
|
87
|
// Assert.assertNotNull(( (NameServiceImpl)nameService.vocabularyDao);
|
88
|
}
|
89
|
|
90
|
/**
|
91
|
* Test method for {@link eu.etaxonomy.cdm.api.service.NameServiceImpl#getNamesByName(java.lang.String)}.
|
92
|
*/
|
93
|
@Test
|
94
|
public void testGetNamesByName() {
|
95
|
logger.warn("Not yet implemented");
|
96
|
}
|
97
|
|
98
|
|
99
|
@Test
|
100
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
|
101
|
public void testDeleteTaxonNameWithNameRelations() {
|
102
|
|
103
|
final String[] tableNames = new String[]{"USERACCOUNT", "TaxonName","NameRelationship","HybridRelationship","DescriptionBase","NomenclaturalStatus","TaxonBase","SpecimenOrObservationBase","OriginalSourceBase","DescriptionElementBase"};
|
104
|
// printDataSetWithNull(System.err, true, null);
|
105
|
|
106
|
TaxonName name1 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
107
|
name1.setTitleCache("Name1", true);
|
108
|
TaxonName nameWithBasionym = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
109
|
nameWithBasionym.setTitleCache("nameWithBasionym", true);
|
110
|
|
111
|
NameRelationshipType nameRelType = (NameRelationshipType)termService.find(NameRelationshipType.BASIONYM().getUuid());
|
112
|
name1.addRelationshipToName(nameWithBasionym,nameRelType , null, null, null);
|
113
|
// nameWithBasionym.addBasionym(name1);
|
114
|
nameService.save(name1);
|
115
|
commitAndStartNewTransaction(tableNames);
|
116
|
|
117
|
|
118
|
name1 = nameService.find(name1.getUuid());
|
119
|
DeleteResult result = nameService.delete(name1);
|
120
|
if (!result.isOk()){
|
121
|
Exception e = result.getExceptions().iterator().next();
|
122
|
Assert.assertEquals("The Ecxeption should be a ReferencedObjectException because it is a basionym", "Name can't be deleted as it is a basionym.", e.getMessage());
|
123
|
} else{
|
124
|
Assert.fail();
|
125
|
}
|
126
|
name1 = nameService.find(name1.getUuid());
|
127
|
Assert.assertNotNull("Name should still be in database",name1);
|
128
|
nameWithBasionym = name1.getNameRelations().iterator().next().getToName();
|
129
|
nameWithBasionym.removeBasionyms();
|
130
|
|
131
|
result = nameService.delete(name1); //should throw now exception
|
132
|
|
133
|
|
134
|
|
135
|
commitAndStartNewTransaction(tableNames);
|
136
|
name1 = nameService.find(name1.getUuid());
|
137
|
Assert.assertNull("Name should not be in database anymore",name1);
|
138
|
|
139
|
}
|
140
|
|
141
|
@Test
|
142
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
|
143
|
public void testDeleteTaxonNameConfiguratorWithNameRelations() {
|
144
|
final String[] tableNames = new String[]{"TaxonName","NameRelationship","HybridRelationship"};
|
145
|
|
146
|
// printDataSet(System.err, new String[]{"TaxonName","NameRelationship","HybridRelationship","DescriptionBase","NomenclaturalStatus","TaxonBase","SpecimenOrObservationBase","OriginalSourceBase",
|
147
|
// "DescriptionElementBase",
|
148
|
// "AGENTBASE", "USERACCOUNT", "PERMISSIONGROUP", "USERACCOUNT_PERMISSIONGROUP", "USERACCOUNT_GRANTEDAUTHORITYIMPL", "GRANTEDAUTHORITYIMPL"});
|
149
|
|
150
|
TaxonName name1 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
151
|
name1.setTitleCache("Name1", true);
|
152
|
TaxonName nameWithBasionym = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
153
|
nameWithBasionym.setTitleCache("nameWithBasionym", true);
|
154
|
|
155
|
NameRelationshipType nameRelType = (NameRelationshipType)termService.find(NameRelationshipType.BASIONYM().getUuid());
|
156
|
name1.addRelationshipToName(nameWithBasionym,nameRelType , null, null, null);
|
157
|
nameService.save(name1);
|
158
|
commitAndStartNewTransaction(tableNames);
|
159
|
NameDeletionConfigurator config = new NameDeletionConfigurator();
|
160
|
|
161
|
name1 = nameService.find(name1.getUuid());
|
162
|
DeleteResult result = nameService.delete(name1.getUuid(), config);
|
163
|
if (result.isOk()){
|
164
|
Assert.fail("This should throw an error as long as name relationships exist.");
|
165
|
}
|
166
|
|
167
|
|
168
|
name1 = nameService.find(name1.getUuid());
|
169
|
Assert.assertNotNull("Name should still be in database",name1);
|
170
|
|
171
|
//ignore is basionym for
|
172
|
config.setIgnoreIsBasionymFor(true);
|
173
|
|
174
|
name1 = nameService.find(name1.getUuid());
|
175
|
nameService.delete(name1.getUuid(), config);
|
176
|
commitAndStartNewTransaction(tableNames);
|
177
|
name1 = nameService.find(name1.getUuid());
|
178
|
Assert.assertNull("Name should not be in database anymore",name1);
|
179
|
|
180
|
}
|
181
|
|
182
|
@Test
|
183
|
public void testDeleteTaxonNameConfiguratorWithNameRelationsAll() {
|
184
|
final String[] tableNames = new String[]{"TaxonName","NameRelationship","HybridRelationship"};
|
185
|
|
186
|
TaxonName name1 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
187
|
name1.setTitleCache("Name1", true);
|
188
|
TaxonName nameWithBasionym = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
189
|
nameWithBasionym.setTitleCache("nameWithBasionym", true);
|
190
|
|
191
|
NameRelationshipType nameRelType = (NameRelationshipType)termService.find(NameRelationshipType.BASIONYM().getUuid());
|
192
|
name1.addRelationshipToName(nameWithBasionym,nameRelType , null, null, null);
|
193
|
nameService.save(name1);
|
194
|
commitAndStartNewTransaction(tableNames);
|
195
|
NameDeletionConfigurator config = new NameDeletionConfigurator();
|
196
|
|
197
|
name1 = nameService.find(name1.getUuid());
|
198
|
DeleteResult result = nameService.delete(name1.getUuid(), config);
|
199
|
if (result.isOk()){
|
200
|
Assert.fail("Delete should throw an error as long as name relationships exist.");
|
201
|
}
|
202
|
|
203
|
name1 = nameService.find(name1.getUuid());
|
204
|
Assert.assertNotNull("Name should still be in database",name1);
|
205
|
|
206
|
//ignore all name relationships
|
207
|
config.setRemoveAllNameRelationships(true);
|
208
|
|
209
|
name1 = nameService.find(name1.getUuid());
|
210
|
result = nameService.delete(name1.getUuid(), config);
|
211
|
logger.debug(result);
|
212
|
commitAndStartNewTransaction(tableNames);
|
213
|
name1 = nameService.find(name1.getUuid());
|
214
|
Assert.assertNull("Name should not be in database anymore",name1);
|
215
|
|
216
|
}
|
217
|
|
218
|
@Test
|
219
|
public void testDeleteTaxonNameConfiguratorWithHasBasionym() {
|
220
|
final String[] tableNames = new String[]{"TaxonName","NameRelationship","HybridRelationship"};
|
221
|
|
222
|
TaxonName name1 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
223
|
name1.setTitleCache("Name1", true);
|
224
|
TaxonName basionym = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
225
|
basionym.setTitleCache("basionym", true);
|
226
|
|
227
|
NameRelationshipType nameRelType = (NameRelationshipType)termService.find(NameRelationshipType.BASIONYM().getUuid());
|
228
|
basionym.addRelationshipToName(name1,nameRelType , null, null, null);
|
229
|
nameService.save(name1);
|
230
|
commitAndStartNewTransaction(tableNames);
|
231
|
NameDeletionConfigurator config = new NameDeletionConfigurator();
|
232
|
config.setIgnoreHasBasionym(false);
|
233
|
|
234
|
name1 = nameService.find(name1.getUuid());
|
235
|
DeleteResult result = nameService.delete(name1.getUuid(), config);
|
236
|
if (result.isOk()){
|
237
|
Assert.fail("Delete should throw an error as long as name relationships exist.");
|
238
|
}
|
239
|
|
240
|
|
241
|
name1 = nameService.find(name1.getUuid());
|
242
|
Assert.assertNotNull("Name should still be in database",name1);
|
243
|
|
244
|
//ignore has basionym
|
245
|
config.setIgnoreHasBasionym(true);
|
246
|
try {
|
247
|
name1 = nameService.find(name1.getUuid());
|
248
|
result = nameService.delete(name1.getUuid(), config);
|
249
|
logger.debug(result);
|
250
|
commitAndStartNewTransaction(tableNames);
|
251
|
name1 = nameService.find(name1.getUuid());
|
252
|
Assert.assertNull("Name should not be in database anymore",name1);
|
253
|
} catch (Exception e) {
|
254
|
Assert.fail("Delete should not throw an error for .");
|
255
|
}
|
256
|
}
|
257
|
|
258
|
@Test
|
259
|
// @Ignore //currently does not run in suite
|
260
|
public void testDeleteTaxonNameWithHybridRelations() {
|
261
|
final String[] tableNames = new String[]{"TaxonName","NameRelationship","HybridRelationship"};
|
262
|
|
263
|
TaxonName name1 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
264
|
name1.setTitleCache("Name1", true);
|
265
|
TaxonName parent = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
266
|
parent.setTitleCache("parent", true);
|
267
|
TaxonName child = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
268
|
child.setTitleCache("child", true);
|
269
|
|
270
|
HybridRelationshipType relType = (HybridRelationshipType)termService.find(HybridRelationshipType.FIRST_PARENT().getUuid());
|
271
|
name1.addHybridParent(parent, relType, null);
|
272
|
nameService.save(name1);
|
273
|
commitAndStartNewTransaction(tableNames); //otherwise first save is rolled back with following failing delete
|
274
|
Assert.assertEquals("'Parent' should be a parent in a hybrid relation.", 1,parent.getHybridParentRelations().size());
|
275
|
// printDataSet(System.out, tableNames);
|
276
|
|
277
|
//parent
|
278
|
|
279
|
name1 = nameService.find(name1.getUuid());
|
280
|
DeleteResult result = nameService.delete(name1);
|
281
|
if (result.isError()){
|
282
|
Assert.fail("Delete should throw NO exception when deleting a hybrid child: " + result.getExceptions().iterator().next().getMessage());
|
283
|
}
|
284
|
commitAndStartNewTransaction(tableNames);
|
285
|
name1 = nameService.find(name1.getUuid());
|
286
|
Assert.assertNull("Name should not be in database anymore",name1);
|
287
|
parent = nameService.find(parent.getUuid());
|
288
|
Assert.assertEquals("'Parent' should not be a parent anymore.", 0,parent.getHybridParentRelations().size());
|
289
|
|
290
|
//child
|
291
|
name1 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
292
|
name1.addHybridChild(child, relType, null);
|
293
|
nameService.save(name1);
|
294
|
commitAndStartNewTransaction(tableNames);
|
295
|
|
296
|
|
297
|
result = nameService.delete(name1);
|
298
|
if (result.isOk()){
|
299
|
Assert.fail("Delete should throw an error as long as hybrid child exist.");
|
300
|
}
|
301
|
name1 = nameService.find(name1.getUuid());
|
302
|
Assert.assertNotNull("Name should still be in database",name1);
|
303
|
name1.removeHybridChild(child);
|
304
|
|
305
|
result = nameService.delete(name1); //should throw now exception
|
306
|
if (result.isError()){
|
307
|
Assert.fail("Delete should throw NO exception when deleting a hybrid child: " +result.getExceptions().iterator().next().getMessage());
|
308
|
}
|
309
|
|
310
|
commitAndStartNewTransaction(tableNames);
|
311
|
name1 = nameService.find(name1.getUuid());
|
312
|
Assert.assertNull("Name should not be in database anymore",name1);
|
313
|
}
|
314
|
|
315
|
@Test
|
316
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
|
317
|
public void testDeleteTaxonNameInConcept() {
|
318
|
final String[] tableNames = new String[]{"TaxonName","TaxonBase"};
|
319
|
|
320
|
TaxonName name1 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
321
|
name1.setTitleCache("Name1", true);
|
322
|
TaxonName basionym = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
323
|
basionym.setTitleCache("basionym", true);
|
324
|
|
325
|
Taxon taxon = Taxon.NewInstance(name1, null);
|
326
|
nameService.save(name1);
|
327
|
taxonService.save(taxon);
|
328
|
commitAndStartNewTransaction(tableNames);
|
329
|
|
330
|
DeleteResult result = nameService.delete(name1);
|
331
|
|
332
|
if (result.isOk()){
|
333
|
Assert.fail("Delete should throw an error as long as name is used in a concept.");
|
334
|
}
|
335
|
TaxonName nameBase =nameService.find(name1.getUuid());
|
336
|
Assert.assertNotNull("Name should still be in database",nameBase);
|
337
|
TaxonBase<?> taxonBase = taxonService.find(taxon.getUuid());
|
338
|
Assert.assertNotNull("Taxon should still be in database",taxonBase);
|
339
|
taxon = (Taxon)taxonBase;
|
340
|
taxon.setName(basionym);
|
341
|
taxonService.save(taxon);
|
342
|
nameBase =nameService.find(name1.getUuid());
|
343
|
|
344
|
|
345
|
result = nameService.delete(nameBase); //should throw no exception
|
346
|
if (result.isError()){
|
347
|
Assert.fail("Delete should throw NO error ");
|
348
|
}
|
349
|
commitAndStartNewTransaction(tableNames);
|
350
|
name1 = nameService.find(name1.getUuid());
|
351
|
Assert.assertNull("Name should still be in database",name1);
|
352
|
taxon = (Taxon)taxonService.find(taxon.getUuid());
|
353
|
Assert.assertNotNull("Taxon should still be in database",taxon);
|
354
|
}
|
355
|
|
356
|
@Test
|
357
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
|
358
|
public void testDeleteTaxonNameAsStoredUnder() {
|
359
|
final String[] tableNames = new String[]{"TaxonName","SpecimenOrObservationBase"};
|
360
|
|
361
|
TaxonName name1 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
362
|
name1.setTitleCache("Name1", true);
|
363
|
DerivedUnit specimen = DerivedUnit.NewPreservedSpecimenInstance();
|
364
|
specimen.setStoredUnder(name1);
|
365
|
|
366
|
occurrenceService.save(specimen);
|
367
|
UUID uuidName1 = nameService.save(name1).getUuid();
|
368
|
|
369
|
commitAndStartNewTransaction(tableNames);
|
370
|
DeleteResult result = nameService.delete(name1);
|
371
|
if (result.isOk()){
|
372
|
Assert.fail("This should throw an error because name is used for specimen#storedUnder.");
|
373
|
}
|
374
|
commitAndStartNewTransaction(tableNames);
|
375
|
|
376
|
name1 = nameService.find(uuidName1);
|
377
|
Assert.assertNotNull("Name should still be in database",name1);
|
378
|
specimen = (DerivedUnit)occurrenceService.find(specimen.getUuid());
|
379
|
Assert.assertNotNull("Specimen should still be in database",name1);
|
380
|
specimen.setStoredUnder(null);
|
381
|
occurrenceService.saveOrUpdate(specimen);
|
382
|
|
383
|
nameService.delete(name1); //should throw no exception
|
384
|
commitAndStartNewTransaction(tableNames);
|
385
|
|
386
|
name1 = nameService.find(uuidName1);
|
387
|
Assert.assertNull("Name should not be in database anymore",name1);
|
388
|
specimen = (DerivedUnit)occurrenceService.find(specimen.getUuid());
|
389
|
Assert.assertNotNull("Specimen should still be in database",specimen);
|
390
|
|
391
|
occurrenceService.delete(specimen); //this is to better run this test in the test suit
|
392
|
|
393
|
}
|
394
|
|
395
|
@Test
|
396
|
@Ignore //currently does not run in suite
|
397
|
public void testDeleteTaxonNameInSource() {
|
398
|
final String[] tableNames = new String[]{"TaxonName","DescriptionBase","TaxonBase","OriginalSourceBase","DescriptionElementBase"};
|
399
|
|
400
|
TaxonName name1 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
401
|
name1.setTitleCache("Name1", true);
|
402
|
TaxonName taxonName = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
403
|
taxonName.setTitleCache("taxonName", true);
|
404
|
Taxon taxon = Taxon.NewInstance(taxonName, null);
|
405
|
|
406
|
TaxonDescription taxonDescription = TaxonDescription.NewInstance(taxon);
|
407
|
Feature feature = (Feature)termService.find(Feature.DESCRIPTION().getUuid());
|
408
|
Language lang = (Language)termService.find(Language.DEFAULT().getUuid());
|
409
|
TextData textData = TextData.NewInstance("Any text", lang, null);
|
410
|
textData.setFeature(feature);
|
411
|
taxonDescription.addElement(textData);
|
412
|
DescriptionElementSource source = DescriptionElementSource.NewPrimarySourceInstance(null, null, name1, "");
|
413
|
textData.addSource(source);
|
414
|
taxonService.saveOrUpdate(taxon);
|
415
|
nameService.save(name1);
|
416
|
try {
|
417
|
commitAndStartNewTransaction(tableNames);
|
418
|
name1 = nameService.find(name1.getUuid());
|
419
|
nameService.delete(name1);
|
420
|
Assert.fail("Delete should throw an error as long as name is used in a source.");
|
421
|
} catch (Exception e) {
|
422
|
if (e.getMessage().contains("Name can't be deleted as it is used as descriptionElementSource#nameUsedInSource")){
|
423
|
//ok
|
424
|
endTransaction(); //exception rolls back transaction!
|
425
|
startNewTransaction();
|
426
|
}else{
|
427
|
Assert.fail("Unexpected error occurred when trying to delete taxon name: " + e.getMessage());
|
428
|
}
|
429
|
}
|
430
|
name1 = nameService.find(name1.getUuid());
|
431
|
Assert.assertNotNull("Name should still be in database",name1);
|
432
|
taxon = (Taxon)taxonService.find(taxon.getUuid());
|
433
|
Assert.assertNotNull("Taxon should still be in database",name1);
|
434
|
source = taxon.getDescriptions().iterator().next().getElements().iterator().next().getSources().iterator().next();
|
435
|
source.setNameUsedInSource(null);
|
436
|
taxonService.saveOrUpdate(taxon);
|
437
|
|
438
|
nameService.delete(name1); //should throw now exception
|
439
|
|
440
|
commitAndStartNewTransaction(tableNames);
|
441
|
name1 = nameService.find(name1.getUuid());
|
442
|
Assert.assertNull("Name should not be in database anymore",name1);
|
443
|
taxon = (Taxon)taxonService.find(taxon.getUuid());
|
444
|
Assert.assertNotNull("Taxon should still be in database",taxon);
|
445
|
source = taxon.getDescriptions().iterator().next().getElements().iterator().next().getSources().iterator().next();
|
446
|
Assert.assertNull("Source should not have a nameUsedInSource anymore",source.getNameUsedInSource());
|
447
|
}
|
448
|
|
449
|
|
450
|
@Test
|
451
|
public void testDeleteTaxonNameAsType() {
|
452
|
final String[] tableNames = new String[]{"TaxonName","TypeDesignationBase","TaxonName_TypeDesignationBase"};
|
453
|
|
454
|
TaxonName name1 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
455
|
name1.setTitleCache("Name used as type", true);
|
456
|
|
457
|
TaxonName higherName = TaxonNameFactory.NewBotanicalInstance(getGenusRank());
|
458
|
higherName.setTitleCache("genus name", true);
|
459
|
NameTypeDesignationStatus typeStatus = (NameTypeDesignationStatus)termService.find(NameTypeDesignationStatus.AUTOMATIC().getUuid());
|
460
|
boolean addToAllHomotypicNames = true;
|
461
|
higherName.addNameTypeDesignation(name1, null, null, null, typeStatus, addToAllHomotypicNames);
|
462
|
nameService.save(higherName);
|
463
|
|
464
|
commitAndStartNewTransaction(tableNames);
|
465
|
name1 = nameService.find(name1.getUuid());
|
466
|
DeleteResult result = nameService.delete(name1);
|
467
|
if (result.isOk()){
|
468
|
Assert.fail("This should throw an error because name is used in a type designation.");
|
469
|
}
|
470
|
|
471
|
commitAndStartNewTransaction(tableNames);
|
472
|
name1 = nameService.find(name1.getUuid());
|
473
|
Assert.assertNotNull("Name should still be in database",name1);
|
474
|
higherName = nameService.find(higherName.getUuid());
|
475
|
higherName.getNameTypeDesignations().iterator().next().removeType(); //keeps the designation but removes the name from it
|
476
|
// nameService.deleteTypeDesignation(higherName,commitAndStartNewTransaction(tableNames) ); //deletes the complete designation //both options can be used
|
477
|
|
478
|
nameService.delete(name1); //should throw now exception
|
479
|
|
480
|
commitAndStartNewTransaction(tableNames);
|
481
|
name1 = nameService.find(name1.getUuid());
|
482
|
Assert.assertNull("Name should not be in database anymore",name1);
|
483
|
higherName = nameService.find(higherName.getUuid());
|
484
|
Assert.assertNotNull("Higher name should still exist in database",higherName);
|
485
|
Assert.assertEquals("Higher name should not have type designations anymore",1, higherName.getTypeDesignations().size());
|
486
|
}
|
487
|
|
488
|
|
489
|
@Test
|
490
|
public void testDeleteTaxonName() {
|
491
|
final String[] tableNames = new String[]{"TaxonName","NameRelationship","HybridRelationship","DescriptionBase","NomenclaturalStatus","TaxonBase","SpecimenOrObservationBase","OriginalSourceBase","DescriptionElementBase","TypeDesignationBase","TaxonName_TypeDesignationBase"};
|
492
|
|
493
|
TaxonName name1 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
494
|
name1.setTitleCache("Name1", true);
|
495
|
|
496
|
//TaxonNameDescription
|
497
|
name1 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
498
|
TaxonNameDescription.NewInstance(name1);
|
499
|
nameService.saveOrUpdate(name1);
|
500
|
commitAndStartNewTransaction(tableNames);
|
501
|
|
502
|
name1 = nameService.find(name1.getUuid());
|
503
|
DeleteResult result = nameService.delete(name1);//should throw now exception
|
504
|
|
505
|
setComplete();
|
506
|
endTransaction();
|
507
|
name1 = nameService.find(name1.getUuid());
|
508
|
Assert.assertNull("Name should not be in database anymore",name1);
|
509
|
|
510
|
// printDataSet(System.out, tableNames);
|
511
|
|
512
|
|
513
|
//NomenclaturalStatus
|
514
|
name1 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
515
|
NomenclaturalStatusType nomStatusType = (NomenclaturalStatusType)termService.find(NomenclaturalStatusType.ILLEGITIMATE().getUuid());
|
516
|
NomenclaturalStatus status = NomenclaturalStatus.NewInstance(nomStatusType);
|
517
|
name1.addStatus(status);
|
518
|
nameService.saveOrUpdate(name1);
|
519
|
commitAndStartNewTransaction(tableNames);
|
520
|
|
521
|
name1 = nameService.find(name1.getUuid());
|
522
|
|
523
|
nameService.delete(name1); //should throw now exception
|
524
|
if (!result.isOk()){
|
525
|
Assert.fail();
|
526
|
}
|
527
|
setComplete();
|
528
|
endTransaction();
|
529
|
// printDataSet(System.out, tableNames);
|
530
|
|
531
|
|
532
|
//Type Designations
|
533
|
name1 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
534
|
name1.setTitleCache("Name with type designation", true);
|
535
|
SpecimenTypeDesignation typeDesignation = SpecimenTypeDesignation.NewInstance();
|
536
|
SpecimenTypeDesignationStatus typeStatus = (SpecimenTypeDesignationStatus)termService.find(SpecimenTypeDesignationStatus.HOLOTYPE().getUuid());
|
537
|
typeDesignation.setTypeStatus(typeStatus);
|
538
|
DerivedUnit specimen = DerivedUnit.NewPreservedSpecimenInstance();
|
539
|
specimen.setTitleCache("Type specimen", true);
|
540
|
occurrenceService.save(specimen);
|
541
|
typeDesignation.setTypeSpecimen(specimen);
|
542
|
|
543
|
name1.addTypeDesignation(typeDesignation, true);
|
544
|
nameService.save(name1);
|
545
|
commitAndStartNewTransaction(tableNames);
|
546
|
// printDataSet(System.out, tableNames);
|
547
|
|
548
|
name1 = nameService.find(name1.getUuid());
|
549
|
|
550
|
result = nameService.delete(name1); //should throw now exception
|
551
|
if (!result.isOk()){
|
552
|
Assert.fail();
|
553
|
}
|
554
|
setComplete();
|
555
|
endTransaction();
|
556
|
// printDataSet(System.out, tableNames);
|
557
|
|
558
|
}
|
559
|
|
560
|
@Test
|
561
|
public void testDeleteTaxonNameWithTypeInHomotypicalGroup() {
|
562
|
final String[] tableNames = new String[]{"TaxonName","NameRelationship","HybridRelationship","DescriptionBase","NomenclaturalStatus","TaxonBase","SpecimenOrObservationBase","OriginalSourceBase","DescriptionElementBase","TypeDesignationBase","TaxonName_TypeDesignationBase"};
|
563
|
|
564
|
//Type Designations for homotypical group with > 1 names
|
565
|
TaxonName name1 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
566
|
name1.setTitleCache("Name1 with type designation", true);
|
567
|
TaxonName name2 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
568
|
name2.setTitleCache("Name2 with type designation", true);
|
569
|
name2.setHomotypicalGroup(name1.getHomotypicalGroup());
|
570
|
|
571
|
DerivedUnit specimen = DerivedUnit.NewPreservedSpecimenInstance();
|
572
|
specimen.setTitleCache("Type specimen 2", true);
|
573
|
occurrenceService.save(specimen);
|
574
|
SpecimenTypeDesignationStatus typeStatus = (SpecimenTypeDesignationStatus)termService.find(SpecimenTypeDesignationStatus.HOLOTYPE().getUuid());
|
575
|
|
576
|
SpecimenTypeDesignation typeDesignation = SpecimenTypeDesignation.NewInstance();
|
577
|
typeDesignation.setTypeStatus(typeStatus);
|
578
|
typeDesignation.setTypeSpecimen(specimen);
|
579
|
|
580
|
boolean addToAllNames = true;
|
581
|
name1.addTypeDesignation(typeDesignation, addToAllNames);
|
582
|
nameService.saveOrUpdate(name1);
|
583
|
commitAndStartNewTransaction(tableNames);
|
584
|
|
585
|
name1 = nameService.find(name1.getUuid());
|
586
|
|
587
|
nameService.delete(name1); //should throw now exception
|
588
|
|
589
|
setComplete();
|
590
|
endTransaction();
|
591
|
// printDataSet(System.out, tableNames);
|
592
|
|
593
|
}
|
594
|
|
595
|
@Test
|
596
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
|
597
|
public void testDeleteTypeDesignation() {
|
598
|
final String[] tableNames = new String[]{
|
599
|
"TaxonName","TypeDesignationBase","TaxonName_TypeDesignationBase",
|
600
|
"SpecimenOrObservationBase"};
|
601
|
|
602
|
// IBotanicalName name1 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
603
|
// name1.setTitleCache("Name1");
|
604
|
// name1.setUuid(UUID.fromString("6dbd41d1-fe13-4d9c-bb58-31f051c2c384"));
|
605
|
//
|
606
|
// IBotanicalName name2 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
|
607
|
// name2.setTitleCache("Name2");
|
608
|
// name2.setUuid(UUID.fromString("f9e9c13f-5fa5-48d3-88cf-712c921a099e"));
|
609
|
//
|
610
|
// IBotanicalName name3 = TaxonNameFactory.NewBotanicalInstance(getGenusRank());
|
611
|
// name3.setTitleCache("Name3");
|
612
|
// name3.setUuid(UUID.fromString("e1e66264-f16a-4df9-80fd-6ab5028a3c28"));
|
613
|
//
|
614
|
//
|
615
|
// SpecimenTypeDesignation desig1 = SpecimenTypeDesignation.NewInstance();
|
616
|
// desig1.setUuid(UUID.fromString("1357c307-00c3-499c-8e20-0849d4706125"));
|
617
|
// name1.addTypeDesignation(desig1, true);
|
618
|
// name2.addTypeDesignation(desig1, true);
|
619
|
//
|
620
|
// SpecimenTypeDesignation desig2 = SpecimenTypeDesignation.NewInstance();
|
621
|
// desig2.setUuid(UUID.fromString("9bbda70b-7272-4e65-a807-852a3f2eba63"));
|
622
|
// name1.addTypeDesignation(desig2, true);
|
623
|
//
|
624
|
// Specimen specimen1 = Specimen.NewInstance();
|
625
|
// Fossil specimen2 = Fossil.NewInstance();
|
626
|
//
|
627
|
// desig1.setTypeSpecimen(specimen1);
|
628
|
// desig2.setTypeSpecimen(specimen2);
|
629
|
//
|
630
|
// NameTypeDesignation nameDesig = NameTypeDesignation.NewInstance();
|
631
|
// nameDesig.setTypeName(name1);
|
632
|
// name3.addTypeDesignation(nameDesig, true);
|
633
|
//
|
634
|
// nameService.save(name1);
|
635
|
// nameService.save(name2);
|
636
|
// nameService.save(name3);
|
637
|
//
|
638
|
// commitAndStartNewTransaction(tableNames);
|
639
|
//
|
640
|
// printDataSet(System.out, tableNames);
|
641
|
//
|
642
|
|
643
|
|
644
|
TaxonName name1 = this.nameService.load(UUID.fromString("6dbd41d1-fe13-4d9c-bb58-31f051c2c384"));
|
645
|
TaxonName name2 = this.nameService.load(UUID.fromString("f9e9c13f-5fa5-48d3-88cf-712c921a099e"));
|
646
|
TaxonName name3 = this.nameService.load(UUID.fromString("e1e66264-f16a-4df9-80fd-6ab5028a3c28"));
|
647
|
DerivedUnit specimen1 = CdmBase.deproxy(this.occurrenceService.load(UUID.fromString("0d19a9ca-21a7-4adb-8640-8d6719e15eea")), DerivedUnit.class);
|
648
|
DerivedUnit fossil = CdmBase.deproxy(this.occurrenceService.load(UUID.fromString("4c48b7c8-4c8d-4e48-b083-0837fe51a0a9")), DerivedUnit.class);
|
649
|
|
650
|
Set<TypeDesignationBase> desigs1 = name1.getTypeDesignations();
|
651
|
Set<TypeDesignationBase> desigs2 = name2.getTypeDesignations();
|
652
|
Set<TypeDesignationBase> desigs3 = name3.getTypeDesignations();
|
653
|
|
654
|
Assert.assertEquals("name1 should have 2 type designations", 2, desigs1.size());
|
655
|
Assert.assertEquals("name2 should have 1 type designations", 1, desigs2.size());
|
656
|
Assert.assertEquals("name3 should have 1 type designations", 1, desigs3.size());
|
657
|
Assert.assertEquals("Specimen1 should be used in 1 type designation", 1, specimen1.getSpecimenTypeDesignations().size());
|
658
|
Assert.assertEquals("Fossil should be used in 1 type designation", 1, fossil.getSpecimenTypeDesignations().size());
|
659
|
|
660
|
nameService.deleteTypeDesignation((TaxonName)null, null);
|
661
|
|
662
|
commitAndStartNewTransaction(tableNames);
|
663
|
|
664
|
name1 = this.nameService.load(UUID.fromString("6dbd41d1-fe13-4d9c-bb58-31f051c2c384"));
|
665
|
name2 = this.nameService.load(UUID.fromString("f9e9c13f-5fa5-48d3-88cf-712c921a099e"));
|
666
|
name3 = this.nameService.load(UUID.fromString("e1e66264-f16a-4df9-80fd-6ab5028a3c28"));
|
667
|
specimen1 = CdmBase.deproxy(this.occurrenceService.load(UUID.fromString("0d19a9ca-21a7-4adb-8640-8d6719e15eea")), DerivedUnit.class);
|
668
|
fossil = CdmBase.deproxy(this.occurrenceService.load(UUID.fromString("4c48b7c8-4c8d-4e48-b083-0837fe51a0a9")), DerivedUnit.class);
|
669
|
|
670
|
desigs1 = name1.getTypeDesignations();
|
671
|
desigs2 = name2.getTypeDesignations();
|
672
|
desigs3 = name3.getTypeDesignations();
|
673
|
//nothing should be deleted
|
674
|
Assert.assertEquals("name1 should have 2 type designations", 2, desigs1.size());
|
675
|
Assert.assertEquals("name2 should have 1 type designations", 1, desigs2.size());
|
676
|
Assert.assertEquals("name3 should have 1 type designations", 1, desigs3.size());
|
677
|
Assert.assertEquals("Specimen1 should be used in 1 type designation", 1, specimen1.getSpecimenTypeDesignations().size());
|
678
|
Assert.assertEquals("Fossil should be used in 1 type designation", 1, fossil.getSpecimenTypeDesignations().size());
|
679
|
|
680
|
nameService.deleteTypeDesignation(name1, null);
|
681
|
|
682
|
commitAndStartNewTransaction(tableNames);
|
683
|
|
684
|
name1 = this.nameService.load(UUID.fromString("6dbd41d1-fe13-4d9c-bb58-31f051c2c384"));
|
685
|
name2 = this.nameService.load(UUID.fromString("f9e9c13f-5fa5-48d3-88cf-712c921a099e"));
|
686
|
name3 = this.nameService.load(UUID.fromString("e1e66264-f16a-4df9-80fd-6ab5028a3c28"));
|
687
|
specimen1 = CdmBase.deproxy(this.occurrenceService.load(UUID.fromString("0d19a9ca-21a7-4adb-8640-8d6719e15eea")), DerivedUnit.class);
|
688
|
fossil = CdmBase.deproxy(this.occurrenceService.load(UUID.fromString("4c48b7c8-4c8d-4e48-b083-0837fe51a0a9")), DerivedUnit.class);
|
689
|
|
690
|
desigs1 = name1.getTypeDesignations();
|
691
|
desigs2 = name2.getTypeDesignations();
|
692
|
desigs3 = name3.getTypeDesignations();
|
693
|
//only the types of name1 should be deleted
|
694
|
Assert.assertEquals("name1 should have 0 type designations", 0, desigs1.size());
|
695
|
Assert.assertEquals("name2 should have 1 type designations", 1, desigs2.size());
|
696
|
Assert.assertEquals("name3 should have 1 type designations", 1, desigs3.size());
|
697
|
Assert.assertEquals("Specimen1 should be used in 1 type designation", 1, specimen1.getSpecimenTypeDesignations().size());
|
698
|
Assert.assertEquals("Fossil should be used in 0 type designation", 0, fossil.getSpecimenTypeDesignations().size());
|
699
|
|
700
|
SpecimenTypeDesignation desig2 = (SpecimenTypeDesignation)name2.getTypeDesignations().iterator().next();
|
701
|
nameService.deleteTypeDesignation(name2, desig2);
|
702
|
|
703
|
commitAndStartNewTransaction(tableNames);
|
704
|
|
705
|
name1 = this.nameService.load(UUID.fromString("6dbd41d1-fe13-4d9c-bb58-31f051c2c384"));
|
706
|
name2 = this.nameService.load(UUID.fromString("f9e9c13f-5fa5-48d3-88cf-712c921a099e"));
|
707
|
name3 = this.nameService.load(UUID.fromString("e1e66264-f16a-4df9-80fd-6ab5028a3c28"));
|
708
|
specimen1 = CdmBase.deproxy(this.occurrenceService.load(UUID.fromString("0d19a9ca-21a7-4adb-8640-8d6719e15eea")), DerivedUnit.class);
|
709
|
fossil = CdmBase.deproxy(this.occurrenceService.load(UUID.fromString("4c48b7c8-4c8d-4e48-b083-0837fe51a0a9")), DerivedUnit.class);
|
710
|
|
711
|
desigs1 = name1.getTypeDesignations();
|
712
|
desigs2 = name2.getTypeDesignations();
|
713
|
desigs3 = name3.getTypeDesignations();
|
714
|
|
715
|
Assert.assertEquals("name1 should have 0 type designations", 0, desigs1.size());
|
716
|
Assert.assertEquals("name2 should have 0 type designations", 0, desigs2.size());
|
717
|
Assert.assertEquals("name3 should have 1 type designations", 1, desigs3.size());
|
718
|
Assert.assertEquals("Specimen1 should be used in 0 type designation", 0, specimen1.getSpecimenTypeDesignations().size());
|
719
|
Assert.assertEquals("Fossil should be used in 0 type designation", 0, fossil.getSpecimenTypeDesignations().size());
|
720
|
|
721
|
NameTypeDesignation desig3 = (NameTypeDesignation)name3.getTypeDesignations().iterator().next();
|
722
|
name3.addTypeDesignation(SpecimenTypeDesignation.NewInstance(), false);
|
723
|
this.nameService.update(name3);
|
724
|
|
725
|
this.nameService.load(UUID.fromString("e1e66264-f16a-4df9-80fd-6ab5028a3c28"));
|
726
|
desigs3 = name3.getTypeDesignations();
|
727
|
|
728
|
NameTypeDesignation desigNew = NameTypeDesignation.NewInstance();
|
729
|
commitAndStartNewTransaction(tableNames);
|
730
|
name3 = nameService.load(name3.getUuid());
|
731
|
|
732
|
Assert.assertEquals("name3 should have 2 type designations", 2, desigs3.size());
|
733
|
|
734
|
nameService.deleteTypeDesignation(name3, desig3);
|
735
|
commitAndStartNewTransaction(tableNames);
|
736
|
|
737
|
name1 = this.nameService.load(UUID.fromString("6dbd41d1-fe13-4d9c-bb58-31f051c2c384"));
|
738
|
name2 = this.nameService.load(UUID.fromString("f9e9c13f-5fa5-48d3-88cf-712c921a099e"));
|
739
|
name3 = this.nameService.load(UUID.fromString("e1e66264-f16a-4df9-80fd-6ab5028a3c28"));
|
740
|
specimen1 = CdmBase.deproxy(this.occurrenceService.load(UUID.fromString("0d19a9ca-21a7-4adb-8640-8d6719e15eea")), DerivedUnit.class);
|
741
|
fossil = CdmBase.deproxy(this.occurrenceService.load(UUID.fromString("4c48b7c8-4c8d-4e48-b083-0837fe51a0a9")), DerivedUnit.class);
|
742
|
|
743
|
|
744
|
desigs1 = name1.getTypeDesignations();
|
745
|
desigs2 = name2.getTypeDesignations();
|
746
|
desigs3 = name3.getTypeDesignations();
|
747
|
|
748
|
Assert.assertEquals("name1 should have 0 type designations", 0, desigs1.size());
|
749
|
Assert.assertEquals("name2 should have 0 type designations", 0, desigs2.size());
|
750
|
Assert.assertEquals("name3 should have 0 type designations", 1, desigs3.size());
|
751
|
Assert.assertEquals("Specimen1 should be used in 0 type designation", 0, specimen1.getSpecimenTypeDesignations().size());
|
752
|
Assert.assertEquals("Fossil should be used in 0 type designation", 0, fossil.getSpecimenTypeDesignations().size());
|
753
|
|
754
|
}
|
755
|
|
756
|
@Test
|
757
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
|
758
|
public void testDeleteTypeDesignationWithRegistration() {
|
759
|
final String[] tableNames = new String[]{
|
760
|
"TaxonName","TypeDesignationBase","TaxonName_TypeDesignationBase",
|
761
|
"SpecimenOrObservationBase"};
|
762
|
|
763
|
TaxonName name3 = this.nameService.load(UUID.fromString("e1e66264-f16a-4df9-80fd-6ab5028a3c28"));
|
764
|
|
765
|
Set<TypeDesignationBase> desigs3 = name3.getTypeDesignations();
|
766
|
|
767
|
NameTypeDesignation desig3 = (NameTypeDesignation)name3.getTypeDesignations().iterator().next();
|
768
|
name3.addTypeDesignation(SpecimenTypeDesignation.NewInstance(), false);
|
769
|
this.nameService.update(name3);
|
770
|
|
771
|
name3 = this.nameService.load(UUID.fromString("e1e66264-f16a-4df9-80fd-6ab5028a3c28"));
|
772
|
desigs3 = name3.getTypeDesignations();
|
773
|
|
774
|
NameTypeDesignation desigNew = NameTypeDesignation.NewInstance();
|
775
|
Registration registration = Registration.NewInstance("abc", "abc", name3, null);
|
776
|
registration.addTypeDesignation(desigNew);
|
777
|
|
778
|
UUID uuidReg = registrationService.saveOrUpdate(registration);
|
779
|
commitAndStartNewTransaction(tableNames);
|
780
|
|
781
|
name3 = nameService.load(name3.getUuid());
|
782
|
|
783
|
Set<Registration> regs = name3.getRegistrations();
|
784
|
desigs3 = name3.getTypeDesignations();
|
785
|
Assert.assertEquals("name3 should have 2 type designations", 2, desigs3.size());
|
786
|
Assert.assertEquals("name should have 1 registrations", 1, regs.size());
|
787
|
Assert.assertEquals("registration should have 1 type designations",1, regs.iterator().next().getTypeDesignations().size());
|
788
|
|
789
|
nameService.deleteTypeDesignation(name3, desig3);
|
790
|
commitAndStartNewTransaction(tableNames);
|
791
|
|
792
|
name3 = this.nameService.load(UUID.fromString("e1e66264-f16a-4df9-80fd-6ab5028a3c28"));
|
793
|
|
794
|
regs = name3.getRegistrations();
|
795
|
Assert.assertEquals("name3 should have 1 registration", 1, regs.size());
|
796
|
Assert.assertEquals("registration should have 1 type designations",1, regs.iterator().next().getTypeDesignations().size());
|
797
|
|
798
|
desigs3 = name3.getTypeDesignations();
|
799
|
|
800
|
nameService.deleteTypeDesignation(name3, desigNew);
|
801
|
commitAndStartNewTransaction(tableNames);
|
802
|
name3 = this.nameService.load(UUID.fromString("e1e66264-f16a-4df9-80fd-6ab5028a3c28"));
|
803
|
regs = name3.getRegistrations();
|
804
|
desigs3 = name3.getTypeDesignations();
|
805
|
|
806
|
Assert.assertEquals("name3 should have 1 type designations", 1, desigs3.size());
|
807
|
Assert.assertEquals("registration should have 0 type designations",0, regs.iterator().next().getTypeDesignations().size());
|
808
|
}
|
809
|
|
810
|
|
811
|
@Test
|
812
|
@DataSet
|
813
|
public void testDeleteTypeDesignationAllNames() {
|
814
|
final String[] tableNames = new String[]{
|
815
|
"TaxonName","TypeDesignationBase",
|
816
|
"TaxonName_TypeDesignationBase","SpecimenOrObservationBase"};
|
817
|
|
818
|
|
819
|
TaxonName name1 = this.nameService.load(UUID.fromString("6dbd41d1-fe13-4d9c-bb58-31f051c2c384"));
|
820
|
TaxonName name2 = this.nameService.load(UUID.fromString("f9e9c13f-5fa5-48d3-88cf-712c921a099e"));
|
821
|
TaxonName name3 = this.nameService.load(UUID.fromString("e1e66264-f16a-4df9-80fd-6ab5028a3c28"));
|
822
|
DerivedUnit specimen1 = CdmBase.deproxy(this.occurrenceService.load(UUID.fromString("0d19a9ca-21a7-4adb-8640-8d6719e15eea")), DerivedUnit.class);
|
823
|
DerivedUnit fossil = CdmBase.deproxy(this.occurrenceService.load(UUID.fromString("4c48b7c8-4c8d-4e48-b083-0837fe51a0a9")), DerivedUnit.class);
|
824
|
|
825
|
Set<TypeDesignationBase> desigs1 = name1.getTypeDesignations();
|
826
|
Set<TypeDesignationBase> desigs2 = name2.getTypeDesignations();
|
827
|
Set<TypeDesignationBase> desigs3 = name3.getTypeDesignations();
|
828
|
|
829
|
Assert.assertEquals("name1 should have 2 type designations", 2, desigs1.size());
|
830
|
Assert.assertEquals("name2 should have 1 type designations", 1, desigs2.size());
|
831
|
Assert.assertEquals("name3 should have 1 type designations", 1, desigs3.size());
|
832
|
Assert.assertEquals("Specimen1 should be used in 1 type designation", 1, specimen1.getSpecimenTypeDesignations().size());
|
833
|
Assert.assertEquals("Fossil should be used in 1 type designation", 1, fossil.getSpecimenTypeDesignations().size());
|
834
|
|
835
|
SpecimenTypeDesignation desig2 = (SpecimenTypeDesignation)name2.getTypeDesignations().iterator().next();
|
836
|
|
837
|
nameService.deleteTypeDesignation(null, desig2);
|
838
|
|
839
|
commitAndStartNewTransaction(tableNames);
|
840
|
|
841
|
name1 = this.nameService.load(UUID.fromString("6dbd41d1-fe13-4d9c-bb58-31f051c2c384"));
|
842
|
name2 = this.nameService.load(UUID.fromString("f9e9c13f-5fa5-48d3-88cf-712c921a099e"));
|
843
|
name3 = this.nameService.load(UUID.fromString("e1e66264-f16a-4df9-80fd-6ab5028a3c28"));
|
844
|
specimen1 = CdmBase.deproxy(this.occurrenceService.load(UUID.fromString("0d19a9ca-21a7-4adb-8640-8d6719e15eea")), DerivedUnit.class);
|
845
|
fossil = CdmBase.deproxy(this.occurrenceService.load(UUID.fromString("4c48b7c8-4c8d-4e48-b083-0837fe51a0a9")), DerivedUnit.class);
|
846
|
|
847
|
desigs1 = name1.getTypeDesignations();
|
848
|
desigs2 = name2.getTypeDesignations();
|
849
|
desigs3 = name3.getTypeDesignations();
|
850
|
|
851
|
Assert.assertEquals("name1 should have 1 type designations", 1, desigs1.size());
|
852
|
Assert.assertEquals("name2 should have 0 type designations", 0, desigs2.size());
|
853
|
Assert.assertEquals("name3 should have 1 type designations", 1, desigs3.size());
|
854
|
Assert.assertEquals("Specimen1 should be used in 0 type designation", 0, specimen1.getSpecimenTypeDesignations().size());
|
855
|
Assert.assertEquals("Fossil should be used in 1 type designation", 1, fossil.getSpecimenTypeDesignations().size());
|
856
|
|
857
|
}
|
858
|
|
859
|
private Rank getSpeciesRank() {
|
860
|
return (Rank)termService.find(Rank.uuidSpecies);
|
861
|
}
|
862
|
|
863
|
private Rank getGenusRank() {
|
864
|
return (Rank)termService.find(Rank.uuidGenus);
|
865
|
}
|
866
|
|
867
|
/* (non-Javadoc)
|
868
|
* @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
|
869
|
*/
|
870
|
@Override
|
871
|
public void createTestDataSet() throws FileNotFoundException {}
|
872
|
|
873
|
|
874
|
}
|