2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.api
.service
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertNotNull
;
14 import static org
.junit
.Assert
.assertNull
;
15 import static org
.junit
.Assert
.assertTrue
;
17 import java
.util
.ArrayList
;
18 import java
.util
.Iterator
;
19 import java
.util
.List
;
21 import java
.util
.UUID
;
23 import org
.apache
.log4j
.Logger
;
24 import org
.junit
.Assert
;
25 import org
.junit
.Test
;
26 import org
.unitils
.dbunit
.annotation
.DataSet
;
27 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
29 import eu
.etaxonomy
.cdm
.api
.service
.config
.NameDeletionConfigurator
;
30 import eu
.etaxonomy
.cdm
.api
.service
.config
.SynonymDeletionConfigurator
;
31 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
32 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonNodeDeletionConfigurator
.ChildHandling
;
33 import eu
.etaxonomy
.cdm
.api
.service
.exception
.DataChangeNoRollbackException
;
34 import eu
.etaxonomy
.cdm
.api
.service
.exception
.HomotypicalGroupChangeException
;
35 import eu
.etaxonomy
.cdm
.datagenerator
.TaxonGenerator
;
36 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
37 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
38 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
39 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
;
40 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
41 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
42 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
43 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
44 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
45 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
46 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
47 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
48 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
49 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
50 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
51 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
52 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
53 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
54 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
55 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
56 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
57 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
58 import eu
.etaxonomy
.cdm
.test
.unitils
.CleanSweepInsertLoadStrategy
;
65 public class TaxonServiceImplTest
extends CdmTransactionalIntegrationTest
{
66 private static final Logger logger
= Logger
.getLogger(TaxonServiceImplTest
.class);
69 private ITaxonService service
;
72 private INameService nameService
;
75 private IReferenceService referenceService
;
78 private IClassificationService classificationService
;
81 private ITaxonNodeService nodeService
;
84 private IDescriptionService descriptionService
;
87 private IMarkerService markerService
;
93 /****************** TESTS *****************************/
97 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#getTaxonByUuid(java.util.UUID)}.
100 public final void testGetTaxonByUuid() {
101 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
102 UUID uuid
= service
.save(expectedTaxon
);
103 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
104 assertEquals(expectedTaxon
, actualTaxon
);
108 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#saveTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)}.
111 public final void testSaveTaxon() {
112 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
113 UUID uuid
= service
.save(expectedTaxon
);
114 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
115 assertEquals(expectedTaxon
, actualTaxon
);
119 public final void testSaveOrUpdateTaxon() {
120 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
121 UUID uuid
= service
.save(expectedTaxon
);
122 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
123 assertEquals(expectedTaxon
, actualTaxon
);
125 actualTaxon
.setName(BotanicalName
.NewInstance(Rank
.SPECIES()));
127 service
.saveOrUpdate(actualTaxon
);
133 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#removeTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)}.
136 public final void testRemoveTaxon() {
137 Taxon taxon
= Taxon
.NewInstance(BotanicalName
.NewInstance(Rank
.UNKNOWN_RANK()), null);
138 UUID uuid
= service
.save(taxon
);
139 service
.delete(taxon
);
140 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
141 assertNull(actualTaxon
);
146 public final void testMakeTaxonSynonym() {
147 Rank rank
= Rank
.SPECIES();
148 Taxon tax1
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test1", null, null, null, null, null, null, null), null);
149 Synonym synonym
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
150 tax1
.addHomotypicSynonym(synonym
, null, null);
151 UUID uuidTaxon
= service
.save(tax1
);
152 UUID uuidSyn
= service
.save(synonym
);
154 service
.swapSynonymAndAcceptedTaxon(synonym
, tax1
);
157 TaxonBase
<?
> tax
= service
.find(uuidTaxon
);
158 TaxonBase
<?
> syn
= service
.find(uuidSyn
);
160 assertTrue(tax
.getName().getTitleCache().equals("Test2"));
162 HomotypicalGroup groupTest
= tax
.getHomotypicGroup();
163 HomotypicalGroup groupTest2
= syn
.getHomotypicGroup();
164 assertEquals(groupTest
, groupTest2
);
169 public final void testChangeSynonymToAcceptedTaxon(){
170 Rank rank
= Rank
.SPECIES();
171 //HomotypicalGroup group = HomotypicalGroup.NewInstance();
172 Taxon taxWithoutSyn
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test1", null, null, null, null, null, null, null), null);
173 Taxon taxWithSyn
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
174 Synonym synonym
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
175 Synonym synonym2
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
176 synonym2
.getName().setHomotypicalGroup(synonym
.getHomotypicGroup());
177 //tax2.addHeterotypicSynonymName(synonym.getName());
178 taxWithSyn
.addSynonym(synonym
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
179 taxWithSyn
.addSynonym(synonym2
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
181 service
.save(taxWithoutSyn
);
182 UUID uuidSyn
= service
.save(synonym
);
183 service
.save(synonym2
);
184 UUID uuidTaxWithSyn
=service
.save(taxWithSyn
);
188 taxon
= service
.changeSynonymToAcceptedTaxon(synonym
, taxWithSyn
, true, true, null, null);
189 } catch (HomotypicalGroupChangeException e
) {
190 Assert
.fail("Invocation of change method should not throw an exception");
193 //test flush (resave deleted object)
194 TaxonBase
<?
> syn
= service
.find(uuidSyn
);
195 taxWithSyn
= (Taxon
)service
.find(uuidTaxWithSyn
);
196 Taxon taxNew
= (Taxon
)service
.find(taxon
.getUuid());
198 assertNotNull(taxWithSyn
);
199 assertNotNull(taxNew
);
201 Assert
.assertEquals("New taxon should have 1 synonym relationship (the old homotypic synonym)", 1, taxon
.getSynonymRelations().size());
207 public final void testChangeSynonymToAcceptedTaxonSynonymForTwoTaxa(){
208 Rank rank
= Rank
.SPECIES();
209 //HomotypicalGroup group = HomotypicalGroup.NewInstance();
210 Taxon taxWithoutSyn
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test1", null, null, null, null, null, null, null), null);
211 Taxon tax2WithSyn
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test5", null, null, null, null, null, null, null), null);
212 Taxon taxWithSyn
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
213 Synonym synonym
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
214 Synonym synonym2
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
215 //synonym2.getName().setHomotypicalGroup(taxWithSyn.getHomotypicGroup());
216 //tax2.addHeterotypicSynonymName(synonym.getName());
217 taxWithSyn
.addSynonym(synonym
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
218 taxWithSyn
.addSynonym(synonym2
, SynonymRelationshipType
.HOMOTYPIC_SYNONYM_OF());
219 tax2WithSyn
.addSynonym(synonym
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
221 service
.save(taxWithoutSyn
);
223 UUID uuidSyn
= service
.save(synonym
);
224 service
.save(synonym2
);
225 UUID uuidTaxWithSyn
=service
.save(taxWithSyn
);
226 service
.save(tax2WithSyn
);
231 taxon
= service
.changeSynonymToAcceptedTaxon(synonym
, taxWithSyn
, true, true, null, null);
233 } catch (HomotypicalGroupChangeException e
) {
234 Assert
.fail("Invocation of change method should not throw an exception");
239 //test flush (resave deleted object)
240 TaxonBase
<?
> syn
= service
.find(uuidSyn
);
241 taxWithSyn
= (Taxon
)service
.find(uuidTaxWithSyn
);
242 Taxon taxNew
= (Taxon
)service
.find(taxon
.getUuid());
244 assertNotNull(taxWithSyn
);
245 assertNotNull(taxNew
);
247 // Assert.assertEquals("New taxon should have 1 synonym relationship (the old homotypic synonym)", 1, taxon.getSynonymRelations().size());
251 * Old implementation taken from {@link TaxonServiceImplBusinessTest} for old version of method.
252 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#moveSynonymToAnotherTaxon(eu.etaxonomy.cdm.model.taxon.SynonymRelationship, eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)}.
255 public final void testMoveSynonymToAnotherTaxon_OLD() {
256 SynonymRelationshipType heteroTypicSynonymRelationshipType
= SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF();
257 Reference
<?
> reference
= ReferenceFactory
.newGeneric();
258 String referenceDetail
= "test";
260 NonViralName
<?
> t1n
= NonViralName
.NewInstance(null);
261 Taxon t1
= Taxon
.NewInstance(t1n
, reference
);
262 NonViralName
<?
> t2n
= NonViralName
.NewInstance(null);
263 Taxon t2
= Taxon
.NewInstance(t2n
, reference
);
264 NonViralName
<?
> s1n
= NonViralName
.NewInstance(null);
265 Synonym s1
= Synonym
.NewInstance(s1n
, reference
);
266 t1
.addSynonym(s1
, heteroTypicSynonymRelationshipType
);
268 SynonymRelationship synonymRelation
= t1
.getSynonymRelations().iterator().next();
270 boolean keepReference
= false;
271 boolean moveHomotypicGroup
= false;
273 service
.moveSynonymToAnotherTaxon(synonymRelation
, t2
, moveHomotypicGroup
, heteroTypicSynonymRelationshipType
, reference
, referenceDetail
, keepReference
);
274 } catch (HomotypicalGroupChangeException e
) {
275 Assert
.fail("Method call should not throw exception");
278 Assert
.assertTrue("t1 should have no synonym relationships", t1
.getSynonymRelations().isEmpty());
280 Set
<SynonymRelationship
> synonymRelations
= t2
.getSynonymRelations();
281 Assert
.assertTrue("t2 should have exactly one synonym relationship", synonymRelations
.size() == 1);
283 synonymRelation
= synonymRelations
.iterator().next();
285 Assert
.assertEquals(t2
, synonymRelation
.getAcceptedTaxon());
286 Assert
.assertEquals(heteroTypicSynonymRelationshipType
, synonymRelation
.getType());
287 Assert
.assertEquals(reference
, synonymRelation
.getCitation());
288 Assert
.assertEquals(referenceDetail
, synonymRelation
.getCitationMicroReference());
292 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testMoveSynonymToAnotherTaxon.xml")
293 public final void testMoveSynonymToAnotherTaxon() throws Exception
{
294 final String
[] tableNames
= new String
[]{"SynonymRelationship"};
296 // printDataSet(System.err, new String[]{"AgentBase", "TaxonBase"});
297 // printDataSet(System.err, new String[]{"TaxonNode"});
299 UUID uuidNewTaxon
= UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
300 UUID uuidOldTaxon
= UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
301 UUID uuidSyn1
= UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
302 UUID uuidSyn3
= UUID
.fromString("3fba2b22-22ae-4291-af67-faab748a5232");
303 UUID uuidSyn4
= UUID
.fromString("f9b589c7-50cf-4df2-a52e-1b85eb7e4805");
304 UUID uuidSyn5
= UUID
.fromString("fcc0bcf8-8bac-43bd-9508-1e97821587dd");
305 UUID uuidSyn6
= UUID
.fromString("0ccd4e7c-6fbd-4b7c-bd47-29e45b92f34b");
306 UUID uuidRef1
= UUID
.fromString("336f9b38-698c-45d7-be7b-993ed3355bdc");
307 UUID uuidRef2
= UUID
.fromString("c8f49d1a-69e1-48a3-98bb-45d61f3da3e7");
310 boolean moveHomotypicGroup
= true;
311 SynonymRelationshipType newSynonymRelationshipType
= null;
312 boolean keepReference
= true;
313 Reference
<?
> newReference
= null;
314 String newReferenceDetail
= null;
316 Taxon newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
317 Synonym homotypicSynonym
= (Synonym
)service
.load(uuidSyn1
);
318 Assert
.assertNotNull("Synonym should exist", homotypicSynonym
);
319 Assert
.assertEquals("Synonym should have 1 relation", 1, homotypicSynonym
.getSynonymRelations().size());
320 SynonymRelationship rel
= homotypicSynonym
.getSynonymRelations().iterator().next();
321 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
322 Taxon oldTaxon
= rel
.getAcceptedTaxon();
325 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
326 Assert
.fail("Homotypic synonym move to other taxon should throw an exception");
327 } catch (HomotypicalGroupChangeException e
) {
328 if (e
.getMessage().contains("Synonym is in homotypic group with accepted taxon and other synonym(s). First remove synonym from homotypic group of accepted taxon before moving to other taxon")){
330 commitAndStartNewTransaction(tableNames
);
332 Assert
.fail("Unexpected exception occurred: " + e
.getMessage());
336 homotypicSynonym
= (Synonym
)service
.load(uuidSyn1
);
337 Assert
.assertNotNull("Synonym should still exist", homotypicSynonym
);
338 Assert
.assertEquals("Synonym should still have 1 relation", 1, homotypicSynonym
.getSynonymRelations().size());
339 rel
= homotypicSynonym
.getSynonymRelations().iterator().next();
340 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", oldTaxon
, rel
.getAcceptedTaxon());
342 //test heterotypic synonym with other synonym in homotypic group
343 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
344 Synonym heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
345 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
346 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
347 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
348 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
349 oldTaxon
= rel
.getAcceptedTaxon();
350 moveHomotypicGroup
= false;
353 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
354 Assert
.fail("Heterotypic synonym move to other taxon should throw an exception");
355 } catch (HomotypicalGroupChangeException e
) {
356 if (e
.getMessage().contains("Synonym is in homotypic group with other synonym(s). Either move complete homotypic group or remove synonym from homotypic group prior to moving to other taxon")){
358 commitAndStartNewTransaction(tableNames
);
360 Assert
.fail("Unexpected exception occurred: " + e
.getMessage());
364 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
365 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
366 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
367 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
368 Assert
.assertEquals("Accepted taxon of single relation should still be the old taxon", oldTaxon
, rel
.getAcceptedTaxon());
371 //test heterotypic synonym with no other synonym in homotypic group
374 // printDataSet(System.err, new String[]{"TaxonBase"});
376 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
377 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn5
);
378 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
379 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
380 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
381 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
382 oldTaxon
= rel
.getAcceptedTaxon();
383 moveHomotypicGroup
= false;
387 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
388 } catch (HomotypicalGroupChangeException e
) {
389 Assert
.fail("Move of single heterotypic synonym should not throw exception: " + e
.getMessage());
392 //FIXME throws exception
393 commitAndStartNewTransaction(tableNames
);
395 // printDataSet(System.err, new String[]{"AgentBase", "TaxonBase"});
397 // printDataSet(System.err, new String[]{"TaxonBase"});
399 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn5
);
401 // printDataSet(System.err, new String[]{"TaxonBase"});
404 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
405 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
406 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
407 Assert
.assertEquals("Accepted taxon of single relation should be new taxon", newTaxon
, rel
.getAcceptedTaxon());
408 Assert
.assertEquals("Old detail should be kept", "rel5", rel
.getCitationMicroReference());
411 //test heterotypic synonym with other synonym in homotypic group and moveHomotypicGroup="true"
413 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
414 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
415 Reference
<?
> ref1
= referenceService
.load(uuidRef1
);
416 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
417 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
418 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
419 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
420 oldTaxon
= rel
.getAcceptedTaxon();
421 Assert
.assertEquals("Detail should be ref1", ref1
, rel
.getCitation());
422 Assert
.assertEquals("Detail should be 'rel3'", "rel3", rel
.getCitationMicroReference());
423 TaxonNameBase
<?
,?
> oldSynName3
= heterotypicSynonym
.getName();
425 Synonym heterotypicSynonym4
= (Synonym
)service
.load(uuidSyn4
);
426 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym4
);
427 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym4
.getSynonymRelations().size());
428 SynonymRelationship rel4
= heterotypicSynonym4
.getSynonymRelations().iterator().next();
429 Assert
.assertEquals("Accepted taxon of other synonym in group should be the old taxon", uuidOldTaxon
, rel4
.getAcceptedTaxon().getUuid());
430 Assert
.assertSame("Homotypic group of both synonyms should be same", oldSynName3
.getHomotypicalGroup() , heterotypicSynonym4
.getName().getHomotypicalGroup() );
432 moveHomotypicGroup
= true;
433 keepReference
= false;
436 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
437 } catch (HomotypicalGroupChangeException e
) {
438 Assert
.fail("Move with 'moveHomotypicGroup = true' should not throw exception: " + e
.getMessage());
441 commitAndStartNewTransaction(tableNames
);
442 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
443 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
444 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
445 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
446 Assert
.assertEquals("Accepted taxon of relation should be new taxon now", newTaxon
, rel
.getAcceptedTaxon());
447 TaxonNameBase
<?
,?
> synName3
= rel
.getSynonym().getName();
449 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn4
);
450 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
451 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
452 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
453 Assert
.assertEquals("Accepted taxon of relation should be new taxon now", newTaxon
, rel
.getAcceptedTaxon());
454 Assert
.assertNull("Old citation should be removed", rel
.getCitation());
455 Assert
.assertNull("Old detail should be removed", rel
.getCitationMicroReference());
456 TaxonNameBase
<?
,?
> synName4
= rel
.getSynonym().getName();
457 Assert
.assertEquals("Homotypic group of both synonyms should be equal", synName3
.getHomotypicalGroup() , synName4
.getHomotypicalGroup() );
458 Assert
.assertSame("Homotypic group of both synonyms should be same", synName3
.getHomotypicalGroup() , synName4
.getHomotypicalGroup() );
459 Assert
.assertEquals("Homotypic group of both synonyms should be equal to old homotypic group", oldSynName3
.getHomotypicalGroup() , synName3
.getHomotypicalGroup() );
462 //test single heterotypic synonym to homotypic synonym of new taxon
464 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
465 Reference
<?
> ref2
= referenceService
.load(uuidRef2
);
466 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn6
);
467 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
468 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
469 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
470 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
471 oldTaxon
= rel
.getAcceptedTaxon();
472 moveHomotypicGroup
= false;
473 keepReference
= false;
475 newReferenceDetail
= "newRefDetail";
476 newSynonymRelationshipType
= SynonymRelationshipType
.HOMOTYPIC_SYNONYM_OF();
479 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
480 } catch (HomotypicalGroupChangeException e
) {
481 Assert
.fail("Move of single heterotypic synonym should not throw exception: " + e
.getMessage());
484 commitAndStartNewTransaction(tableNames
);
485 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn6
);
486 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
487 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
488 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
489 Assert
.assertEquals("Relationship type should be 'homotypic synonym'", newSynonymRelationshipType
, rel
.getType());
490 Assert
.assertEquals("Accepted taxon of single relation should be new taxon", newTaxon
, rel
.getAcceptedTaxon());
491 Assert
.assertEquals("New citation should be ref2", ref2
,rel
.getCitation());
492 Assert
.assertEquals("New detail should be kept", "newRefDetail", rel
.getCitationMicroReference());
494 Assert
.assertEquals("New taxon and new synonym should have equal homotypical group", rel
.getSynonym().getHomotypicGroup(), rel
.getAcceptedTaxon().getHomotypicGroup());
495 Assert
.assertSame("New taxon and new synonym should have same homotypical group", rel
.getSynonym().getHomotypicGroup(), rel
.getAcceptedTaxon().getHomotypicGroup());
501 public final void testGetHeterotypicSynonymyGroups(){
502 Rank rank
= Rank
.SPECIES();
503 Reference
<?
> ref1
= ReferenceFactory
.newGeneric();
504 //HomotypicalGroup group = HomotypicalGroup.NewInstance();
505 Taxon taxon1
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
506 Synonym synonym0
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
507 Synonym synonym1
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
508 Synonym synonym2
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
509 synonym0
.getName().setHomotypicalGroup(taxon1
.getHomotypicGroup());
510 synonym2
.getName().setHomotypicalGroup(synonym1
.getHomotypicGroup());
511 //tax2.addHeterotypicSynonymName(synonym.getName());
512 taxon1
.addSynonym(synonym1
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
513 taxon1
.addSynonym(synonym2
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
515 service
.save(synonym1
);
516 service
.save(synonym2
);
517 service
.save(taxon1
);
519 List
<List
<Synonym
>> heteroSyns
= service
.getHeterotypicSynonymyGroups(taxon1
, null);
520 Assert
.assertEquals("There should be 1 heterotypic group", 1, heteroSyns
.size());
521 List
<Synonym
> synList
= heteroSyns
.get(0);
522 Assert
.assertEquals("There should be 2 heterotypic syns in group 1", 2, synList
.size());
525 synonym2
.setSec(ref1
);
526 heteroSyns
= service
.getHeterotypicSynonymyGroups(taxon1
, null);
527 Assert
.assertEquals("There should be 1 heterotypic group", 1, heteroSyns
.size());
528 synList
= heteroSyns
.get(0);
529 Assert
.assertEquals("getHeterotypicSynonymyGroups should be independent of sec reference", 2, synList
.size());
535 public final void testGetHomotypicSynonymsByHomotypicGroup(){
536 Rank rank
= Rank
.SPECIES();
537 Reference
<?
> ref1
= ReferenceFactory
.newGeneric();
538 //HomotypicalGroup group = HomotypicalGroup.NewInstance();
539 Taxon taxon1
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
540 Synonym synonym0
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
541 Synonym synonym1
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
542 Synonym synonym2
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
543 synonym0
.getName().setHomotypicalGroup(taxon1
.getHomotypicGroup());
544 synonym2
.getName().setHomotypicalGroup(synonym1
.getHomotypicGroup());
545 //tax2.addHeterotypicSynonymName(synonym.getName());
546 taxon1
.addSynonym(synonym0
, SynonymRelationshipType
.HOMOTYPIC_SYNONYM_OF());
547 taxon1
.addSynonym(synonym1
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
548 taxon1
.addSynonym(synonym2
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
550 service
.save(synonym1
);
551 service
.save(synonym2
);
552 service
.save(taxon1
);
554 List
<Synonym
> homoSyns
= service
.getHomotypicSynonymsByHomotypicGroup(taxon1
, null);
555 Assert
.assertEquals("There should be 1 heterotypic group", 1, homoSyns
.size());
556 Assert
.assertSame("The homotypic synonym should be synonym0", synonym0
, homoSyns
.get(0));
559 synonym0
.setSec(ref1
);
560 homoSyns
= service
.getHomotypicSynonymsByHomotypicGroup(taxon1
, null);
561 Assert
.assertEquals("getHeterotypicSynonymyGroups should be independent of sec reference", 1, homoSyns
.size());
566 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
567 //test delete synonym, but the name will not be deleted
568 public final void testDeleteSynonymSynonymTaxonDontDeleteName(){
569 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
570 "SynonymRelationship","SynonymRelationship_AUD",
571 "HomotypicalGroup","HomotypicalGroup_AUD"};
573 int nSynonyms
= service
.count(Synonym
.class);
574 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
575 int nNames
= nameService
.count(TaxonNameBase
.class);
576 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
579 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
582 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
583 SynonymDeletionConfigurator config
= new SynonymDeletionConfigurator();
584 config
.setDeleteNameIfPossible(false);
585 config
.setNewHomotypicGroupIfNeeded(true);
586 service
.deleteSynonym(synonym1
, config
);
588 this.commitAndStartNewTransaction(tableNames
);
590 nSynonyms
= service
.count(Synonym
.class);
591 Assert
.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms
);
592 nNames
= nameService
.count(TaxonNameBase
.class);
593 Assert
.assertEquals("There should be 4 names left in the database", 4, nNames
);
594 int nRelations
= service
.countAllRelationships();
595 Assert
.assertEquals("There should be no relationship left in the database", 0, nRelations
);
599 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
600 //test delete synonym and his name
601 public final void testDeleteSynonymSynonymTaxonDeleteName(){
602 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
603 "SynonymRelationship","SynonymRelationship_AUD",
604 "HomotypicalGroup","HomotypicalGroup_AUD"};
606 int nSynonyms
= service
.count(Synonym
.class);
607 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
608 int nNames
= nameService
.count(TaxonNameBase
.class);
609 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
610 int nRelations
= service
.countAllRelationships();
612 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
615 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
616 service
.deleteSynonym(synonym1
, new SynonymDeletionConfigurator());
618 this.commitAndStartNewTransaction(tableNames
);
620 nSynonyms
= service
.count(Synonym
.class);
621 Assert
.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms
);
622 nNames
= nameService
.count(TaxonNameBase
.class);
623 Assert
.assertEquals("There should be 3 names left in the database", 3, nNames
);
624 nRelations
= service
.countAllRelationships();
625 Assert
.assertEquals("There should be no relationship left in the database", 0, nRelations
);
630 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
631 //test remove synonym from taxon -> synonym and name still in the db and the synonymrelationship to the other taxon
632 //test delete synonym -> all relationships are deleted, the name is deleted and the synonym itself
633 public final void testDeleteSynonymSynonymTaxonBooleanRelToOneTaxon(){
634 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
635 "SynonymRelationship","SynonymRelationship_AUD",
636 "HomotypicalGroup","HomotypicalGroup_AUD"};
638 int nSynonyms
= service
.count(Synonym
.class);
639 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
640 int nNames
= nameService
.count(TaxonNameBase
.class);
641 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
643 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
644 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
645 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
648 Taxon taxon2
= (Taxon
)service
.load(uuidTaxon2
);
650 List
<String
> initStrat
= new ArrayList
<String
>();
651 initStrat
.add("markers");
652 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
, initStrat
);
654 taxon2
.removeSynonym(synonym1
, false);
655 service
.saveOrUpdate(taxon2
);
657 commitAndStartNewTransaction(null);
659 nSynonyms
= service
.count(Synonym
.class);
660 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
661 nNames
= nameService
.count(TaxonNameBase
.class);
662 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
663 int nRelations
= service
.countAllRelationships();
664 Assert
.assertEquals("There should be 1 relationship left in the database", 1, nRelations
);
666 synonym1
.addMarker(Marker
.NewInstance(MarkerType
.IMPORTED(), true));
667 synonym1
.addMarker(Marker
.NewInstance(MarkerType
.COMPUTED(), true));
668 service
.update(synonym1
);
669 synonym1
=(Synonym
) service
.load(uuidSynonym1
);
672 Set
<Marker
> markers
= synonym1
.getMarkers();
673 Marker marker
= markers
.iterator().next();
674 UUID markerUUID
= marker
.getUuid();
675 // taxon2 = (Taxon)service.load(uuidTaxon2);
676 synonym1
= (Synonym
)service
.load(uuidSynonym1
);
678 service
.deleteSynonym(synonym1
, new SynonymDeletionConfigurator());
680 commitAndStartNewTransaction(tableNames
);
682 nSynonyms
= service
.count(Synonym
.class);
683 Assert
.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms
);
684 nNames
= nameService
.count(TaxonNameBase
.class);
685 Assert
.assertEquals("There should be 3 names left in the database", 3, nNames
);
686 nRelations
= service
.countAllRelationships();
687 Assert
.assertEquals("There should be no relationship left in the database", 0, nRelations
);
688 marker
= markerService
.load(markerUUID
);
694 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
695 //test delete synonym, only for a special taxon, but because of other relationships it will not be deleted at all
696 public final void testDeleteSynonymSynonymTaxonBooleanDeleteOneTaxon(){
697 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
698 "SynonymRelationship","SynonymRelationship_AUD",
699 "HomotypicalGroup","HomotypicalGroup_AUD"};
702 int nSynonyms
= service
.count(Synonym
.class);
703 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
704 int nNames
= nameService
.count(TaxonNameBase
.class);
705 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
707 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
708 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
709 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
710 UUID uuidSynonym2
=UUID
.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
712 Taxon taxon1
= (Taxon
)service
.load(uuidTaxon1
);
713 Taxon taxon2
= (Taxon
)service
.load(uuidTaxon2
);
714 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
716 service
.deleteSynonym(synonym1
, taxon1
, new SynonymDeletionConfigurator());
718 this.commitAndStartNewTransaction(tableNames
);
720 nSynonyms
= service
.count(Synonym
.class);
721 Assert
.assertEquals("There should still be 2 synonyms left in the database (synonym is related to taxon2)", 2, nSynonyms
);
722 nNames
= nameService
.count(TaxonNameBase
.class);
723 Assert
.assertEquals("There should be 4 names left in the database (name not deleted as synonym was not deleted)", 4, nNames
);
724 int nRelations
= service
.countAllRelationships();
725 Assert
.assertEquals("There should be 1 relationship left in the database", 1, nRelations
);
731 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
733 public final void testDeleteSynonymSynonymTaxonBooleanWithRelatedName(){
734 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
735 "SynonymRelationship","SynonymRelationship_AUD",
736 "HomotypicalGroup","HomotypicalGroup_AUD"};
738 int nSynonyms
= service
.count(Synonym
.class);
739 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
740 int nNames
= nameService
.count(TaxonNameBase
.class);
741 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
743 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
744 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
745 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
746 UUID uuidSynonym2
=UUID
.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
747 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
749 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
750 TaxonNameBase name2
= nameService
.load(uuidSynonymName2
);
751 UUID name3Uuid
= synonym1
.getName().getUuid();
752 TaxonNameBase name3
= nameService
.load(name3Uuid
);
753 name3
.addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null);
755 service
.saveOrUpdate(synonym1
);
757 int nRelations
= nameService
.getAllRelationships(1000, 0).size();
758 logger
.info("number of name relations: " + nRelations
);
759 Assert
.assertEquals("There should be 1 name relationship left in the database", 1, nRelations
);
760 SynonymDeletionConfigurator config
= new SynonymDeletionConfigurator();
762 service
.deleteSynonym(synonym1
, config
);
764 this.commitAndStartNewTransaction(tableNames
);
765 //synonym is deleted, but the name can not be deleted because of a name relationship
766 nSynonyms
= service
.count(Synonym
.class);
767 Assert
.assertEquals("There should still be 1 synonyms left in the database", 1, nSynonyms
);
768 nNames
= nameService
.count(TaxonNameBase
.class);
769 Assert
.assertEquals("There should be 4 names left in the database (name is related to synonymName2)", 4, nNames
);
770 nRelations
= service
.countAllRelationships();
771 //may change with better implementation of countAllRelationships (see #2653)
772 nRelations
= nameService
.getAllRelationships(1000, 0).size();
773 logger
.info("number of name relations: " + nRelations
);
774 Assert
.assertEquals("There should be 1 name relationship left in the database", 1, nRelations
);
778 name2
= nameService
.load(uuidSynonymName2
);
779 NameRelationship rel
= CdmBase
.deproxy(name2
.getNameRelations().iterator().next(), NameRelationship
.class);
780 name2
.removeNameRelationship(rel
);
781 nameService
.save(name2
);
783 this.endTransaction();
787 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
788 public final void testDeleteSynonymSynonymTaxonBooleanWithRelatedNameDeleteAllNameRelations(){
789 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
790 "SynonymRelationship","SynonymRelationship_AUD",
791 "HomotypicalGroup","HomotypicalGroup_AUD"};
793 int nSynonyms
= service
.count(Synonym
.class);
794 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
795 int nNames
= nameService
.count(TaxonNameBase
.class);
796 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
798 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
799 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
800 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
801 UUID uuidSynonym2
=UUID
.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
802 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
804 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
805 TaxonNameBase name2
= nameService
.load(uuidSynonymName2
);
806 UUID name3Uuid
= synonym1
.getName().getUuid();
807 TaxonNameBase name3
= nameService
.load(name3Uuid
);
808 name3
.addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null);
810 service
.saveOrUpdate(synonym1
);
812 int nRelations
= nameService
.getAllRelationships(1000, 0).size();
813 logger
.info("number of name relations: " + nRelations
);
814 Assert
.assertEquals("There should be 1 name relationship left in the database", 1, nRelations
);
815 SynonymDeletionConfigurator config
= new SynonymDeletionConfigurator();
816 NameDeletionConfigurator nameDeletionConfig
= new NameDeletionConfigurator();
817 nameDeletionConfig
.setRemoveAllNameRelationships(true);
818 config
.setNameDeletionConfig(nameDeletionConfig
);
820 service
.deleteSynonym(synonym1
, config
);
822 this.commitAndStartNewTransaction(tableNames
);
824 nSynonyms
= service
.count(Synonym
.class);
825 Assert
.assertEquals("There should still be 1 synonyms left in the database", 1, nSynonyms
);
826 nNames
= nameService
.count(TaxonNameBase
.class);
827 Assert
.assertEquals("There should be 3 names left in the database ", 3, nNames
);
828 nRelations
= service
.countAllRelationships();
829 //may change with better implementation of countAllRelationships (see #2653)
830 nRelations
= nameService
.getAllRelationships(1000, 0).size();
831 logger
.info("number of name relations: " + nRelations
);
832 Assert
.assertEquals("There should be no name relationship left in the database", 0, nRelations
);
836 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
837 public final void testDeleteSynonymSynonymTaxonBooleanWithRelatedNameIgnoreIsBasionym(){
838 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
839 "SynonymRelationship","SynonymRelationship_AUD",
840 "HomotypicalGroup","HomotypicalGroup_AUD"};
842 int nSynonyms
= service
.count(Synonym
.class);
843 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
844 int nNames
= nameService
.count(TaxonNameBase
.class);
845 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
847 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
848 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
849 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
850 UUID uuidSynonym2
=UUID
.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
851 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
853 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
854 TaxonNameBase name2
= nameService
.load(uuidSynonymName2
);
855 UUID name3Uuid
= synonym1
.getName().getUuid();
856 TaxonNameBase name3
= nameService
.load(name3Uuid
);
857 name3
.addRelationshipFromName(name2
, NameRelationshipType
.BASIONYM(), null);
859 service
.saveOrUpdate(synonym1
);
861 int nRelations
= nameService
.getAllRelationships(1000, 0).size();
862 logger
.info("number of name relations: " + nRelations
);
863 Assert
.assertEquals("There should be 1 name relationship left in the database", 1, nRelations
);
864 SynonymDeletionConfigurator config
= new SynonymDeletionConfigurator();
865 NameDeletionConfigurator nameDeletionConfig
= new NameDeletionConfigurator();
866 nameDeletionConfig
.setIgnoreIsBasionymFor(true);
867 config
.setNameDeletionConfig(nameDeletionConfig
);
869 service
.deleteSynonym(synonym1
, config
);
871 this.commitAndStartNewTransaction(tableNames
);
873 nSynonyms
= service
.count(Synonym
.class);
874 Assert
.assertEquals("There should still be 1 synonyms left in the database", 1, nSynonyms
);
875 nNames
= nameService
.count(TaxonNameBase
.class);
876 Assert
.assertEquals("There should be 3 names left in the database ", 3, nNames
);
877 nRelations
= service
.countAllRelationships();
878 //may change with better implementation of countAllRelationships (see #2653)
879 nRelations
= nameService
.getAllRelationships(1000, 0).size();
880 logger
.info("number of name relations: " + nRelations
);
881 Assert
.assertEquals("There should be no name relationship left in the database", 0, nRelations
);
886 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
887 public final void testDeleteSynonymSynonymTaxonBooleanWithRollback(){
888 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
889 "SynonymRelationship","SynonymRelationship_AUD",
890 "HomotypicalGroup","HomotypicalGroup_AUD"};
892 int nSynonyms
= service
.count(Synonym
.class);
893 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
894 int nNames
= nameService
.count(TaxonNameBase
.class);
895 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
896 int nRelations
= service
.countAllRelationships();
899 //may change with better implementation of countAllRelationships (see #2653)
902 Assert
.assertEquals("There should be 2 relationships in the database (the 2 synonym relationship) but no name relationship", 2, nRelations
);
904 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
905 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
907 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
908 TaxonNameBase name2
= nameService
.load(uuidSynonymName2
);
909 synonym1
.getName().addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null);
911 service
.deleteSynonym(synonym1
, new SynonymDeletionConfigurator());
914 // printDataSet(System.out, tableNames);
915 this.startNewTransaction();
917 nSynonyms
= service
.count(Synonym
.class);
918 Assert
.assertEquals("There should still be 2 synonyms left in the database", 2, nSynonyms
);
919 nNames
= nameService
.count(TaxonNameBase
.class);
920 Assert
.assertEquals("There should be 4 names left in the database", 4, nNames
);
921 nRelations
= service
.countAllRelationships();
922 //may change with better implementation of countAllRelationships (see #2653)
923 Assert
.assertEquals("There should be 2 relationship in the database (the 2 synonym relationship) but no name relationship", 2, nRelations
);
928 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
929 public final void testDeleteSynonymSynonymTaxonBooleanWithoutTransaction(){
930 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
931 "SynonymRelationship","SynonymRelationship_AUD",
932 "HomotypicalGroup","HomotypicalGroup_AUD"};
934 int nSynonyms
= service
.count(Synonym
.class);
935 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
936 int nNames
= nameService
.count(TaxonNameBase
.class);
937 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
938 int nRelations
= service
.countAllRelationships();
939 //may change with better implementation of countAllRelationships (see #2653)
940 Assert
.assertEquals("There should be 2 relationship in the database (the 2 synonym relationships) but no name relationship", 2, nRelations
);
942 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
943 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
945 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
946 TaxonNameBase name2
= nameService
.load(uuidSynonymName2
);
947 synonym1
.getName().addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null);
949 service
.saveOrUpdate(synonym1
);
952 this.endTransaction();
954 // printDataSet(System.out, tableNames);
956 //out of wrapping transaction
957 service
.deleteSynonym(synonym1
, new SynonymDeletionConfigurator());
959 this.startNewTransaction();
961 nSynonyms
= service
.count(Synonym
.class);
962 Assert
.assertEquals("There should still be 1 synonyms left in the database. The rollback on name delete should not lead to rollback in synonym delete.", 1, nSynonyms
);
963 nNames
= nameService
.count(TaxonNameBase
.class);
964 Assert
.assertEquals("There should be 4 names left in the database", 4, nNames
);
965 nRelations
= service
.countAllRelationships();
966 Assert
.assertEquals("There should be no taxon or synonym relationship in the database", 0, nRelations
);
967 nRelations
= nameService
.getAllRelationships(1000,0).size();
968 Assert
.assertEquals("There should be one name relationship in the database", 1, nRelations
);
973 @DataSet("TaxonServiceImplTest.testInferredSynonyms.xml")
974 public void testCreateInferredSynonymy(){
976 UUID classificationUuid
= UUID
.fromString("aeee7448-5298-4991-b724-8d5b75a0a7a9");
977 Classification tree
= classificationService
.find(classificationUuid
);
978 UUID taxonUuid
= UUID
.fromString("bc09aca6-06fd-4905-b1e7-cbf7cc65d783");
979 TaxonBase
<?
> taxonBase
= service
.find(taxonUuid
);
980 List
<TaxonBase
> synonyms
= service
.list(Synonym
.class, null, null, null, null);
981 assertEquals("Number of synonyms should be 2",2,synonyms
.size());
982 Taxon taxon
= (Taxon
)taxonBase
;
984 //synonyms = taxonDao.getAllSynonyms(null, null);
985 //assertEquals("Number of synonyms should be 2",2,synonyms.size());
986 List
<Synonym
> inferredSynonyms
= service
.createInferredSynonyms(taxon
, tree
, SynonymRelationshipType
.INFERRED_EPITHET_OF(), true);
987 assertNotNull("there should be a new synonym ", inferredSynonyms
);
988 assertEquals ("the name of inferred epithet should be SynGenus lachesis", "SynGenus lachesis sec. Sp. Pl.", inferredSynonyms
.get(0).getTitleCache());
990 inferredSynonyms
= service
.createInferredSynonyms(taxon
, tree
, SynonymRelationshipType
.INFERRED_GENUS_OF(), true);
991 assertNotNull("there should be a new synonym ", inferredSynonyms
);
992 assertEquals ("the name of inferred epithet should be SynGenus lachesis", "Acherontia ciprosus sec. Sp. Pl.", inferredSynonyms
.get(0).getTitleCache());
994 inferredSynonyms
= service
.createInferredSynonyms(taxon
, tree
, SynonymRelationshipType
.POTENTIAL_COMBINATION_OF(), true);
995 assertNotNull("there should be a new synonym ", inferredSynonyms
);
996 assertEquals ("the name of inferred epithet should be SynGenus lachesis", "SynGenus ciprosus sec. Sp. Pl.", inferredSynonyms
.get(0).getTitleCache());
997 //assertTrue("set of synonyms should contain an inferred Synonym ", synonyms.contains(arg0))
1001 @DataSet("BlankDataSet.xml")
1002 public final void testTaxonDeletionConfig(){
1003 final String
[]tableNames
= {
1004 "Classification", "Classification_AUD",
1005 "TaxonBase","TaxonBase_AUD",
1006 "TaxonNode","TaxonNode_AUD",
1007 "TaxonNameBase","TaxonNameBase_AUD",
1008 "SynonymRelationship","SynonymRelationship_AUD",
1009 "TaxonRelationship", "TaxonRelationship_AUD",
1010 "TaxonDescription", "TaxonDescription_AUD",
1011 "HomotypicalGroup","HomotypicalGroup_AUD",
1012 "PolytomousKey","PolytomousKey_AUD",
1013 "PolytomousKeyNode","PolytomousKeyNode_AUD",
1014 "Media","Media_AUD",
1015 "WorkingSet","WorkingSet_AUD",
1016 "DescriptionElementBase","DescriptionElementBase_AUD"};
1018 UUID uuidParent
=UUID
.fromString("b5271d4f-e203-4577-941f-00d76fa9f4ca");
1019 UUID uuidChild1
=UUID
.fromString("326167f9-0b97-4e7d-b1bf-4ca47b82e21e");
1020 UUID uuidSameAs
=UUID
.fromString("c2bb0f01-f2dd-43fb-ba12-2a85727ccb8d");
1021 commitAndStartNewTransaction(tableNames
);
1022 Taxon testTaxon
= TaxonGenerator
.getTestTaxon();
1023 service
.save(testTaxon
);
1024 commitAndStartNewTransaction(tableNames
);
1025 int nTaxa
= service
.count(Taxon
.class);
1027 Assert
.assertEquals("There should be 4 taxa in the database", 4, nTaxa
);
1028 Taxon parent
= (Taxon
)service
.find(TaxonGenerator
.GENUS_UUID
);
1029 Assert
.assertNotNull("Parent taxon should exist", parent
);
1030 Taxon child1
= (Taxon
)service
.find(TaxonGenerator
.SPECIES1_UUID
);
1031 Assert
.assertNotNull("Child taxon should exist", child1
);
1032 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1033 config
.setDeleteTaxonNodes(false);
1034 config
.setDeleteMisappliedNamesAndInvalidDesignations(false);
1036 //commitAndStartNewTransaction(tableNames);
1038 service
.deleteTaxon(child1
, config
, null);
1039 Assert
.fail("Delete should throw an error as long as name is used in classification.");
1040 } catch (DataChangeNoRollbackException e
) {
1041 if (e
.getMessage().contains("Taxon can't be deleted as it is used in a classification node")){
1043 commitAndStartNewTransaction(tableNames
);
1045 Assert
.fail("Unexpected error occurred when trying to delete taxon: " + e
.getMessage());
1049 nTaxa
= service
.count(Taxon
.class);
1050 Assert
.assertEquals("There should be 4 taxa in the database", 4, nTaxa
);
1051 child1
= (Taxon
)service
.find(TaxonGenerator
.SPECIES1_UUID
);
1052 Assert
.assertNotNull("Child taxon should exist", child1
);
1053 Assert
.assertEquals("Child should belong to 1 node", 1, child1
.getTaxonNodes().size());
1055 TaxonNode node
= child1
.getTaxonNodes().iterator().next();
1056 TaxonNode parentNode
= node
.getParent();
1057 parentNode
=CdmBase
.deproxy(parentNode
, TaxonNode
.class);
1058 parentNode
.deleteChildNode(node
);
1059 nodeService
.save(parentNode
);
1060 commitAndStartNewTransaction(tableNames
);
1062 child1
= (Taxon
)service
.find(TaxonGenerator
.SPECIES1_UUID
);
1064 assertEquals(0, child1
.getTaxonNodes().size());
1067 service
.deleteTaxon(child1
, config
, null);
1068 } catch (DataChangeNoRollbackException e
) {
1069 Assert
.fail("Delete should not throw an exception anymore");
1071 nTaxa
= service
.count(Taxon
.class);
1072 Assert
.assertEquals("There should be 3 taxa in the database", 3, nTaxa
);
1074 config
.setDeleteTaxonNodes(true);
1075 Taxon child2
=(Taxon
) service
.find(TaxonGenerator
.SPECIES2_UUID
);
1078 service
.deleteTaxon(child2
, config
, null);
1079 } catch (DataChangeNoRollbackException e
) {
1080 Assert
.fail("Delete should not throw an exception");
1082 //service.find(uuid);
1084 nTaxa
= service
.count(Taxon
.class);
1085 Assert
.assertEquals("There should be 2 taxa in the database",2, nTaxa
);
1086 // nNames = nameService.count(TaxonNameBase.class);
1087 // Assert.assertEquals("There should be 3 names left in the database", 3, nNames);
1088 // int nRelations = service.countAllRelationships();
1089 // Assert.assertEquals("There should be no relationship left in the database", 0, nRelations);
1094 @DataSet(value
="BlankDataSet.xml")
1095 public final void testDeleteTaxon(){
1097 //create a small classification
1098 Taxon testTaxon
= TaxonGenerator
.getTestTaxon();
1100 UUID uuid
= service
.save(testTaxon
);
1102 Taxon speciesTaxon
= (Taxon
)service
.find(TaxonGenerator
.SPECIES1_UUID
);
1103 Iterator
<TaxonDescription
> descriptionIterator
= speciesTaxon
.getDescriptions().iterator();
1104 UUID descrUUID
= null;
1105 UUID descrElementUUID
= null;
1106 if (descriptionIterator
.hasNext()){
1107 TaxonDescription descr
= descriptionIterator
.next();
1108 descrUUID
= descr
.getUuid();
1109 descrElementUUID
= descr
.getElements().iterator().next().getUuid();
1111 BotanicalName taxonName
= (BotanicalName
) nameService
.find(TaxonGenerator
.SPECIES1_NAME_UUID
);
1112 assertNotNull(taxonName
);
1114 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1115 config
.setDeleteNameIfPossible(false);
1120 service
.deleteTaxon(speciesTaxon
, config
, null);
1121 } catch (DataChangeNoRollbackException e
) {
1122 e
.printStackTrace();
1126 commitAndStartNewTransaction(null);
1128 taxonName
= (BotanicalName
) nameService
.find(TaxonGenerator
.SPECIES1_NAME_UUID
);
1129 Taxon taxon
= (Taxon
)service
.find(TaxonGenerator
.SPECIES1_UUID
);
1131 //descriptionService.find(descrUUID);
1132 assertNull(descriptionService
.find(descrUUID
));
1133 assertNull(descriptionService
.getDescriptionElementByUuid(descrElementUUID
));
1134 //assertNull(synName);
1135 assertNotNull(taxonName
);
1142 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="BlankDataSet.xml")
1143 public final void testDeleteTaxonDeleteSynonymRelations(){
1145 final String
[]tableNames
= {
1146 "Classification", "Classification_AUD",
1147 "TaxonBase","TaxonBase_AUD",
1148 "TaxonNode","TaxonNode_AUD",
1149 "TaxonNameBase","TaxonNameBase_AUD"};
1150 commitAndStartNewTransaction(tableNames
);
1151 //create a small classification
1152 Taxon testTaxon
= TaxonGenerator
.getTestTaxon();
1154 UUID uuid
= service
.save(testTaxon
);
1156 Taxon speciesTaxon
= (Taxon
)service
.find(TaxonGenerator
.SPECIES2_UUID
);
1158 SynonymRelationship synRel
= speciesTaxon
.getSynonymRelations().iterator().next();
1159 UUID synonymRelationUuid
= synRel
.getUuid();
1160 UUID synonymUuid
= synRel
.getSynonym().getUuid();
1161 int i
= service
.getAllRelationships(1000, 0).size();
1163 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1164 config
.setDeleteSynonymsIfPossible(false);
1167 service
.deleteTaxon(speciesTaxon
, config
, null);
1168 } catch (DataChangeNoRollbackException e
) {
1169 e
.printStackTrace();
1173 commitAndStartNewTransaction(null);
1175 Taxon taxon
= (Taxon
)service
.find(TaxonGenerator
.SPECIES2_UUID
);
1176 assertNull("The deleted taxon should no longer exist", taxon
);
1178 assertNotNull("The synonym should still exist since DeleteSynonymsIfPossible was false", service
.find(synonymUuid
));
1180 for(RelationshipBase rel
: service
.getAllRelationships(1000, 0)){
1181 if(rel
instanceof SynonymRelationship
&& rel
.getUuid().equals(synonymRelationUuid
)){
1182 Assert
.fail("The SynonymRelationship should no longer exist");
1189 @DataSet(value
="BlankDataSet.xml")
1190 public final void testDeleteTaxonNameUsedInOtherContext(){
1192 //create a small classification
1193 Taxon testTaxon
= TaxonGenerator
.getTestTaxon();
1195 UUID uuid
= service
.save(testTaxon
);
1197 Taxon speciesTaxon
= (Taxon
)service
.find(TaxonGenerator
.SPECIES1_UUID
);
1199 BotanicalName taxonName
= (BotanicalName
) nameService
.find(TaxonGenerator
.SPECIES1_NAME_UUID
);
1200 assertNotNull(taxonName
);
1201 BotanicalName fromName
= BotanicalName
.NewInstance(Rank
.SPECIES());
1202 taxonName
.addRelationshipFromName(fromName
, NameRelationshipType
.VALIDATED_BY_NAME(), null);
1204 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1205 config
.setDeleteNameIfPossible(true);
1207 service
.deleteTaxon(speciesTaxon
, config
, null);
1208 } catch (DataChangeNoRollbackException e
) {
1211 e
.printStackTrace();
1213 commitAndStartNewTransaction(null);
1215 taxonName
= (BotanicalName
) nameService
.find(TaxonGenerator
.SPECIES1_NAME_UUID
);
1216 Taxon taxon
= (Taxon
)service
.find(TaxonGenerator
.SPECIES1_UUID
);
1217 //because of the namerelationship the name cannot be deleted
1218 assertNotNull(taxonName
);
1224 @DataSet(value
="BlankDataSet.xml")
1225 public final void testDeleteTaxonNameUsedInTwoClassificationsDeleteAllNodes(){
1226 commitAndStartNewTransaction(null);
1227 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1228 //create a small classification
1229 Taxon testTaxon
= TaxonGenerator
.getTestTaxon();
1231 UUID uuid
= service
.save(testTaxon
);
1232 //BotanicalName name = nameService.find(uuid);
1233 Set
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes();
1234 TaxonNode node
= nodes
.iterator().next();
1235 List
<TaxonNode
> childNodes
= node
.getChildNodes();
1236 TaxonNode childNode
= childNodes
.iterator().next();
1237 UUID childUUID
= childNode
.getTaxon().getUuid();
1238 Classification secondClassification
= TaxonGenerator
.getTestClassification("secondClassification");
1240 secondClassification
.addChildTaxon(testTaxon
, null, null);
1241 //delete the taxon in all classifications
1243 service
.deleteTaxon(testTaxon
, config
, null);
1244 } catch (DataChangeNoRollbackException e
) {
1247 commitAndStartNewTransaction(null);
1248 Taxon tax
= (Taxon
)service
.find(uuid
);
1250 Taxon childTaxon
= (Taxon
)service
.find(childUUID
);
1252 commitAndStartNewTransaction(null);
1261 @DataSet(value
="BlankDataSet.xml")
1262 public final void testDeleteTaxonNameUsedInTwoClassificationsDoNotDeleteAllNodes(){
1263 // delete the taxon only in second classification, this should delete only the nodes, not the taxa
1264 Taxon testTaxon
= TaxonGenerator
.getTestTaxon();
1265 UUID uuid
= service
.save(testTaxon
);
1266 Classification secondClassification
= TaxonGenerator
.getTestClassification("secondClassification");
1267 Set
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes();
1268 TaxonNode node
= nodes
.iterator().next();
1269 List
<TaxonNode
> childNodes
= node
.getChildNodes();
1270 TaxonNode childNode
= childNodes
.iterator().next();
1271 UUID childUUID
= childNode
.getTaxon().getUuid();
1272 childNode
= secondClassification
.addChildTaxon(testTaxon
, null, null);
1273 UUID childNodeUUID
= childNode
.getUuid();
1275 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1276 config
.setDeleteInAllClassifications(false);
1278 service
.deleteTaxon(testTaxon
, config
, secondClassification
);
1279 Assert
.fail("The taxon should not be deletable because it is used in a second classification and the configuration is set to deleteInAllClassifications = false");
1280 } catch (DataChangeNoRollbackException e
) {
1281 logger
.debug(e
.getMessage());
1284 //commitAndStartNewTransaction(null);
1285 Taxon tax
= (Taxon
)service
.find(uuid
);
1287 Taxon childTaxon
= (Taxon
)service
.find(childUUID
);
1289 node
= nodeService
.find(childNodeUUID
);
1294 @DataSet(value
="BlankDataSet.xml")
1295 public final void testTaxonNodeDeletionConfiguratorMoveToParent(){
1296 //test childHandling MOVE_TO_PARENT:
1297 Taxon testTaxon
= TaxonGenerator
.getTestTaxon();
1298 UUID uuid
= service
.save(testTaxon
);
1300 Taxon topMost
= Taxon
.NewInstance(BotanicalName
.NewInstance(Rank
.FAMILY()), null);
1302 Iterator
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes().iterator();
1303 TaxonNode node
=nodes
.next();
1304 Classification classification
= node
.getClassification();
1305 classification
.addParentChild(topMost
, testTaxon
, null, null);
1306 UUID topMostUUID
= service
.save(topMost
);
1308 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1309 config
.getTaxonNodeConfig().setChildHandling(ChildHandling
.MOVE_TO_PARENT
);
1312 service
.deleteTaxon(testTaxon
, config
, null);
1313 } catch (DataChangeNoRollbackException e
) {
1317 commitAndStartNewTransaction(null);
1318 Taxon tax
= (Taxon
)service
.find(uuid
);
1320 tax
= (Taxon
)service
.find(topMostUUID
);
1321 Set
<TaxonNode
> topMostNodes
= tax
.getTaxonNodes();
1322 assertNotNull(topMostNodes
);
1323 assertEquals("there should be one taxon node", 1, topMostNodes
.size());
1324 nodes
= topMostNodes
.iterator();
1325 TaxonNode topMostNode
= nodes
.next();
1326 int size
= topMostNode
.getChildNodes().size();
1328 assertEquals(2, size
);
1332 @DataSet(value
="BlankDataSet.xml")
1333 public final void testTaxonNodeDeletionConfiguratorDeleteChildren(){
1334 //test childHandling DELETE:
1335 Taxon testTaxon
= TaxonGenerator
.getTestTaxon();
1336 UUID uuid
= service
.save(testTaxon
);
1338 Taxon topMost
= Taxon
.NewInstance(BotanicalName
.NewInstance(Rank
.FAMILY()), null);
1340 Iterator
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes().iterator();
1341 TaxonNode node
=nodes
.next();
1342 UUID taxonNodeUUID
= node
.getUuid();
1343 Classification classification
= node
.getClassification();
1344 classification
.addParentChild(topMost
, testTaxon
, null, null);
1345 UUID topMostUUID
= service
.save(topMost
);
1347 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1348 config
.getTaxonNodeConfig().setChildHandling(ChildHandling
.DELETE
);
1351 service
.deleteTaxon(testTaxon
, config
, null);
1352 } catch (DataChangeNoRollbackException e
) {
1356 commitAndStartNewTransaction(null);
1357 Taxon tax
= (Taxon
)service
.find(uuid
);
1359 tax
= (Taxon
)service
.find(topMostUUID
);
1360 Set
<TaxonNode
> topMostNodes
= tax
.getTaxonNodes();
1361 assertNotNull(topMostNodes
);
1362 assertEquals("there should be one taxon node", 1, topMostNodes
.size());
1363 nodes
= topMostNodes
.iterator();
1364 TaxonNode topMostNode
= nodes
.next();
1365 int size
= topMostNode
.getChildNodes().size();
1366 node
= nodeService
.find(taxonNodeUUID
);
1368 assertEquals(0, size
);
1373 @DataSet(value
="BlankDataSet.xml")
1374 public final void testTaxonDeletionConfiguratorDeleteMarker(){
1375 //test childHandling DELETE:
1376 Taxon testTaxon
= TaxonGenerator
.getTestTaxon();
1377 UUID uuid
= service
.save(testTaxon
);
1379 Taxon topMost
= Taxon
.NewInstance(BotanicalName
.NewInstance(Rank
.FAMILY()), null);
1381 Iterator
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes().iterator();
1382 TaxonNode node
=nodes
.next();
1383 Classification classification
= node
.getClassification();
1384 classification
.addParentChild(topMost
, testTaxon
, null, null);
1385 UUID topMostUUID
= service
.save(topMost
);
1386 Marker marker
= Marker
.NewInstance(testTaxon
, true, MarkerType
.IS_DOUBTFUL());
1387 testTaxon
.addMarker(marker
);
1388 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1389 config
.getTaxonNodeConfig().setChildHandling(ChildHandling
.DELETE
);
1392 service
.deleteTaxon(testTaxon
, config
, null);
1393 } catch (DataChangeNoRollbackException e
) {
1397 commitAndStartNewTransaction(null);
1398 Taxon tax
= (Taxon
)service
.find(uuid
);
1400 tax
= (Taxon
)service
.find(topMostUUID
);
1401 Set
<TaxonNode
> topMostNodes
= tax
.getTaxonNodes();
1402 assertNotNull(topMostNodes
);
1403 assertEquals("there should be one taxon node", 1, topMostNodes
.size());
1404 nodes
= topMostNodes
.iterator();
1405 TaxonNode topMostNode
= nodes
.next();
1406 int size
= topMostNode
.getChildNodes().size();
1408 assertEquals(0, size
);
1413 @DataSet(value
="BlankDataSet.xml")
1414 public final void testTaxonDeletionConfiguratorTaxonWithMisappliedName(){
1416 Taxon testTaxon
= TaxonGenerator
.getTestTaxon();
1417 UUID uuid
= service
.save(testTaxon
);
1419 Taxon misappliedName
= Taxon
.NewInstance(BotanicalName
.NewInstance(Rank
.GENUS()), null);
1421 Iterator
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes().iterator();
1422 TaxonNode node
=nodes
.next();
1423 testTaxon
.addMisappliedName(misappliedName
, null, null);
1424 UUID misappliedNameUUID
= service
.save(misappliedName
);
1426 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1427 config
.setDeleteMisappliedNamesAndInvalidDesignations(true);
1430 service
.deleteTaxon(testTaxon
, config
, null);
1431 } catch (DataChangeNoRollbackException e
) {
1435 commitAndStartNewTransaction(null);
1436 Taxon tax
= (Taxon
)service
.find(uuid
);
1438 tax
= (Taxon
)service
.find(misappliedNameUUID
);
1439 //TODO: is that correct or should it be deleted because there is no relation to anything
1444 @DataSet(value
="BlankDataSet.xml")
1445 public final void testTaxonDeletionConfiguratorTaxonWithMisappliedNameDoNotDelete(){
1447 Taxon testTaxon
= TaxonGenerator
.getTestTaxon();
1448 UUID uuid
= service
.save(testTaxon
);
1450 Taxon misappliedName
= Taxon
.NewInstance(BotanicalName
.NewInstance(Rank
.GENUS()), null);
1452 Iterator
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes().iterator();
1453 TaxonNode node
=nodes
.next();
1454 testTaxon
.addMisappliedName(misappliedName
, null, null);
1455 UUID misappliedNameUUID
= service
.save(misappliedName
);
1457 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1458 config
.setDeleteMisappliedNamesAndInvalidDesignations(false);
1461 service
.deleteTaxon(testTaxon
, config
, null);
1462 } catch (DataChangeNoRollbackException e
) {
1466 commitAndStartNewTransaction(null);
1467 Taxon tax
= (Taxon
)service
.find(uuid
);
1469 tax
= (Taxon
)service
.find(misappliedNameUUID
);
1470 //TODO: is that correct or should it be deleted because there is no relation to anything
1476 @DataSet(value
="BlankDataSet.xml")
1477 public final void testTaxonDeletionConfiguratorTaxonMisappliedName(){
1479 Taxon testTaxon
= TaxonGenerator
.getTestTaxon();
1480 UUID uuid
= service
.save(testTaxon
);
1482 Taxon misappliedNameTaxon
= Taxon
.NewInstance(BotanicalName
.NewInstance(Rank
.GENUS()), null);
1484 Iterator
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes().iterator();
1485 TaxonNode node
=nodes
.next();
1486 testTaxon
.addMisappliedName(misappliedNameTaxon
, null, null);
1487 UUID misappliedNameUUID
= service
.save(misappliedNameTaxon
);
1488 misappliedNameTaxon
= (Taxon
)service
.find(misappliedNameUUID
);
1489 UUID misNameUUID
= misappliedNameTaxon
.getName().getUuid();
1491 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1495 service
.deleteTaxon(misappliedNameTaxon
, config
, null);
1496 } catch (DataChangeNoRollbackException e
) {
1497 e
.printStackTrace();
1501 commitAndStartNewTransaction(null);
1502 Taxon tax
= (Taxon
)service
.find(uuid
);
1504 tax
= (Taxon
)service
.find(misappliedNameUUID
);
1505 BotanicalName name
= (BotanicalName
) nameService
.find(misNameUUID
);