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