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
;
16 import java
.util
.List
;
18 import java
.util
.UUID
;
20 import org
.apache
.log4j
.Logger
;
21 import org
.junit
.Assert
;
22 import org
.junit
.Ignore
;
23 import org
.junit
.Test
;
24 import org
.unitils
.dbunit
.annotation
.DataSet
;
25 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
27 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
28 import eu
.etaxonomy
.cdm
.api
.service
.exception
.HomotypicalGroupChangeException
;
29 import eu
.etaxonomy
.cdm
.api
.service
.exception
.ReferencedObjectUndeletableException
;
30 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
31 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
32 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
33 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
34 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
35 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
36 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
37 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
38 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
39 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
40 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
41 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
42 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
43 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
44 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
45 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
46 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
47 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
48 import eu
.etaxonomy
.cdm
.test
.unitils
.CleanSweepInsertLoadStrategy
;
55 public class TaxonServiceImplTest
extends CdmTransactionalIntegrationTest
{
56 @SuppressWarnings("unused")
57 private static final Logger logger
= Logger
.getLogger(TaxonServiceImplTest
.class);
60 private ITaxonService service
;
63 private INameService nameService
;
66 private IReferenceService referenceService
;
69 private IClassificationService classificationService
;
72 /****************** TESTS *****************************/
76 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#getTaxonByUuid(java.util.UUID)}.
79 public final void testGetTaxonByUuid() {
80 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
81 UUID uuid
= service
.save(expectedTaxon
);
82 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
83 assertEquals(expectedTaxon
, actualTaxon
);
87 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#saveTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)}.
90 public final void testSaveTaxon() {
91 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
92 UUID uuid
= service
.save(expectedTaxon
);
93 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
94 assertEquals(expectedTaxon
, actualTaxon
);
98 public final void testSaveOrUpdateTaxon() {
99 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
100 UUID uuid
= service
.save(expectedTaxon
);
101 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
102 assertEquals(expectedTaxon
, actualTaxon
);
104 actualTaxon
.setName(BotanicalName
.NewInstance(Rank
.SPECIES()));
106 service
.saveOrUpdate(actualTaxon
);
112 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#removeTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)}.
115 public final void testRemoveTaxon() {
116 Taxon taxon
= Taxon
.NewInstance(BotanicalName
.NewInstance(Rank
.UNKNOWN_RANK()), null);
117 UUID uuid
= service
.save(taxon
);
118 service
.delete(taxon
);
119 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
120 assertNull(actualTaxon
);
125 public final void testMakeTaxonSynonym() {
126 Rank rank
= Rank
.SPECIES();
127 Taxon tax1
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test1", null, null, null, null, null, null, null), null);
128 Synonym synonym
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
129 tax1
.addHomotypicSynonym(synonym
, null, null);
130 UUID uuidTaxon
= service
.save(tax1
);
131 UUID uuidSyn
= service
.save(synonym
);
133 service
.swapSynonymAndAcceptedTaxon(synonym
, tax1
);
136 TaxonBase
<?
> tax
= service
.find(uuidTaxon
);
137 TaxonBase
<?
> syn
= service
.find(uuidSyn
);
138 HomotypicalGroup groupTest
= tax
.getHomotypicGroup();
139 HomotypicalGroup groupTest2
= syn
.getHomotypicGroup();
140 assertEquals(groupTest
, groupTest2
);
145 public final void testChangeSynonymToAcceptedTaxon(){
146 Rank rank
= Rank
.SPECIES();
147 //HomotypicalGroup group = HomotypicalGroup.NewInstance();
148 Taxon taxWithoutSyn
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test1", null, null, null, null, null, null, null), null);
149 Taxon taxWithSyn
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
150 Synonym synonym
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
151 Synonym synonym2
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
152 synonym2
.getName().setHomotypicalGroup(synonym
.getHomotypicGroup());
153 //tax2.addHeterotypicSynonymName(synonym.getName());
154 taxWithSyn
.addSynonym(synonym
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
155 taxWithSyn
.addSynonym(synonym2
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
157 service
.save(taxWithoutSyn
);
158 UUID uuidSyn
= service
.save(synonym
);
159 service
.save(synonym2
);
160 service
.save(taxWithSyn
);
164 taxon
= service
.changeSynonymToAcceptedTaxon(synonym
, taxWithSyn
, true, true, null, null);
165 } catch (HomotypicalGroupChangeException e
) {
166 Assert
.fail("Invocation of change method should not throw an exception");
168 //test flush (resave deleted object)
169 TaxonBase
<?
> syn
= service
.find(uuidSyn
);
171 Assert
.assertEquals("New taxon should have 1 synonym relationship (the old homotypic synonym)", 1, taxon
.getSynonymRelations().size());
176 * Old implementation taken from {@link TaxonServiceImplBusinessTest} for old version of method.
177 * 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)}.
180 public final void testMoveSynonymToAnotherTaxon_OLD() {
181 SynonymRelationshipType heteroTypicSynonymRelationshipType
= SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF();
182 Reference
<?
> reference
= ReferenceFactory
.newGeneric();
183 String referenceDetail
= "test";
185 NonViralName
<?
> t1n
= NonViralName
.NewInstance(null);
186 Taxon t1
= Taxon
.NewInstance(t1n
, reference
);
187 NonViralName
<?
> t2n
= NonViralName
.NewInstance(null);
188 Taxon t2
= Taxon
.NewInstance(t2n
, reference
);
189 NonViralName
<?
> s1n
= NonViralName
.NewInstance(null);
190 Synonym s1
= Synonym
.NewInstance(s1n
, reference
);
191 t1
.addSynonym(s1
, heteroTypicSynonymRelationshipType
);
193 SynonymRelationship synonymRelation
= t1
.getSynonymRelations().iterator().next();
195 boolean keepReference
= false;
196 boolean moveHomotypicGroup
= false;
198 service
.moveSynonymToAnotherTaxon(synonymRelation
, t2
, moveHomotypicGroup
, heteroTypicSynonymRelationshipType
, reference
, referenceDetail
, keepReference
);
199 } catch (HomotypicalGroupChangeException e
) {
200 Assert
.fail("Method call should not throw exception");
203 Assert
.assertTrue("t1 should have no synonym relationships", t1
.getSynonymRelations().isEmpty());
205 Set
<SynonymRelationship
> synonymRelations
= t2
.getSynonymRelations();
206 Assert
.assertTrue("t2 should have exactly one synonym relationship", synonymRelations
.size() == 1);
208 synonymRelation
= synonymRelations
.iterator().next();
210 Assert
.assertEquals(t2
, synonymRelation
.getAcceptedTaxon());
211 Assert
.assertEquals(heteroTypicSynonymRelationshipType
, synonymRelation
.getType());
212 Assert
.assertEquals(reference
, synonymRelation
.getCitation());
213 Assert
.assertEquals(referenceDetail
, synonymRelation
.getCitationMicroReference());
217 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testMoveSynonymToAnotherTaxon.xml")
218 public final void testMoveSynonymToAnotherTaxon() throws Exception
{
219 final String
[] tableNames
= new String
[]{"SynonymRelationship"};
221 // printDataSet(System.err, new String[]{"AgentBase", "TaxonBase"});
222 // printDataSet(System.err, new String[]{"TaxonNode"});
224 UUID uuidNewTaxon
= UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
225 UUID uuidOldTaxon
= UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
226 UUID uuidSyn1
= UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
227 UUID uuidSyn3
= UUID
.fromString("3fba2b22-22ae-4291-af67-faab748a5232");
228 UUID uuidSyn4
= UUID
.fromString("f9b589c7-50cf-4df2-a52e-1b85eb7e4805");
229 UUID uuidSyn5
= UUID
.fromString("fcc0bcf8-8bac-43bd-9508-1e97821587dd");
230 UUID uuidSyn6
= UUID
.fromString("0ccd4e7c-6fbd-4b7c-bd47-29e45b92f34b");
231 UUID uuidRef1
= UUID
.fromString("336f9b38-698c-45d7-be7b-993ed3355bdc");
232 UUID uuidRef2
= UUID
.fromString("c8f49d1a-69e1-48a3-98bb-45d61f3da3e7");
235 boolean moveHomotypicGroup
= true;
236 SynonymRelationshipType newSynonymRelationshipType
= null;
237 boolean keepReference
= true;
238 Reference
<?
> newReference
= null;
239 String newReferenceDetail
= null;
241 Taxon newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
242 Synonym homotypicSynonym
= (Synonym
)service
.load(uuidSyn1
);
243 Assert
.assertNotNull("Synonym should exist", homotypicSynonym
);
244 Assert
.assertEquals("Synonym should have 1 relation", 1, homotypicSynonym
.getSynonymRelations().size());
245 SynonymRelationship rel
= homotypicSynonym
.getSynonymRelations().iterator().next();
246 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
247 Taxon oldTaxon
= rel
.getAcceptedTaxon();
250 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
251 Assert
.fail("Homotypic synonym move to other taxon should throw an exception");
252 } catch (HomotypicalGroupChangeException e
) {
253 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")){
255 commitAndStartNewTransaction(tableNames
);
257 Assert
.fail("Unexpected exception occurred: " + e
.getMessage());
261 homotypicSynonym
= (Synonym
)service
.load(uuidSyn1
);
262 Assert
.assertNotNull("Synonym should still exist", homotypicSynonym
);
263 Assert
.assertEquals("Synonym should still have 1 relation", 1, homotypicSynonym
.getSynonymRelations().size());
264 rel
= homotypicSynonym
.getSynonymRelations().iterator().next();
265 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", oldTaxon
, rel
.getAcceptedTaxon());
267 //test heterotypic synonym with other synonym in homotypic group
268 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
269 Synonym heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
270 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
271 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
272 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
273 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
274 oldTaxon
= rel
.getAcceptedTaxon();
275 moveHomotypicGroup
= false;
278 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
279 Assert
.fail("Heterotypic synonym move to other taxon should throw an exception");
280 } catch (HomotypicalGroupChangeException e
) {
281 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")){
283 commitAndStartNewTransaction(tableNames
);
285 Assert
.fail("Unexpected exception occurred: " + e
.getMessage());
289 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
290 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
291 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
292 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
293 Assert
.assertEquals("Accepted taxon of single relation should still be the old taxon", oldTaxon
, rel
.getAcceptedTaxon());
296 //test heterotypic synonym with no other synonym in homotypic group
299 // printDataSet(System.err, new String[]{"TaxonBase"});
301 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
302 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn5
);
303 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
304 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
305 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
306 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
307 oldTaxon
= rel
.getAcceptedTaxon();
308 moveHomotypicGroup
= false;
312 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
313 } catch (HomotypicalGroupChangeException e
) {
314 Assert
.fail("Move of single heterotypic synonym should not throw exception: " + e
.getMessage());
317 //FIXME throws exception
318 commitAndStartNewTransaction(tableNames
);
320 // printDataSet(System.err, new String[]{"AgentBase", "TaxonBase"});
322 // printDataSet(System.err, new String[]{"TaxonBase"});
324 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn5
);
326 // printDataSet(System.err, new String[]{"TaxonBase"});
329 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
330 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
331 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
332 Assert
.assertEquals("Accepted taxon of single relation should be new taxon", newTaxon
, rel
.getAcceptedTaxon());
333 Assert
.assertEquals("Old detail should be kept", "rel5", rel
.getCitationMicroReference());
336 //test heterotypic synonym with other synonym in homotypic group and moveHomotypicGroup="true"
338 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
339 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
340 Reference
<?
> ref1
= referenceService
.load(uuidRef1
);
341 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
342 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
343 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
344 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
345 oldTaxon
= rel
.getAcceptedTaxon();
346 Assert
.assertEquals("Detail should be ref1", ref1
, rel
.getCitation());
347 Assert
.assertEquals("Detail should be 'rel3'", "rel3", rel
.getCitationMicroReference());
348 TaxonNameBase
<?
,?
> oldSynName3
= heterotypicSynonym
.getName();
350 Synonym heterotypicSynonym4
= (Synonym
)service
.load(uuidSyn4
);
351 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym4
);
352 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym4
.getSynonymRelations().size());
353 SynonymRelationship rel4
= heterotypicSynonym4
.getSynonymRelations().iterator().next();
354 Assert
.assertEquals("Accepted taxon of other synonym in group should be the old taxon", uuidOldTaxon
, rel4
.getAcceptedTaxon().getUuid());
355 Assert
.assertSame("Homotypic group of both synonyms should be same", oldSynName3
.getHomotypicalGroup() , heterotypicSynonym4
.getName().getHomotypicalGroup() );
357 moveHomotypicGroup
= true;
358 keepReference
= false;
361 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
362 } catch (HomotypicalGroupChangeException e
) {
363 Assert
.fail("Move with 'moveHomotypicGroup = true' should not throw exception: " + e
.getMessage());
366 commitAndStartNewTransaction(tableNames
);
367 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
368 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
369 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
370 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
371 Assert
.assertEquals("Accepted taxon of relation should be new taxon now", newTaxon
, rel
.getAcceptedTaxon());
372 TaxonNameBase
<?
,?
> synName3
= rel
.getSynonym().getName();
374 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn4
);
375 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
376 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
377 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
378 Assert
.assertEquals("Accepted taxon of relation should be new taxon now", newTaxon
, rel
.getAcceptedTaxon());
379 Assert
.assertNull("Old citation should be removed", rel
.getCitation());
380 Assert
.assertNull("Old detail should be removed", rel
.getCitationMicroReference());
381 TaxonNameBase
<?
,?
> synName4
= rel
.getSynonym().getName();
382 Assert
.assertEquals("Homotypic group of both synonyms should be equal", synName3
.getHomotypicalGroup() , synName4
.getHomotypicalGroup() );
383 Assert
.assertSame("Homotypic group of both synonyms should be same", synName3
.getHomotypicalGroup() , synName4
.getHomotypicalGroup() );
384 Assert
.assertEquals("Homotypic group of both synonyms should be equal to old homotypic group", oldSynName3
.getHomotypicalGroup() , synName3
.getHomotypicalGroup() );
387 //test single heterotypic synonym to homotypic synonym of new taxon
389 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
390 Reference
<?
> ref2
= (Reference
<?
>)referenceService
.load(uuidRef2
);
391 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn6
);
392 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
393 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
394 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
395 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
396 oldTaxon
= rel
.getAcceptedTaxon();
397 moveHomotypicGroup
= false;
398 keepReference
= false;
400 newReferenceDetail
= "newRefDetail";
401 newSynonymRelationshipType
= SynonymRelationshipType
.HOMOTYPIC_SYNONYM_OF();
404 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
405 } catch (HomotypicalGroupChangeException e
) {
406 Assert
.fail("Move of single heterotypic synonym should not throw exception: " + e
.getMessage());
409 commitAndStartNewTransaction(tableNames
);
410 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn6
);
411 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
412 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
413 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
414 Assert
.assertEquals("Relationship type should be 'homotypic synonym'", newSynonymRelationshipType
, rel
.getType());
415 Assert
.assertEquals("Accepted taxon of single relation should be new taxon", newTaxon
, rel
.getAcceptedTaxon());
416 Assert
.assertEquals("New citation should be ref2", ref2
,rel
.getCitation());
417 Assert
.assertEquals("New detail should be kept", "newRefDetail", rel
.getCitationMicroReference());
419 Assert
.assertEquals("New taxon and new synonym should have equal homotypical group", rel
.getSynonym().getHomotypicGroup(), rel
.getAcceptedTaxon().getHomotypicGroup());
420 Assert
.assertSame("New taxon and new synonym should have same homotypical group", rel
.getSynonym().getHomotypicGroup(), rel
.getAcceptedTaxon().getHomotypicGroup());
426 public final void testGetHeterotypicSynonymyGroups(){
427 Rank rank
= Rank
.SPECIES();
428 Reference
<?
> ref1
= ReferenceFactory
.newGeneric();
429 //HomotypicalGroup group = HomotypicalGroup.NewInstance();
430 Taxon taxon1
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
431 Synonym synonym0
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
432 Synonym synonym1
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
433 Synonym synonym2
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
434 synonym0
.getName().setHomotypicalGroup(taxon1
.getHomotypicGroup());
435 synonym2
.getName().setHomotypicalGroup(synonym1
.getHomotypicGroup());
436 //tax2.addHeterotypicSynonymName(synonym.getName());
437 taxon1
.addSynonym(synonym1
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
438 taxon1
.addSynonym(synonym2
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
440 service
.save(synonym1
);
441 service
.save(synonym2
);
442 service
.save(taxon1
);
444 List
<List
<Synonym
>> heteroSyns
= service
.getHeterotypicSynonymyGroups(taxon1
, null);
445 Assert
.assertEquals("There should be 1 heterotypic group", 1, heteroSyns
.size());
446 List
<Synonym
> synList
= heteroSyns
.get(0);
447 Assert
.assertEquals("There should be 2 heterotypic syns in group 1", 2, synList
.size());
450 synonym2
.setSec(ref1
);
451 heteroSyns
= service
.getHeterotypicSynonymyGroups(taxon1
, null);
452 Assert
.assertEquals("There should be 1 heterotypic group", 1, heteroSyns
.size());
453 synList
= heteroSyns
.get(0);
454 Assert
.assertEquals("getHeterotypicSynonymyGroups should be independent of sec reference", 2, synList
.size());
460 public final void testGetHomotypicSynonymsByHomotypicGroup(){
461 Rank rank
= Rank
.SPECIES();
462 Reference
<?
> ref1
= ReferenceFactory
.newGeneric();
463 //HomotypicalGroup group = HomotypicalGroup.NewInstance();
464 Taxon taxon1
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
465 Synonym synonym0
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
466 Synonym synonym1
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
467 Synonym synonym2
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
468 synonym0
.getName().setHomotypicalGroup(taxon1
.getHomotypicGroup());
469 synonym2
.getName().setHomotypicalGroup(synonym1
.getHomotypicGroup());
470 //tax2.addHeterotypicSynonymName(synonym.getName());
471 taxon1
.addSynonym(synonym0
, SynonymRelationshipType
.HOMOTYPIC_SYNONYM_OF());
472 taxon1
.addSynonym(synonym1
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
473 taxon1
.addSynonym(synonym2
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
475 service
.save(synonym1
);
476 service
.save(synonym2
);
477 service
.save(taxon1
);
479 List
<Synonym
> homoSyns
= service
.getHomotypicSynonymsByHomotypicGroup(taxon1
, null);
480 Assert
.assertEquals("There should be 1 heterotypic group", 1, homoSyns
.size());
481 Assert
.assertSame("The homotypic synonym should be synonym0", synonym0
, homoSyns
.get(0));
484 synonym0
.setSec(ref1
);
485 homoSyns
= service
.getHomotypicSynonymsByHomotypicGroup(taxon1
, null);
486 Assert
.assertEquals("getHeterotypicSynonymyGroups should be independent of sec reference", 1, homoSyns
.size());
491 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
492 public final void testDeleteSynonymSynonymTaxonBoolean(){
493 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
494 "SynonymRelationship","SynonymRelationship_AUD",
495 "HomotypicalGroup","HomotypicalGroup_AUD"};
496 // BotanicalName taxonName1 = BotanicalName.NewInstance(Rank.SPECIES());
497 // taxonName1.setTitleCache("TaxonName1",true);
498 // BotanicalName taxonName2 = BotanicalName.NewInstance(Rank.SPECIES());
499 // taxonName2.setTitleCache("TaxonName2",true);
500 // BotanicalName synonymName1 = BotanicalName.NewInstance(Rank.SPECIES());
501 // synonymName1.setTitleCache("Synonym1",true);
502 // BotanicalName synonymName2 = BotanicalName.NewInstance(Rank.SPECIES());
503 // synonymName2.setTitleCache("Synonym2",true);
505 // Reference<?> sec = null;
506 // Taxon taxon1 = Taxon.NewInstance(taxonName1, sec);
507 // Taxon taxon2 = Taxon.NewInstance(taxonName2, sec);
508 // Synonym synonym1 = Synonym.NewInstance(synonymName1, sec);
509 // Synonym synonym2 = Synonym.NewInstance(synonymName2, sec);
511 // SynonymRelationship rel1 = taxon1.addSynonym(synonym1, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
512 // SynonymRelationship rel = taxon2.addSynonym(synonym1, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
513 // rel.setProParte(true);
514 // rel1.setProParte(true);
516 // service.save(taxon1);
517 // service.save(synonym2);
519 // this.setComplete();
520 // this.endTransaction();
523 int nSynonyms
= service
.count(Synonym
.class);
524 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
525 int nNames
= nameService
.count(TaxonNameBase
.class);
526 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
528 // UUID uuidTaxon1=UUID.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
529 // UUID uuidTaxon2=UUID.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
530 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
531 // UUID uuidSynonym2=UUID.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
533 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
534 service
.deleteSynonym(synonym1
, null, true, true);
536 this.commitAndStartNewTransaction(tableNames
);
538 nSynonyms
= service
.count(Synonym
.class);
539 Assert
.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms
);
540 nNames
= nameService
.count(TaxonNameBase
.class);
541 Assert
.assertEquals("There should be 3 names left in the database", 3, nNames
);
542 int nRelations
= service
.countAllRelationships();
543 Assert
.assertEquals("There should be no relationship left in the database", 0, nRelations
);
547 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
548 public final void testDeleteSynonymSynonymTaxonBooleanRelToOneTaxon(){
549 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
550 "SynonymRelationship","SynonymRelationship_AUD",
551 "HomotypicalGroup","HomotypicalGroup_AUD"};
553 int nSynonyms
= service
.count(Synonym
.class);
554 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
555 int nNames
= nameService
.count(TaxonNameBase
.class);
556 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
558 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
559 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
560 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
561 // UUID uuidSynonym2=UUID.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
563 Taxon taxon2
= (Taxon
)service
.load(uuidTaxon2
);
566 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
568 taxon2
.removeSynonym(synonym1
, false);
569 service
.saveOrUpdate(taxon2
);
571 commitAndStartNewTransaction(null);
573 nSynonyms
= service
.count(Synonym
.class);
574 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
575 nNames
= nameService
.count(TaxonNameBase
.class);
576 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
577 int nRelations
= service
.countAllRelationships();
578 Assert
.assertEquals("There should be 1 relationship left in the database", 1, nRelations
);
580 taxon2
= (Taxon
)service
.load(uuidTaxon2
);
581 synonym1
= (Synonym
)service
.load(uuidSynonym1
);
583 service
.deleteSynonym(synonym1
, null, true, true);
585 commitAndStartNewTransaction(tableNames
);
587 nSynonyms
= service
.count(Synonym
.class);
588 Assert
.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms
);
589 nNames
= nameService
.count(TaxonNameBase
.class);
590 Assert
.assertEquals("There should be 3 names left in the database", 3, nNames
);
591 nRelations
= service
.countAllRelationships();
592 Assert
.assertEquals("There should be no relationship left in the database", 0, nRelations
);
597 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
598 public final void testDeleteSynonymSynonymTaxonBooleanDeleteOneTaxon(){
599 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
600 "SynonymRelationship","SynonymRelationship_AUD",
601 "HomotypicalGroup","HomotypicalGroup_AUD"};
603 // printDataSet(System.err, new String[]{"TaxonNode"});
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
);
611 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
612 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
613 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
614 UUID uuidSynonym2
=UUID
.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
616 Taxon taxon1
= (Taxon
)service
.load(uuidTaxon1
);
617 Taxon taxon2
= (Taxon
)service
.load(uuidTaxon2
);
618 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
620 service
.deleteSynonym(synonym1
, taxon1
, true, true);
622 this.commitAndStartNewTransaction(tableNames
);
624 nSynonyms
= service
.count(Synonym
.class);
625 Assert
.assertEquals("There should still be 2 synonyms left in the database (synonym is related to taxon2)", 2, nSynonyms
);
626 nNames
= nameService
.count(TaxonNameBase
.class);
627 Assert
.assertEquals("There should be 4 names left in the database (name not deleted as synonym was not deleted)", 4, nNames
);
628 int nRelations
= service
.countAllRelationships();
629 Assert
.assertEquals("There should be 1 relationship left in the database", 1, nRelations
);
634 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
635 public final void testDeleteSynonymSynonymTaxonBooleanWithRelatedName(){
636 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
637 "SynonymRelationship","SynonymRelationship_AUD",
638 "HomotypicalGroup","HomotypicalGroup_AUD"};
640 int nSynonyms
= service
.count(Synonym
.class);
641 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
642 int nNames
= nameService
.count(TaxonNameBase
.class);
643 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
645 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
646 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
647 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
648 UUID uuidSynonym2
=UUID
.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
649 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
651 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
652 TaxonNameBase name2
= (TaxonNameBase
)nameService
.load(uuidSynonymName2
);
653 synonym1
.getName().addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null);
655 service
.deleteSynonym(synonym1
, null, true, true);
657 this.commitAndStartNewTransaction(tableNames
);
659 nSynonyms
= service
.count(Synonym
.class);
660 Assert
.assertEquals("There should still be 1 synonyms left in the database", 1, nSynonyms
);
661 nNames
= nameService
.count(TaxonNameBase
.class);
662 Assert
.assertEquals("There should be 4 names left in the database (name is related to synonymName2)", 4, nNames
);
663 int nRelations
= service
.countAllRelationships();
664 //may change with better implementation of countAllRelationships (see #2653)
665 Assert
.assertEquals("There should be 0 taxon relationships left in the database", 0, nRelations
);
666 nRelations
= nameService
.getAllRelationships(1000, 0).size();
667 Assert
.assertEquals("There should be 1 name relationship left in the database", 1, nRelations
);
671 name2
= (TaxonNameBase
)nameService
.load(uuidSynonymName2
);
672 NameRelationship rel
= CdmBase
.deproxy(name2
.getNameRelations().iterator().next(), NameRelationship
.class);
673 name2
.removeNameRelationship(rel
);
674 nameService
.save(name2
);
676 this.endTransaction();
681 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
682 public final void testDeleteSynonymSynonymTaxonBooleanWithRollback(){
683 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
684 "SynonymRelationship","SynonymRelationship_AUD",
685 "HomotypicalGroup","HomotypicalGroup_AUD"};
687 int nSynonyms
= service
.count(Synonym
.class);
688 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
689 int nNames
= nameService
.count(TaxonNameBase
.class);
690 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
691 int nRelations
= service
.countAllRelationships();
692 //may change with better implementation of countAllRelationships (see #2653)
693 Assert
.assertEquals("There should be 2 relationship in the database (the 2 synonym relationship) but no name relationship", 2, nRelations
);
695 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
696 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
698 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
699 TaxonNameBase name2
= (TaxonNameBase
)nameService
.load(uuidSynonymName2
);
700 synonym1
.getName().addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null);
702 service
.deleteSynonym(synonym1
, null, true, true);
705 // printDataSet(System.out, tableNames);
706 this.startNewTransaction();
708 nSynonyms
= service
.count(Synonym
.class);
709 Assert
.assertEquals("There should still be 2 synonyms left in the database", 2, nSynonyms
);
710 nNames
= nameService
.count(TaxonNameBase
.class);
711 Assert
.assertEquals("There should be 4 names left in the database", 4, nNames
);
712 nRelations
= service
.countAllRelationships();
713 //may change with better implementation of countAllRelationships (see #2653)
714 Assert
.assertEquals("There should be 2 relationship in the database (the 2 synonym relationship) but no name relationship", 2, nRelations
);
719 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
720 public final void testDeleteSynonymSynonymTaxonBooleanWithoutTransaction(){
721 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
722 "SynonymRelationship","SynonymRelationship_AUD",
723 "HomotypicalGroup","HomotypicalGroup_AUD"};
725 int nSynonyms
= service
.count(Synonym
.class);
726 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
727 int nNames
= nameService
.count(TaxonNameBase
.class);
728 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
729 int nRelations
= service
.countAllRelationships();
730 //may change with better implementation of countAllRelationships (see #2653)
731 Assert
.assertEquals("There should be 2 relationship in the database (the 2 synonym relationship) but no name relationship", 2, nRelations
);
733 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
734 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
736 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
737 TaxonNameBase name2
= (TaxonNameBase
)nameService
.load(uuidSynonymName2
);
738 synonym1
.getName().addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null);
740 service
.saveOrUpdate(synonym1
);
743 this.endTransaction();
745 // printDataSet(System.out, tableNames);
747 //out of wrapping transaction
748 service
.deleteSynonym(synonym1
, null, true, true);
750 this.startNewTransaction();
752 nSynonyms
= service
.count(Synonym
.class);
753 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
);
754 nNames
= nameService
.count(TaxonNameBase
.class);
755 Assert
.assertEquals("There should be 4 names left in the database", 4, nNames
);
756 nRelations
= service
.countAllRelationships();
757 Assert
.assertEquals("There should be no taxon or synonym relationship in the database", 0, nRelations
);
758 nRelations
= nameService
.getAllRelationships(1000,0).size();
759 Assert
.assertEquals("There should be 1 name relationship in the database", 1, nRelations
);
764 @DataSet("TaxonServiceImplTest.testInferredSynonyms.xml")
765 public void testCreateInferredSynonymy(){
767 UUID classificationUuid
= UUID
.fromString("aeee7448-5298-4991-b724-8d5b75a0a7a9");
768 Classification tree
= classificationService
.find(classificationUuid
);
769 UUID taxonUuid
= UUID
.fromString("bc09aca6-06fd-4905-b1e7-cbf7cc65d783");
770 TaxonBase
<?
> taxonBase
= service
.find(taxonUuid
);
771 List
<TaxonBase
> synonyms
= service
.list(Synonym
.class, null, null, null, null);
772 assertEquals("Number of synonyms should be 2",2,synonyms
.size());
773 Taxon taxon
= (Taxon
)taxonBase
;
775 //synonyms = taxonDao.getAllSynonyms(null, null);
776 //assertEquals("Number of synonyms should be 2",2,synonyms.size());
777 List
<Synonym
> inferredSynonyms
= service
.createInferredSynonyms(taxon
, tree
, SynonymRelationshipType
.INFERRED_EPITHET_OF(), true);
778 assertNotNull("there should be a new synonym ", inferredSynonyms
);
779 assertEquals ("the name of inferred epithet should be SynGenus lachesis", "SynGenus lachesis sec. Sp. Pl.", inferredSynonyms
.get(0).getTitleCache());
781 inferredSynonyms
= service
.createInferredSynonyms(taxon
, tree
, SynonymRelationshipType
.INFERRED_GENUS_OF(), true);
782 assertNotNull("there should be a new synonym ", inferredSynonyms
);
783 assertEquals ("the name of inferred epithet should be SynGenus lachesis", "Acherontia ciprosus sec. Sp. Pl.", inferredSynonyms
.get(0).getTitleCache());
785 inferredSynonyms
= service
.createInferredSynonyms(taxon
, tree
, SynonymRelationshipType
.POTENTIAL_COMBINATION_OF(), true);
786 assertNotNull("there should be a new synonym ", inferredSynonyms
);
787 assertEquals ("the name of inferred epithet should be SynGenus lachesis", "SynGenus ciprosus sec. Sp. Pl.", inferredSynonyms
.get(0).getTitleCache());
788 //assertTrue("set of synonyms should contain an inferred Synonym ", synonyms.contains(arg0))
792 @DataSet("TaxonServiceImplTest.testDeleteTaxonConfig.xml")
793 @Ignore //not fully working yet
794 public final void testDeleteTaxonConfig(){
795 final String
[]tableNames
= {
796 "Classification", "Classification_AUD",
797 "TaxonBase","TaxonBase_AUD",
798 "TaxonNode","TaxonNode_AUD",
799 "TaxonNameBase","TaxonNameBase_AUD",
800 "SynonymRelationship","SynonymRelationship_AUD",
801 "TaxonRelationship", "TaxonRelationship_AUD",
802 "TaxonDescription", "TaxonDescription_AUD",
803 "HomotypicalGroup","HomotypicalGroup_AUD",
804 "PolytomousKey","PolytomousKey_AUD",
805 "PolytomousKeyNode","PolytomousKeyNode_AUD",
807 "WorkingSet","WorkingSet_AUD",
808 "DescriptionElementBase","DescriptionElementBase_AUD"};
810 UUID uuidParent
=UUID
.fromString("b5271d4f-e203-4577-941f-00d76fa9f4ca");
811 UUID uuidChild1
=UUID
.fromString("326167f9-0b97-4e7d-b1bf-4ca47b82e21e");
812 UUID uuidSameAs
=UUID
.fromString("c2bb0f01-f2dd-43fb-ba12-2a85727ccb8d");
814 int nTaxa
= service
.count(Taxon
.class);
815 Assert
.assertEquals("There should be 3 taxa in the database", 3, nTaxa
);
816 Taxon parent
= (Taxon
)service
.find(uuidParent
);
817 Assert
.assertNotNull("Parent taxon should exist", parent
);
818 Taxon child1
= (Taxon
)service
.find(uuidChild1
);
819 Assert
.assertNotNull("Child taxon should exist", child1
);
823 // commitAndStartNewTransaction(tableNames);
824 service
.deleteTaxon(child1
, new TaxonDeletionConfigurator());
825 Assert
.fail("Delete should throw an error as long as name is used in classification.");
826 } catch (ReferencedObjectUndeletableException e
) {
827 if (e
.getMessage().contains("Taxon can't be deleted as it is used in a classification node")){
829 commitAndStartNewTransaction(tableNames
);
831 Assert
.fail("Unexpected error occurred when trying to delete taxon: " + e
.getMessage());
835 nTaxa
= service
.count(Taxon
.class);
836 Assert
.assertEquals("There should be 3 taxa in the database", 3, nTaxa
);
837 child1
= (Taxon
)service
.find(uuidChild1
);
838 Assert
.assertNotNull("Child taxon should exist", child1
);
839 Assert
.assertEquals("Child should belong to 1 node", 1, child1
.getTaxonNodes().size());
841 TaxonNode node
= child1
.getTaxonNodes().iterator().next();
842 node
.getParent().deleteChildNode(node
);
843 service
.save(node
.getTaxon());
844 commitAndStartNewTransaction(tableNames
);
846 child1
= (Taxon
)service
.find(uuidChild1
);
848 service
.deleteTaxon(child1
, new TaxonDeletionConfigurator());
849 } catch (ReferencedObjectUndeletableException e
) {
850 Assert
.fail("Delete should not throw an exception anymore");
854 // nNames = nameService.count(TaxonNameBase.class);
855 // Assert.assertEquals("There should be 3 names left in the database", 3, nNames);
856 // int nRelations = service.countAllRelationships();
857 // Assert.assertEquals("There should be no relationship left in the database", 0, nRelations);
862 // public final void testDeleteTaxonCreateData(){
863 // final String[]tableNames = {"TaxonBase","TaxonBase_AUD",
864 // "TaxonNode","TaxonNode_AUD",
865 // "TaxonNameBase","TaxonNameBase_AUD",
866 // "SynonymRelationship","SynonymRelationship_AUD",
867 // "TaxonRelationship", "TaxonRelationship_AUD",
868 // "TaxonDescription", "TaxonDescription_AUD",
869 // "HomotypicalGroup","HomotypicalGroup_AUD",
870 // "PolytomousKey","PolytomousKey_AUD",
871 // "PolytomousKeyNode","PolytomousKeyNode_AUD",
872 // "Media","Media_AUD",
873 // "WorkingSet","WorkingSet_AUD",
874 // "DescriptionElementBase","DescriptionElementBase_AUD",
875 // "Classification","Classification_AUD"};
878 // BotanicalName taxonName1 = BotanicalName.NewInstance(Rank.GENUS());
879 // taxonName1.setTitleCache("parent",true);
880 // BotanicalName taxonName2 = BotanicalName.NewInstance(Rank.SPECIES());
881 // taxonName2.setTitleCache("child1",true);
882 // BotanicalName synonymName1 = BotanicalName.NewInstance(Rank.SPECIES());
883 // synonymName1.setTitleCache("Synonym1",true);
884 // BotanicalName sameAsName = BotanicalName.NewInstance(Rank.SPECIES());
885 // sameAsName.setTitleCache("sameAs",true);
887 // Reference<?> sec = null;
888 // Taxon parent = Taxon.NewInstance(taxonName1, sec);
889 // Taxon child1 = Taxon.NewInstance(taxonName2, sec);
890 // Synonym synonym1 = Synonym.NewInstance(synonymName1, sec);
891 // Taxon sameAs = Taxon.NewInstance(sameAsName, sec);
893 // child1.addSynonym(synonym1, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
894 // Classification classification1 = Classification.NewInstance("classification1");
895 // classification1.addParentChild(parent, child1, null, null);
898 // child1.addTaxonRelation(sameAs, TaxonRelationshipType.CONGRUENT_TO(), null, null);
900 // service.save(child1);
902 // this.commitAndStartNewTransaction(tableNames);