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
;
56 public class TaxonServiceImplTest
extends CdmTransactionalIntegrationTest
{
57 @SuppressWarnings("unused")
58 private static final Logger logger
= Logger
.getLogger(TaxonServiceImplTest
.class);
61 private ITaxonService service
;
64 private INameService nameService
;
67 private IReferenceService referenceService
;
70 private IClassificationService classificationService
;
73 /****************** TESTS *****************************/
77 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#getTaxonByUuid(java.util.UUID)}.
80 public final void testGetTaxonByUuid() {
81 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
82 UUID uuid
= service
.save(expectedTaxon
);
83 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
84 assertEquals(expectedTaxon
, actualTaxon
);
88 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#saveTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)}.
91 public final void testSaveTaxon() {
92 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
93 UUID uuid
= service
.save(expectedTaxon
);
94 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
95 assertEquals(expectedTaxon
, actualTaxon
);
99 public final void testSaveOrUpdateTaxon() {
100 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
101 UUID uuid
= service
.save(expectedTaxon
);
102 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
103 assertEquals(expectedTaxon
, actualTaxon
);
105 actualTaxon
.setName(BotanicalName
.NewInstance(Rank
.SPECIES()));
107 service
.saveOrUpdate(actualTaxon
);
113 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#removeTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)}.
116 public final void testRemoveTaxon() {
117 Taxon taxon
= Taxon
.NewInstance(BotanicalName
.NewInstance(Rank
.UNKNOWN_RANK()), null);
118 UUID uuid
= service
.save(taxon
);
119 service
.delete(taxon
);
120 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
121 assertNull(actualTaxon
);
126 public final void testMakeTaxonSynonym() {
127 Rank rank
= Rank
.SPECIES();
128 Taxon tax1
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test1", null, null, null, null, null, null, null), null);
129 Synonym synonym
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
130 tax1
.addHomotypicSynonym(synonym
, null, null);
131 UUID uuidTaxon
= service
.save(tax1
);
132 UUID uuidSyn
= service
.save(synonym
);
134 service
.swapSynonymAndAcceptedTaxon(synonym
, tax1
);
137 TaxonBase
<?
> tax
= service
.find(uuidTaxon
);
138 TaxonBase
<?
> syn
= service
.find(uuidSyn
);
139 HomotypicalGroup groupTest
= tax
.getHomotypicGroup();
140 HomotypicalGroup groupTest2
= syn
.getHomotypicGroup();
141 assertEquals(groupTest
, groupTest2
);
146 public final void testChangeSynonymToAcceptedTaxon(){
147 Rank rank
= Rank
.SPECIES();
148 //HomotypicalGroup group = HomotypicalGroup.NewInstance();
149 Taxon taxWithoutSyn
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test1", null, null, null, null, null, null, null), null);
150 Taxon taxWithSyn
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
151 Synonym synonym
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
152 Synonym synonym2
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
153 synonym2
.getName().setHomotypicalGroup(synonym
.getHomotypicGroup());
154 //tax2.addHeterotypicSynonymName(synonym.getName());
155 taxWithSyn
.addSynonym(synonym
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
156 taxWithSyn
.addSynonym(synonym2
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
158 service
.save(taxWithoutSyn
);
159 UUID uuidSyn
= service
.save(synonym
);
160 service
.save(synonym2
);
161 service
.save(taxWithSyn
);
165 taxon
= service
.changeSynonymToAcceptedTaxon(synonym
, taxWithSyn
, true, true, null, null);
166 } catch (HomotypicalGroupChangeException e
) {
167 Assert
.fail("Invocation of change method should not throw an exception");
169 //test flush (resave deleted object)
170 TaxonBase
<?
> syn
= service
.find(uuidSyn
);
172 Assert
.assertEquals("New taxon should have 1 synonym relationship (the old homotypic synonym)", 1, taxon
.getSynonymRelations().size());
177 * Old implementation taken from {@link TaxonServiceImplBusinessTest} for old version of method.
178 * 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)}.
181 public final void testMoveSynonymToAnotherTaxon_OLD() {
182 SynonymRelationshipType heteroTypicSynonymRelationshipType
= SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF();
183 Reference
<?
> reference
= ReferenceFactory
.newGeneric();
184 String referenceDetail
= "test";
186 NonViralName
<?
> t1n
= NonViralName
.NewInstance(null);
187 Taxon t1
= Taxon
.NewInstance(t1n
, reference
);
188 NonViralName
<?
> t2n
= NonViralName
.NewInstance(null);
189 Taxon t2
= Taxon
.NewInstance(t2n
, reference
);
190 NonViralName
<?
> s1n
= NonViralName
.NewInstance(null);
191 Synonym s1
= Synonym
.NewInstance(s1n
, reference
);
192 t1
.addSynonym(s1
, heteroTypicSynonymRelationshipType
);
194 SynonymRelationship synonymRelation
= t1
.getSynonymRelations().iterator().next();
196 boolean keepReference
= false;
197 boolean moveHomotypicGroup
= false;
199 service
.moveSynonymToAnotherTaxon(synonymRelation
, t2
, moveHomotypicGroup
, heteroTypicSynonymRelationshipType
, reference
, referenceDetail
, keepReference
);
200 } catch (HomotypicalGroupChangeException e
) {
201 Assert
.fail("Method call should not throw exception");
204 Assert
.assertTrue("t1 should have no synonym relationships", t1
.getSynonymRelations().isEmpty());
206 Set
<SynonymRelationship
> synonymRelations
= t2
.getSynonymRelations();
207 Assert
.assertTrue("t2 should have exactly one synonym relationship", synonymRelations
.size() == 1);
209 synonymRelation
= synonymRelations
.iterator().next();
211 Assert
.assertEquals(t2
, synonymRelation
.getAcceptedTaxon());
212 Assert
.assertEquals(heteroTypicSynonymRelationshipType
, synonymRelation
.getType());
213 Assert
.assertEquals(reference
, synonymRelation
.getCitation());
214 Assert
.assertEquals(referenceDetail
, synonymRelation
.getCitationMicroReference());
218 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testMoveSynonymToAnotherTaxon.xml")
219 public final void testMoveSynonymToAnotherTaxon() throws Exception
{
220 final String
[] tableNames
= new String
[]{"SynonymRelationship"};
222 // printDataSet(System.err, new String[]{"AgentBase", "TaxonBase"});
223 // printDataSet(System.err, new String[]{"TaxonNode"});
225 UUID uuidNewTaxon
= UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
226 UUID uuidOldTaxon
= UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
227 UUID uuidSyn1
= UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
228 UUID uuidSyn3
= UUID
.fromString("3fba2b22-22ae-4291-af67-faab748a5232");
229 UUID uuidSyn4
= UUID
.fromString("f9b589c7-50cf-4df2-a52e-1b85eb7e4805");
230 UUID uuidSyn5
= UUID
.fromString("fcc0bcf8-8bac-43bd-9508-1e97821587dd");
231 UUID uuidSyn6
= UUID
.fromString("0ccd4e7c-6fbd-4b7c-bd47-29e45b92f34b");
232 UUID uuidRef1
= UUID
.fromString("336f9b38-698c-45d7-be7b-993ed3355bdc");
233 UUID uuidRef2
= UUID
.fromString("c8f49d1a-69e1-48a3-98bb-45d61f3da3e7");
236 boolean moveHomotypicGroup
= true;
237 SynonymRelationshipType newSynonymRelationshipType
= null;
238 boolean keepReference
= true;
239 Reference
<?
> newReference
= null;
240 String newReferenceDetail
= null;
242 Taxon newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
243 Synonym homotypicSynonym
= (Synonym
)service
.load(uuidSyn1
);
244 Assert
.assertNotNull("Synonym should exist", homotypicSynonym
);
245 Assert
.assertEquals("Synonym should have 1 relation", 1, homotypicSynonym
.getSynonymRelations().size());
246 SynonymRelationship rel
= homotypicSynonym
.getSynonymRelations().iterator().next();
247 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
248 Taxon oldTaxon
= rel
.getAcceptedTaxon();
251 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
252 Assert
.fail("Homotypic synonym move to other taxon should throw an exception");
253 } catch (HomotypicalGroupChangeException e
) {
254 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")){
256 commitAndStartNewTransaction(tableNames
);
258 Assert
.fail("Unexpected exception occurred: " + e
.getMessage());
262 homotypicSynonym
= (Synonym
)service
.load(uuidSyn1
);
263 Assert
.assertNotNull("Synonym should still exist", homotypicSynonym
);
264 Assert
.assertEquals("Synonym should still have 1 relation", 1, homotypicSynonym
.getSynonymRelations().size());
265 rel
= homotypicSynonym
.getSynonymRelations().iterator().next();
266 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", oldTaxon
, rel
.getAcceptedTaxon());
268 //test heterotypic synonym with other synonym in homotypic group
269 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
270 Synonym heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
271 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
272 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
273 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
274 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
275 oldTaxon
= rel
.getAcceptedTaxon();
276 moveHomotypicGroup
= false;
279 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
280 Assert
.fail("Heterotypic synonym move to other taxon should throw an exception");
281 } catch (HomotypicalGroupChangeException e
) {
282 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")){
284 commitAndStartNewTransaction(tableNames
);
286 Assert
.fail("Unexpected exception occurred: " + e
.getMessage());
290 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
291 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
292 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
293 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
294 Assert
.assertEquals("Accepted taxon of single relation should still be the old taxon", oldTaxon
, rel
.getAcceptedTaxon());
297 //test heterotypic synonym with no other synonym in homotypic group
300 // printDataSet(System.err, new String[]{"TaxonBase"});
302 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
303 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn5
);
304 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
305 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
306 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
307 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
308 oldTaxon
= rel
.getAcceptedTaxon();
309 moveHomotypicGroup
= false;
313 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
314 } catch (HomotypicalGroupChangeException e
) {
315 Assert
.fail("Move of single heterotypic synonym should not throw exception: " + e
.getMessage());
318 //FIXME throws exception
319 commitAndStartNewTransaction(tableNames
);
321 // printDataSet(System.err, new String[]{"AgentBase", "TaxonBase"});
323 // printDataSet(System.err, new String[]{"TaxonBase"});
325 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn5
);
327 // printDataSet(System.err, new String[]{"TaxonBase"});
330 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
331 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
332 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
333 Assert
.assertEquals("Accepted taxon of single relation should be new taxon", newTaxon
, rel
.getAcceptedTaxon());
334 Assert
.assertEquals("Old detail should be kept", "rel5", rel
.getCitationMicroReference());
337 //test heterotypic synonym with other synonym in homotypic group and moveHomotypicGroup="true"
339 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
340 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
341 Reference
<?
> ref1
= referenceService
.load(uuidRef1
);
342 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
343 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
344 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
345 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
346 oldTaxon
= rel
.getAcceptedTaxon();
347 Assert
.assertEquals("Detail should be ref1", ref1
, rel
.getCitation());
348 Assert
.assertEquals("Detail should be 'rel3'", "rel3", rel
.getCitationMicroReference());
349 TaxonNameBase
<?
,?
> oldSynName3
= heterotypicSynonym
.getName();
351 Synonym heterotypicSynonym4
= (Synonym
)service
.load(uuidSyn4
);
352 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym4
);
353 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym4
.getSynonymRelations().size());
354 SynonymRelationship rel4
= heterotypicSynonym4
.getSynonymRelations().iterator().next();
355 Assert
.assertEquals("Accepted taxon of other synonym in group should be the old taxon", uuidOldTaxon
, rel4
.getAcceptedTaxon().getUuid());
356 Assert
.assertSame("Homotypic group of both synonyms should be same", oldSynName3
.getHomotypicalGroup() , heterotypicSynonym4
.getName().getHomotypicalGroup() );
358 moveHomotypicGroup
= true;
359 keepReference
= false;
362 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
363 } catch (HomotypicalGroupChangeException e
) {
364 Assert
.fail("Move with 'moveHomotypicGroup = true' should not throw exception: " + e
.getMessage());
367 commitAndStartNewTransaction(tableNames
);
368 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
369 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
370 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
371 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
372 Assert
.assertEquals("Accepted taxon of relation should be new taxon now", newTaxon
, rel
.getAcceptedTaxon());
373 TaxonNameBase
<?
,?
> synName3
= rel
.getSynonym().getName();
375 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn4
);
376 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
377 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
378 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
379 Assert
.assertEquals("Accepted taxon of relation should be new taxon now", newTaxon
, rel
.getAcceptedTaxon());
380 Assert
.assertNull("Old citation should be removed", rel
.getCitation());
381 Assert
.assertNull("Old detail should be removed", rel
.getCitationMicroReference());
382 TaxonNameBase
<?
,?
> synName4
= rel
.getSynonym().getName();
383 Assert
.assertEquals("Homotypic group of both synonyms should be equal", synName3
.getHomotypicalGroup() , synName4
.getHomotypicalGroup() );
384 Assert
.assertSame("Homotypic group of both synonyms should be same", synName3
.getHomotypicalGroup() , synName4
.getHomotypicalGroup() );
385 Assert
.assertEquals("Homotypic group of both synonyms should be equal to old homotypic group", oldSynName3
.getHomotypicalGroup() , synName3
.getHomotypicalGroup() );
388 //test single heterotypic synonym to homotypic synonym of new taxon
390 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
391 Reference
<?
> ref2
= (Reference
<?
>)referenceService
.load(uuidRef2
);
392 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn6
);
393 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
394 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
395 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
396 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
397 oldTaxon
= rel
.getAcceptedTaxon();
398 moveHomotypicGroup
= false;
399 keepReference
= false;
401 newReferenceDetail
= "newRefDetail";
402 newSynonymRelationshipType
= SynonymRelationshipType
.HOMOTYPIC_SYNONYM_OF();
405 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
406 } catch (HomotypicalGroupChangeException e
) {
407 Assert
.fail("Move of single heterotypic synonym should not throw exception: " + e
.getMessage());
410 commitAndStartNewTransaction(tableNames
);
411 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn6
);
412 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
413 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
414 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
415 Assert
.assertEquals("Relationship type should be 'homotypic synonym'", newSynonymRelationshipType
, rel
.getType());
416 Assert
.assertEquals("Accepted taxon of single relation should be new taxon", newTaxon
, rel
.getAcceptedTaxon());
417 Assert
.assertEquals("New citation should be ref2", ref2
,rel
.getCitation());
418 Assert
.assertEquals("New detail should be kept", "newRefDetail", rel
.getCitationMicroReference());
420 Assert
.assertEquals("New taxon and new synonym should have equal homotypical group", rel
.getSynonym().getHomotypicGroup(), rel
.getAcceptedTaxon().getHomotypicGroup());
421 Assert
.assertSame("New taxon and new synonym should have same homotypical group", rel
.getSynonym().getHomotypicGroup(), rel
.getAcceptedTaxon().getHomotypicGroup());
427 public final void testGetHeterotypicSynonymyGroups(){
428 Rank rank
= Rank
.SPECIES();
429 Reference
<?
> ref1
= ReferenceFactory
.newGeneric();
430 //HomotypicalGroup group = HomotypicalGroup.NewInstance();
431 Taxon taxon1
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
432 Synonym synonym0
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
433 Synonym synonym1
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
434 Synonym synonym2
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
435 synonym0
.getName().setHomotypicalGroup(taxon1
.getHomotypicGroup());
436 synonym2
.getName().setHomotypicalGroup(synonym1
.getHomotypicGroup());
437 //tax2.addHeterotypicSynonymName(synonym.getName());
438 taxon1
.addSynonym(synonym1
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
439 taxon1
.addSynonym(synonym2
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
441 service
.save(synonym1
);
442 service
.save(synonym2
);
443 service
.save(taxon1
);
445 List
<List
<Synonym
>> heteroSyns
= service
.getHeterotypicSynonymyGroups(taxon1
, null);
446 Assert
.assertEquals("There should be 1 heterotypic group", 1, heteroSyns
.size());
447 List
<Synonym
> synList
= heteroSyns
.get(0);
448 Assert
.assertEquals("There should be 2 heterotypic syns in group 1", 2, synList
.size());
451 synonym2
.setSec(ref1
);
452 heteroSyns
= service
.getHeterotypicSynonymyGroups(taxon1
, null);
453 Assert
.assertEquals("There should be 1 heterotypic group", 1, heteroSyns
.size());
454 synList
= heteroSyns
.get(0);
455 Assert
.assertEquals("getHeterotypicSynonymyGroups should be independent of sec reference", 2, synList
.size());
461 public final void testGetHomotypicSynonymsByHomotypicGroup(){
462 Rank rank
= Rank
.SPECIES();
463 Reference
<?
> ref1
= ReferenceFactory
.newGeneric();
464 //HomotypicalGroup group = HomotypicalGroup.NewInstance();
465 Taxon taxon1
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
466 Synonym synonym0
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
467 Synonym synonym1
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
468 Synonym synonym2
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
469 synonym0
.getName().setHomotypicalGroup(taxon1
.getHomotypicGroup());
470 synonym2
.getName().setHomotypicalGroup(synonym1
.getHomotypicGroup());
471 //tax2.addHeterotypicSynonymName(synonym.getName());
472 taxon1
.addSynonym(synonym0
, SynonymRelationshipType
.HOMOTYPIC_SYNONYM_OF());
473 taxon1
.addSynonym(synonym1
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
474 taxon1
.addSynonym(synonym2
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
476 service
.save(synonym1
);
477 service
.save(synonym2
);
478 service
.save(taxon1
);
480 List
<Synonym
> homoSyns
= service
.getHomotypicSynonymsByHomotypicGroup(taxon1
, null);
481 Assert
.assertEquals("There should be 1 heterotypic group", 1, homoSyns
.size());
482 Assert
.assertSame("The homotypic synonym should be synonym0", synonym0
, homoSyns
.get(0));
485 synonym0
.setSec(ref1
);
486 homoSyns
= service
.getHomotypicSynonymsByHomotypicGroup(taxon1
, null);
487 Assert
.assertEquals("getHeterotypicSynonymyGroups should be independent of sec reference", 1, homoSyns
.size());
492 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
493 public final void testDeleteSynonymSynonymTaxonBoolean(){
494 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
495 "SynonymRelationship","SynonymRelationship_AUD",
496 "HomotypicalGroup","HomotypicalGroup_AUD"};
497 // BotanicalName taxonName1 = BotanicalName.NewInstance(Rank.SPECIES());
498 // taxonName1.setTitleCache("TaxonName1",true);
499 // BotanicalName taxonName2 = BotanicalName.NewInstance(Rank.SPECIES());
500 // taxonName2.setTitleCache("TaxonName2",true);
501 // BotanicalName synonymName1 = BotanicalName.NewInstance(Rank.SPECIES());
502 // synonymName1.setTitleCache("Synonym1",true);
503 // BotanicalName synonymName2 = BotanicalName.NewInstance(Rank.SPECIES());
504 // synonymName2.setTitleCache("Synonym2",true);
506 // Reference<?> sec = null;
507 // Taxon taxon1 = Taxon.NewInstance(taxonName1, sec);
508 // Taxon taxon2 = Taxon.NewInstance(taxonName2, sec);
509 // Synonym synonym1 = Synonym.NewInstance(synonymName1, sec);
510 // Synonym synonym2 = Synonym.NewInstance(synonymName2, sec);
512 // SynonymRelationship rel1 = taxon1.addSynonym(synonym1, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
513 // SynonymRelationship rel = taxon2.addSynonym(synonym1, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
514 // rel.setProParte(true);
515 // rel1.setProParte(true);
517 // service.save(taxon1);
518 // service.save(synonym2);
520 // this.setComplete();
521 // this.endTransaction();
524 int nSynonyms
= service
.count(Synonym
.class);
525 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
526 int nNames
= nameService
.count(TaxonNameBase
.class);
527 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
529 // UUID uuidTaxon1=UUID.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
530 // UUID uuidTaxon2=UUID.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
531 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
532 // UUID uuidSynonym2=UUID.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
534 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
535 service
.deleteSynonym(synonym1
, null, true, true);
537 this.commitAndStartNewTransaction(tableNames
);
539 nSynonyms
= service
.count(Synonym
.class);
540 Assert
.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms
);
541 nNames
= nameService
.count(TaxonNameBase
.class);
542 Assert
.assertEquals("There should be 3 names left in the database", 3, nNames
);
543 int nRelations
= service
.countAllRelationships();
544 Assert
.assertEquals("There should be no relationship left in the database", 0, nRelations
);
548 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
549 public final void testDeleteSynonymSynonymTaxonBooleanRelToOneTaxon(){
550 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
551 "SynonymRelationship","SynonymRelationship_AUD",
552 "HomotypicalGroup","HomotypicalGroup_AUD"};
554 int nSynonyms
= service
.count(Synonym
.class);
555 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
556 int nNames
= nameService
.count(TaxonNameBase
.class);
557 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
559 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
560 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
561 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
562 // UUID uuidSynonym2=UUID.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
564 Taxon taxon2
= (Taxon
)service
.load(uuidTaxon2
);
567 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
569 taxon2
.removeSynonym(synonym1
, false);
570 service
.saveOrUpdate(taxon2
);
572 commitAndStartNewTransaction(null);
574 nSynonyms
= service
.count(Synonym
.class);
575 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
576 nNames
= nameService
.count(TaxonNameBase
.class);
577 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
578 int nRelations
= service
.countAllRelationships();
579 Assert
.assertEquals("There should be 1 relationship left in the database", 1, nRelations
);
581 taxon2
= (Taxon
)service
.load(uuidTaxon2
);
582 synonym1
= (Synonym
)service
.load(uuidSynonym1
);
584 service
.deleteSynonym(synonym1
, null, true, true);
586 commitAndStartNewTransaction(tableNames
);
588 nSynonyms
= service
.count(Synonym
.class);
589 Assert
.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms
);
590 nNames
= nameService
.count(TaxonNameBase
.class);
591 Assert
.assertEquals("There should be 3 names left in the database", 3, nNames
);
592 nRelations
= service
.countAllRelationships();
593 Assert
.assertEquals("There should be no relationship left in the database", 0, nRelations
);
598 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
599 public final void testDeleteSynonymSynonymTaxonBooleanDeleteOneTaxon(){
600 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
601 "SynonymRelationship","SynonymRelationship_AUD",
602 "HomotypicalGroup","HomotypicalGroup_AUD"};
604 // printDataSet(System.err, new String[]{"TaxonNode"});
607 int nSynonyms
= service
.count(Synonym
.class);
608 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
609 int nNames
= nameService
.count(TaxonNameBase
.class);
610 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
612 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
613 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
614 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
615 UUID uuidSynonym2
=UUID
.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
617 Taxon taxon1
= (Taxon
)service
.load(uuidTaxon1
);
618 Taxon taxon2
= (Taxon
)service
.load(uuidTaxon2
);
619 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
621 service
.deleteSynonym(synonym1
, taxon1
, true, true);
623 this.commitAndStartNewTransaction(tableNames
);
625 nSynonyms
= service
.count(Synonym
.class);
626 Assert
.assertEquals("There should still be 2 synonyms left in the database (synonym is related to taxon2)", 2, nSynonyms
);
627 nNames
= nameService
.count(TaxonNameBase
.class);
628 Assert
.assertEquals("There should be 4 names left in the database (name not deleted as synonym was not deleted)", 4, nNames
);
629 int nRelations
= service
.countAllRelationships();
630 Assert
.assertEquals("There should be 1 relationship left in the database", 1, nRelations
);
635 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
636 public final void testDeleteSynonymSynonymTaxonBooleanWithRelatedName(){
637 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
638 "SynonymRelationship","SynonymRelationship_AUD",
639 "HomotypicalGroup","HomotypicalGroup_AUD"};
641 int nSynonyms
= service
.count(Synonym
.class);
642 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
643 int nNames
= nameService
.count(TaxonNameBase
.class);
644 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
646 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
647 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
648 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
649 UUID uuidSynonym2
=UUID
.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
650 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
652 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
653 TaxonNameBase name2
= (TaxonNameBase
)nameService
.load(uuidSynonymName2
);
654 synonym1
.getName().addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null);
656 service
.deleteSynonym(synonym1
, null, true, true);
658 this.commitAndStartNewTransaction(tableNames
);
660 nSynonyms
= service
.count(Synonym
.class);
661 Assert
.assertEquals("There should still be 1 synonyms left in the database", 1, nSynonyms
);
662 nNames
= nameService
.count(TaxonNameBase
.class);
663 Assert
.assertEquals("There should be 4 names left in the database (name is related to synonymName2)", 4, nNames
);
664 int nRelations
= service
.countAllRelationships();
665 //may change with better implementation of countAllRelationships (see #2653)
666 Assert
.assertEquals("There should be 0 taxon relationships left in the database", 0, nRelations
);
667 nRelations
= nameService
.getAllRelationships(1000, 0).size();
668 Assert
.assertEquals("There should be 1 name relationship left in the database", 1, nRelations
);
672 name2
= (TaxonNameBase
)nameService
.load(uuidSynonymName2
);
673 NameRelationship rel
= CdmBase
.deproxy(name2
.getNameRelations().iterator().next(), NameRelationship
.class);
674 name2
.removeNameRelationship(rel
);
675 nameService
.save(name2
);
677 this.endTransaction();
682 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
683 public final void testDeleteSynonymSynonymTaxonBooleanWithRollback(){
684 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
685 "SynonymRelationship","SynonymRelationship_AUD",
686 "HomotypicalGroup","HomotypicalGroup_AUD"};
688 int nSynonyms
= service
.count(Synonym
.class);
689 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
690 int nNames
= nameService
.count(TaxonNameBase
.class);
691 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
692 int nRelations
= service
.countAllRelationships();
693 //may change with better implementation of countAllRelationships (see #2653)
694 Assert
.assertEquals("There should be 2 relationship in the database (the 2 synonym relationship) but no name relationship", 2, nRelations
);
696 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
697 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
699 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
700 TaxonNameBase name2
= (TaxonNameBase
)nameService
.load(uuidSynonymName2
);
701 synonym1
.getName().addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null);
703 service
.deleteSynonym(synonym1
, null, true, true);
706 // printDataSet(System.out, tableNames);
707 this.startNewTransaction();
709 nSynonyms
= service
.count(Synonym
.class);
710 Assert
.assertEquals("There should still be 2 synonyms left in the database", 2, nSynonyms
);
711 nNames
= nameService
.count(TaxonNameBase
.class);
712 Assert
.assertEquals("There should be 4 names left in the database", 4, nNames
);
713 nRelations
= service
.countAllRelationships();
714 //may change with better implementation of countAllRelationships (see #2653)
715 Assert
.assertEquals("There should be 2 relationship in the database (the 2 synonym relationship) but no name relationship", 2, nRelations
);
720 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
721 public final void testDeleteSynonymSynonymTaxonBooleanWithoutTransaction(){
722 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
723 "SynonymRelationship","SynonymRelationship_AUD",
724 "HomotypicalGroup","HomotypicalGroup_AUD"};
726 int nSynonyms
= service
.count(Synonym
.class);
727 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
728 int nNames
= nameService
.count(TaxonNameBase
.class);
729 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
730 int nRelations
= service
.countAllRelationships();
731 //may change with better implementation of countAllRelationships (see #2653)
732 Assert
.assertEquals("There should be 2 relationship in the database (the 2 synonym relationship) but no name relationship", 2, nRelations
);
734 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
735 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
737 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
738 TaxonNameBase name2
= (TaxonNameBase
)nameService
.load(uuidSynonymName2
);
739 synonym1
.getName().addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null);
741 service
.saveOrUpdate(synonym1
);
744 this.endTransaction();
746 // printDataSet(System.out, tableNames);
748 //out of wrapping transaction
749 service
.deleteSynonym(synonym1
, null, true, true);
751 this.startNewTransaction();
753 nSynonyms
= service
.count(Synonym
.class);
754 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
);
755 nNames
= nameService
.count(TaxonNameBase
.class);
756 Assert
.assertEquals("There should be 4 names left in the database", 4, nNames
);
757 nRelations
= service
.countAllRelationships();
758 Assert
.assertEquals("There should be no taxon or synonym relationship in the database", 0, nRelations
);
759 nRelations
= nameService
.getAllRelationships(1000,0).size();
760 Assert
.assertEquals("There should be 1 name relationship in the database", 1, nRelations
);
765 @DataSet("TaxonServiceImplTest.testInferredSynonyms.xml")
766 public void testCreateInferredSynonymy(){
768 UUID classificationUuid
= UUID
.fromString("aeee7448-5298-4991-b724-8d5b75a0a7a9");
769 Classification tree
= classificationService
.find(classificationUuid
);
770 UUID taxonUuid
= UUID
.fromString("bc09aca6-06fd-4905-b1e7-cbf7cc65d783");
771 TaxonBase
<?
> taxonBase
= service
.find(taxonUuid
);
772 List
<TaxonBase
> synonyms
= service
.list(Synonym
.class, null, null, null, null);
773 assertEquals("Number of synonyms should be 2",2,synonyms
.size());
774 Taxon taxon
= (Taxon
)taxonBase
;
776 //synonyms = taxonDao.getAllSynonyms(null, null);
777 //assertEquals("Number of synonyms should be 2",2,synonyms.size());
778 List
<Synonym
> inferredSynonyms
= service
.createInferredSynonyms(taxon
, tree
, SynonymRelationshipType
.INFERRED_EPITHET_OF(), true);
779 assertNotNull("there should be a new synonym ", inferredSynonyms
);
780 // System.err.println(inferredSynonyms.size());
781 assertEquals ("the name of inferred epithet should be SynGenus lachesis", inferredSynonyms
.get(0).getTitleCache(), "SynGenus lachesis sec. ");
783 inferredSynonyms
= service
.createInferredSynonyms(taxon
, tree
, SynonymRelationshipType
.INFERRED_GENUS_OF(), true);
784 assertNotNull("there should be a new synonym ", inferredSynonyms
);
785 // System.err.println(inferredSynonyms.get(0).getTitleCache());
786 assertEquals ("the name of inferred epithet should be SynGenus lachesis", inferredSynonyms
.get(0).getTitleCache(), "Acherontia ciprosus sec. ");
788 inferredSynonyms
= service
.createInferredSynonyms(taxon
, tree
, SynonymRelationshipType
.POTENTIAL_COMBINATION_OF(), true);
789 assertNotNull("there should be a new synonym ", inferredSynonyms
);
790 assertEquals ("the name of inferred epithet should be SynGenus lachesis", inferredSynonyms
.get(0).getTitleCache(), "SynGenus ciprosus sec. ");
791 //assertTrue("set of synonyms should contain an inferred Synonym ", synonyms.contains(arg0))
795 @DataSet("TaxonServiceImplTest.testDeleteTaxonConfig.xml")
796 @Ignore //not fully working yet
797 public final void testDeleteTaxonConfig(){
798 final String
[]tableNames
= {
799 "Classification", "Classification_AUD",
800 "TaxonBase","TaxonBase_AUD",
801 "TaxonNode","TaxonNode_AUD",
802 "TaxonNameBase","TaxonNameBase_AUD",
803 "SynonymRelationship","SynonymRelationship_AUD",
804 "TaxonRelationship", "TaxonRelationship_AUD",
805 "TaxonDescription", "TaxonDescription_AUD",
806 "HomotypicalGroup","HomotypicalGroup_AUD",
807 "PolytomousKey","PolytomousKey_AUD",
808 "PolytomousKeyNode","PolytomousKeyNode_AUD",
810 "WorkingSet","WorkingSet_AUD",
811 "DescriptionElementBase","DescriptionElementBase_AUD"};
813 UUID uuidParent
=UUID
.fromString("b5271d4f-e203-4577-941f-00d76fa9f4ca");
814 UUID uuidChild1
=UUID
.fromString("326167f9-0b97-4e7d-b1bf-4ca47b82e21e");
815 UUID uuidSameAs
=UUID
.fromString("c2bb0f01-f2dd-43fb-ba12-2a85727ccb8d");
817 int nTaxa
= service
.count(Taxon
.class);
818 Assert
.assertEquals("There should be 3 taxa in the database", 3, nTaxa
);
819 Taxon parent
= (Taxon
)service
.find(uuidParent
);
820 Assert
.assertNotNull("Parent taxon should exist", parent
);
821 Taxon child1
= (Taxon
)service
.find(uuidChild1
);
822 Assert
.assertNotNull("Child taxon should exist", child1
);
826 // commitAndStartNewTransaction(tableNames);
827 service
.deleteTaxon(child1
, new TaxonDeletionConfigurator());
828 Assert
.fail("Delete should throw an error as long as name is used in classification.");
829 } catch (ReferencedObjectUndeletableException e
) {
830 if (e
.getMessage().contains("Taxon can't be deleted as it is used in a classification node")){
832 commitAndStartNewTransaction(tableNames
);
834 Assert
.fail("Unexpected error occurred when trying to delete taxon: " + e
.getMessage());
838 nTaxa
= service
.count(Taxon
.class);
839 Assert
.assertEquals("There should be 3 taxa in the database", 3, nTaxa
);
840 child1
= (Taxon
)service
.find(uuidChild1
);
841 Assert
.assertNotNull("Child taxon should exist", child1
);
842 Assert
.assertEquals("Child should belong to 1 node", 1, child1
.getTaxonNodes().size());
844 TaxonNode node
= child1
.getTaxonNodes().iterator().next();
845 node
.getParent().deleteChildNode(node
);
846 service
.save(node
.getTaxon());
847 commitAndStartNewTransaction(tableNames
);
849 child1
= (Taxon
)service
.find(uuidChild1
);
851 service
.deleteTaxon(child1
, new TaxonDeletionConfigurator());
852 } catch (ReferencedObjectUndeletableException e
) {
853 Assert
.fail("Delete should not throw an exception anymore");
857 // nNames = nameService.count(TaxonNameBase.class);
858 // Assert.assertEquals("There should be 3 names left in the database", 3, nNames);
859 // int nRelations = service.countAllRelationships();
860 // Assert.assertEquals("There should be no relationship left in the database", 0, nRelations);
865 // public final void testDeleteTaxonCreateData(){
866 // final String[]tableNames = {"TaxonBase","TaxonBase_AUD",
867 // "TaxonNode","TaxonNode_AUD",
868 // "TaxonNameBase","TaxonNameBase_AUD",
869 // "SynonymRelationship","SynonymRelationship_AUD",
870 // "TaxonRelationship", "TaxonRelationship_AUD",
871 // "TaxonDescription", "TaxonDescription_AUD",
872 // "HomotypicalGroup","HomotypicalGroup_AUD",
873 // "PolytomousKey","PolytomousKey_AUD",
874 // "PolytomousKeyNode","PolytomousKeyNode_AUD",
875 // "Media","Media_AUD",
876 // "WorkingSet","WorkingSet_AUD",
877 // "DescriptionElementBase","DescriptionElementBase_AUD",
878 // "Classification","Classification_AUD"};
881 // BotanicalName taxonName1 = BotanicalName.NewInstance(Rank.GENUS());
882 // taxonName1.setTitleCache("parent",true);
883 // BotanicalName taxonName2 = BotanicalName.NewInstance(Rank.SPECIES());
884 // taxonName2.setTitleCache("child1",true);
885 // BotanicalName synonymName1 = BotanicalName.NewInstance(Rank.SPECIES());
886 // synonymName1.setTitleCache("Synonym1",true);
887 // BotanicalName sameAsName = BotanicalName.NewInstance(Rank.SPECIES());
888 // sameAsName.setTitleCache("sameAs",true);
890 // Reference<?> sec = null;
891 // Taxon parent = Taxon.NewInstance(taxonName1, sec);
892 // Taxon child1 = Taxon.NewInstance(taxonName2, sec);
893 // Synonym synonym1 = Synonym.NewInstance(synonymName1, sec);
894 // Taxon sameAs = Taxon.NewInstance(sameAsName, sec);
896 // child1.addSynonym(synonym1, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
897 // Classification classification1 = Classification.NewInstance("classification1");
898 // classification1.addParentChild(parent, child1, null, null);
901 // child1.addTaxonRelation(sameAs, TaxonRelationshipType.CONGRUENT_TO(), null, null);
903 // service.save(child1);
905 // this.commitAndStartNewTransaction(tableNames);