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
.io
.IOException
;
17 import java
.net
.URISyntaxException
;
18 import java
.sql
.SQLException
;
19 import java
.util
.List
;
21 import java
.util
.UUID
;
23 import org
.apache
.log4j
.Logger
;
24 import org
.dbunit
.DatabaseUnitException
;
25 import org
.junit
.Assert
;
26 import org
.junit
.Ignore
;
27 import org
.junit
.Before
;
28 import org
.junit
.Test
;
29 import org
.unitils
.dbunit
.annotation
.DataSet
;
30 import org
.unitils
.dbunit
.datasetfactory
.DataSetFactory
;
31 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
33 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
34 import eu
.etaxonomy
.cdm
.api
.service
.exception
.HomotypicalGroupChangeException
;
35 import eu
.etaxonomy
.cdm
.api
.service
.exception
.ReferencedObjectUndeletableException
;
36 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
37 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
38 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
39 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
40 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
41 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
42 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
43 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
44 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
45 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
46 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
47 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
48 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
49 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
50 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
51 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
52 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
53 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
54 import eu
.etaxonomy
.cdm
.test
.unitils
.CleanSweepInsertLoadStrategy
;
60 public class TaxonServiceImplTest
extends CdmTransactionalIntegrationTest
{
61 private static final Logger logger
= Logger
.getLogger(TaxonServiceImplTest
.class);
64 private ITaxonService service
;
67 private INameService nameService
;
70 private IReferenceService referenceService
;
73 private IClassificationService classificationService
;
76 /****************** TESTS *****************************/
80 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#getTaxonByUuid(java.util.UUID)}.
83 public final void testGetTaxonByUuid() {
84 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
85 UUID uuid
= service
.save(expectedTaxon
);
86 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
87 assertEquals(expectedTaxon
, actualTaxon
);
91 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#saveTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)}.
94 public final void testSaveTaxon() {
95 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
96 UUID uuid
= service
.save(expectedTaxon
);
97 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
98 assertEquals(expectedTaxon
, actualTaxon
);
102 public final void testSaveOrUpdateTaxon() {
103 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
104 UUID uuid
= service
.save(expectedTaxon
);
105 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
106 assertEquals(expectedTaxon
, actualTaxon
);
108 actualTaxon
.setName(BotanicalName
.NewInstance(Rank
.SPECIES()));
110 service
.saveOrUpdate(actualTaxon
);
116 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#removeTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)}.
119 public final void testRemoveTaxon() {
120 Taxon taxon
= Taxon
.NewInstance(BotanicalName
.NewInstance(null), null);
121 UUID uuid
= service
.save(taxon
);
122 service
.delete(taxon
);
123 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
124 assertNull(actualTaxon
);
128 // @DataSet("ClearDBDataSet.xml")
129 // public final void clearDataBase() {
132 // commitAndStartNewTransaction(null);
134 // logger.info("DataBase tables cleared");
139 public final void testPrintDataSet() {
141 // printDataSet(System.out);
142 // printDataSet(System.err, new String[] {"TAXONNODE", "AgentBase"});
143 // printTableNames(System.err, "<%1$s />");
149 public final void testMakeTaxonSynonym() {
150 Rank rank
= Rank
.SPECIES();
151 Taxon tax1
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test1", null, null, null, null, null, null, null), null);
152 Synonym synonym
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
153 tax1
.addHomotypicSynonym(synonym
, null, null);
154 UUID uuidTaxon
= service
.save(tax1
);
155 UUID uuidSyn
= service
.save(synonym
);
157 service
.swapSynonymAndAcceptedTaxon(synonym
, tax1
);
160 TaxonBase
<?
> tax
= service
.find(uuidTaxon
);
161 TaxonBase
<?
> syn
= service
.find(uuidSyn
);
162 HomotypicalGroup groupTest
= tax
.getHomotypicGroup();
163 HomotypicalGroup groupTest2
= syn
.getHomotypicGroup();
164 assertEquals(groupTest
, groupTest2
);
168 public final void testChangeSynonymToAcceptedTaxon(){
169 Rank rank
= Rank
.SPECIES();
170 //HomotypicalGroup group = HomotypicalGroup.NewInstance();
171 Taxon taxWithoutSyn
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test1", null, null, null, null, null, null, null), null);
172 Taxon taxWithSyn
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
173 Synonym synonym
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
174 Synonym synonym2
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
175 synonym2
.getName().setHomotypicalGroup(synonym
.getHomotypicGroup());
176 //tax2.addHeterotypicSynonymName(synonym.getName());
177 taxWithSyn
.addSynonym(synonym
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
178 taxWithSyn
.addSynonym(synonym2
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
180 service
.save(taxWithoutSyn
);
181 UUID uuidSyn
= service
.save(synonym
);
182 service
.save(synonym2
);
183 service
.save(taxWithSyn
);
187 taxon
= service
.changeSynonymToAcceptedTaxon(synonym
, taxWithSyn
, true, true, null, null);
188 } catch (HomotypicalGroupChangeException e
) {
189 Assert
.fail("Invocation of change method should not throw an exception");
191 //test flush (resave deleted object)
192 TaxonBase
<?
> syn
= service
.find(uuidSyn
);
194 Assert
.assertEquals("New taxon should have 1 synonym relationship (the old homotypic synonym)", 1, taxon
.getSynonymRelations().size());
199 * Old implementation taken from {@link TaxonServiceImplBusinessTest} for old version of method.
200 * 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)}.
203 public final void testMoveSynonymToAnotherTaxon_OLD() {
204 SynonymRelationshipType heteroTypicSynonymRelationshipType
= SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF();
205 Reference
<?
> reference
= ReferenceFactory
.newGeneric();
206 String referenceDetail
= "test";
208 NonViralName
<?
> t1n
= NonViralName
.NewInstance(null);
209 Taxon t1
= Taxon
.NewInstance(t1n
, reference
);
210 NonViralName
<?
> t2n
= NonViralName
.NewInstance(null);
211 Taxon t2
= Taxon
.NewInstance(t2n
, reference
);
212 NonViralName
<?
> s1n
= NonViralName
.NewInstance(null);
213 Synonym s1
= Synonym
.NewInstance(s1n
, reference
);
214 t1
.addSynonym(s1
, heteroTypicSynonymRelationshipType
);
216 SynonymRelationship synonymRelation
= t1
.getSynonymRelations().iterator().next();
218 boolean keepReference
= false;
219 boolean moveHomotypicGroup
= false;
221 service
.moveSynonymToAnotherTaxon(synonymRelation
, t2
, moveHomotypicGroup
, heteroTypicSynonymRelationshipType
, reference
, referenceDetail
, keepReference
);
222 } catch (HomotypicalGroupChangeException e
) {
223 Assert
.fail("Method call should not throw exception");
226 Assert
.assertTrue("t1 should have no synonym relationships", t1
.getSynonymRelations().isEmpty());
228 Set
<SynonymRelationship
> synonymRelations
= t2
.getSynonymRelations();
229 Assert
.assertTrue("t2 should have exactly one synonym relationship", synonymRelations
.size() == 1);
231 synonymRelation
= synonymRelations
.iterator().next();
233 Assert
.assertEquals(t2
, synonymRelation
.getAcceptedTaxon());
234 Assert
.assertEquals(heteroTypicSynonymRelationshipType
, synonymRelation
.getType());
235 Assert
.assertEquals(reference
, synonymRelation
.getCitation());
236 Assert
.assertEquals(referenceDetail
, synonymRelation
.getCitationMicroReference());
240 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testMoveSynonymToAnotherTaxon.xml")
241 public final void testMoveSynonymToAnotherTaxon() throws Exception
{
242 final String
[] tableNames
= new String
[]{"SynonymRelationship"};
244 // printDataSet(System.err, new String[]{"AgentBase", "TaxonBase"});
245 // printDataSet(System.err, new String[]{"TaxonNode"});
247 UUID uuidNewTaxon
= UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
248 UUID uuidOldTaxon
= UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
249 UUID uuidSyn1
= UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
250 UUID uuidSyn3
= UUID
.fromString("3fba2b22-22ae-4291-af67-faab748a5232");
251 UUID uuidSyn4
= UUID
.fromString("f9b589c7-50cf-4df2-a52e-1b85eb7e4805");
252 UUID uuidSyn5
= UUID
.fromString("fcc0bcf8-8bac-43bd-9508-1e97821587dd");
253 UUID uuidSyn6
= UUID
.fromString("0ccd4e7c-6fbd-4b7c-bd47-29e45b92f34b");
254 UUID uuidRef1
= UUID
.fromString("336f9b38-698c-45d7-be7b-993ed3355bdc");
255 UUID uuidRef2
= UUID
.fromString("c8f49d1a-69e1-48a3-98bb-45d61f3da3e7");
258 boolean moveHomotypicGroup
= true;
259 SynonymRelationshipType newSynonymRelationshipType
= null;
260 boolean keepReference
= true;
261 Reference
<?
> newReference
= null;
262 String newReferenceDetail
= null;
264 Taxon newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
265 Synonym homotypicSynonym
= (Synonym
)service
.load(uuidSyn1
);
266 Assert
.assertNotNull("Synonym should exist", homotypicSynonym
);
267 Assert
.assertEquals("Synonym should have 1 relation", 1, homotypicSynonym
.getSynonymRelations().size());
268 SynonymRelationship rel
= homotypicSynonym
.getSynonymRelations().iterator().next();
269 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
270 Taxon oldTaxon
= rel
.getAcceptedTaxon();
273 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
274 Assert
.fail("Homotypic synonym move to other taxon should throw an exception");
275 } catch (HomotypicalGroupChangeException e
) {
276 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")){
278 commitAndStartNewTransaction(tableNames
);
280 Assert
.fail("Unexpected exception occurred: " + e
.getMessage());
284 homotypicSynonym
= (Synonym
)service
.load(uuidSyn1
);
285 Assert
.assertNotNull("Synonym should still exist", homotypicSynonym
);
286 Assert
.assertEquals("Synonym should still have 1 relation", 1, homotypicSynonym
.getSynonymRelations().size());
287 rel
= homotypicSynonym
.getSynonymRelations().iterator().next();
288 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", oldTaxon
, rel
.getAcceptedTaxon());
290 //test heterotypic synonym with other synonym in homotypic group
291 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
292 Synonym heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
293 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
294 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
295 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
296 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
297 oldTaxon
= rel
.getAcceptedTaxon();
298 moveHomotypicGroup
= false;
301 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
302 Assert
.fail("Heterotypic synonym move to other taxon should throw an exception");
303 } catch (HomotypicalGroupChangeException e
) {
304 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")){
306 commitAndStartNewTransaction(tableNames
);
308 Assert
.fail("Unexpected exception occurred: " + e
.getMessage());
312 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
313 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
314 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
315 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
316 Assert
.assertEquals("Accepted taxon of single relation should still be the old taxon", oldTaxon
, rel
.getAcceptedTaxon());
319 //test heterotypic synonym with no other synonym in homotypic group
322 // printDataSet(System.err, new String[]{"TaxonBase"});
324 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
325 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn5
);
326 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
327 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
328 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
329 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
330 oldTaxon
= rel
.getAcceptedTaxon();
331 moveHomotypicGroup
= false;
335 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
336 } catch (HomotypicalGroupChangeException e
) {
337 Assert
.fail("Move of single heterotypic synonym should not throw exception: " + e
.getMessage());
340 //FIXME thows exception
341 commitAndStartNewTransaction(tableNames
);
343 // printDataSet(System.err, new String[]{"AgentBase", "TaxonBase"});
345 // printDataSet(System.err, new String[]{"TaxonBase"});
347 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn5
);
349 printDataSet(System
.err
, new String
[]{"TaxonBase"});
352 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
353 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
354 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
355 Assert
.assertEquals("Accepted taxon of single relation should be new taxon", newTaxon
, rel
.getAcceptedTaxon());
356 Assert
.assertEquals("Old detail should be kept", "rel5", rel
.getCitationMicroReference());
359 //test heterotypic synonym with other synonym in homotypic group and moveHomotypicGroup="true"
361 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
362 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
363 Reference
<?
> ref1
= referenceService
.load(uuidRef1
);
364 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
365 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
366 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
367 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
368 oldTaxon
= rel
.getAcceptedTaxon();
369 Assert
.assertEquals("Detail should be ref1", ref1
, rel
.getCitation());
370 Assert
.assertEquals("Detail should be 'rel3'", "rel3", rel
.getCitationMicroReference());
371 TaxonNameBase
<?
,?
> oldSynName3
= heterotypicSynonym
.getName();
373 Synonym heterotypicSynonym4
= (Synonym
)service
.load(uuidSyn4
);
374 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym4
);
375 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym4
.getSynonymRelations().size());
376 SynonymRelationship rel4
= heterotypicSynonym4
.getSynonymRelations().iterator().next();
377 Assert
.assertEquals("Accepted taxon of other synonym in group should be the old taxon", uuidOldTaxon
, rel4
.getAcceptedTaxon().getUuid());
378 Assert
.assertSame("Homotypic group of both synonyms should be same", oldSynName3
.getHomotypicalGroup() , heterotypicSynonym4
.getName().getHomotypicalGroup() );
380 moveHomotypicGroup
= true;
381 keepReference
= false;
384 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
385 } catch (HomotypicalGroupChangeException e
) {
386 Assert
.fail("Move with 'moveHomotypicGroup = true' should not throw exception: " + e
.getMessage());
389 commitAndStartNewTransaction(tableNames
);
390 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
391 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
392 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
393 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
394 Assert
.assertEquals("Accepted taxon of relation should be new taxon now", newTaxon
, rel
.getAcceptedTaxon());
395 TaxonNameBase
<?
,?
> synName3
= rel
.getSynonym().getName();
397 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn4
);
398 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
399 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
400 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
401 Assert
.assertEquals("Accepted taxon of relation should be new taxon now", newTaxon
, rel
.getAcceptedTaxon());
402 Assert
.assertNull("Old citation should be removed", rel
.getCitation());
403 Assert
.assertNull("Old detail should be removed", rel
.getCitationMicroReference());
404 TaxonNameBase
<?
,?
> synName4
= rel
.getSynonym().getName();
405 Assert
.assertEquals("Homotypic group of both synonyms should be equal", synName3
.getHomotypicalGroup() , synName4
.getHomotypicalGroup() );
406 Assert
.assertSame("Homotypic group of both synonyms should be same", synName3
.getHomotypicalGroup() , synName4
.getHomotypicalGroup() );
407 Assert
.assertEquals("Homotypic group of both synonyms should be equal to old homotypic group", oldSynName3
.getHomotypicalGroup() , synName3
.getHomotypicalGroup() );
410 //test single heterotypic synonym to homotypic synonym of new taxon
412 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
413 Reference
<?
> ref2
= (Reference
<?
>)referenceService
.load(uuidRef2
);
414 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn6
);
415 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
416 Assert
.assertEquals("Synonym should have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
417 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
418 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, rel
.getAcceptedTaxon().getUuid());
419 oldTaxon
= rel
.getAcceptedTaxon();
420 moveHomotypicGroup
= false;
421 keepReference
= false;
423 newReferenceDetail
= "newRefDetail";
424 newSynonymRelationshipType
= SynonymRelationshipType
.HOMOTYPIC_SYNONYM_OF();
427 service
.moveSynonymToAnotherTaxon(rel
, newTaxon
, moveHomotypicGroup
, newSynonymRelationshipType
, newReference
, newReferenceDetail
, keepReference
);
428 } catch (HomotypicalGroupChangeException e
) {
429 Assert
.fail("Move of single heterotypic synonym should not throw exception: " + e
.getMessage());
432 commitAndStartNewTransaction(tableNames
);
433 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn6
);
434 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
435 Assert
.assertEquals("Synonym should still have 1 relation", 1, heterotypicSynonym
.getSynonymRelations().size());
436 rel
= heterotypicSynonym
.getSynonymRelations().iterator().next();
437 Assert
.assertEquals("Relationship type should be 'homotypic synonym'", newSynonymRelationshipType
, rel
.getType());
438 Assert
.assertEquals("Accepted taxon of single relation should be new taxon", newTaxon
, rel
.getAcceptedTaxon());
439 Assert
.assertEquals("New citation should be ref2", ref2
,rel
.getCitation());
440 Assert
.assertEquals("New detail should be kept", "newRefDetail", rel
.getCitationMicroReference());
442 Assert
.assertEquals("New taxon and new synonym should have equal homotypical group", rel
.getSynonym().getHomotypicGroup(), rel
.getAcceptedTaxon().getHomotypicGroup());
443 Assert
.assertSame("New taxon and new synonym should have same homotypical group", rel
.getSynonym().getHomotypicGroup(), rel
.getAcceptedTaxon().getHomotypicGroup());
449 public final void testGetHeterotypicSynonymyGroups(){
450 Rank rank
= Rank
.SPECIES();
451 Reference
<?
> ref1
= ReferenceFactory
.newGeneric();
452 //HomotypicalGroup group = HomotypicalGroup.NewInstance();
453 Taxon taxon1
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
454 Synonym synonym0
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
455 Synonym synonym1
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
456 Synonym synonym2
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
457 synonym0
.getName().setHomotypicalGroup(taxon1
.getHomotypicGroup());
458 synonym2
.getName().setHomotypicalGroup(synonym1
.getHomotypicGroup());
459 //tax2.addHeterotypicSynonymName(synonym.getName());
460 taxon1
.addSynonym(synonym1
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
461 taxon1
.addSynonym(synonym2
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
463 service
.save(synonym1
);
464 service
.save(synonym2
);
465 service
.save(taxon1
);
467 List
<List
<Synonym
>> heteroSyns
= service
.getHeterotypicSynonymyGroups(taxon1
, null);
468 Assert
.assertEquals("There should be 1 heterotypic group", 1, heteroSyns
.size());
469 List
<Synonym
> synList
= heteroSyns
.get(0);
470 Assert
.assertEquals("There should be 2 heterotypic syns in group 1", 2, synList
.size());
473 synonym2
.setSec(ref1
);
474 heteroSyns
= service
.getHeterotypicSynonymyGroups(taxon1
, null);
475 Assert
.assertEquals("There should be 1 heterotypic group", 1, heteroSyns
.size());
476 synList
= heteroSyns
.get(0);
477 Assert
.assertEquals("getHeterotypicSynonymyGroups should be independent of sec reference", 2, synList
.size());
483 public final void testGetHomotypicSynonymsByHomotypicGroup(){
484 Rank rank
= Rank
.SPECIES();
485 Reference
<?
> ref1
= ReferenceFactory
.newGeneric();
486 //HomotypicalGroup group = HomotypicalGroup.NewInstance();
487 Taxon taxon1
= Taxon
.NewInstance(BotanicalName
.NewInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
488 Synonym synonym0
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
489 Synonym synonym1
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
490 Synonym synonym2
= Synonym
.NewInstance(BotanicalName
.NewInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
491 synonym0
.getName().setHomotypicalGroup(taxon1
.getHomotypicGroup());
492 synonym2
.getName().setHomotypicalGroup(synonym1
.getHomotypicGroup());
493 //tax2.addHeterotypicSynonymName(synonym.getName());
494 taxon1
.addSynonym(synonym0
, SynonymRelationshipType
.HOMOTYPIC_SYNONYM_OF());
495 taxon1
.addSynonym(synonym1
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
496 taxon1
.addSynonym(synonym2
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
498 service
.save(synonym1
);
499 service
.save(synonym2
);
500 service
.save(taxon1
);
502 List
<Synonym
> homoSyns
= service
.getHomotypicSynonymsByHomotypicGroup(taxon1
, null);
503 Assert
.assertEquals("There should be 1 heterotypic group", 1, homoSyns
.size());
504 Assert
.assertSame("The homotypic synonym should be synonym0", synonym0
, homoSyns
.get(0));
507 synonym0
.setSec(ref1
);
508 homoSyns
= service
.getHomotypicSynonymsByHomotypicGroup(taxon1
, null);
509 Assert
.assertEquals("getHeterotypicSynonymyGroups should be independent of sec reference", 1, homoSyns
.size());
514 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
515 public final void testDeleteSynonymSynonymTaxonBoolean(){
516 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
517 "SynonymRelationship","SynonymRelationship_AUD",
518 "HomotypicalGroup","HomotypicalGroup_AUD"};
519 // BotanicalName taxonName1 = BotanicalName.NewInstance(Rank.SPECIES());
520 // taxonName1.setTitleCache("TaxonName1",true);
521 // BotanicalName taxonName2 = BotanicalName.NewInstance(Rank.SPECIES());
522 // taxonName2.setTitleCache("TaxonName2",true);
523 // BotanicalName synonymName1 = BotanicalName.NewInstance(Rank.SPECIES());
524 // synonymName1.setTitleCache("Synonym1",true);
525 // BotanicalName synonymName2 = BotanicalName.NewInstance(Rank.SPECIES());
526 // synonymName2.setTitleCache("Synonym2",true);
528 // Reference<?> sec = null;
529 // Taxon taxon1 = Taxon.NewInstance(taxonName1, sec);
530 // Taxon taxon2 = Taxon.NewInstance(taxonName2, sec);
531 // Synonym synonym1 = Synonym.NewInstance(synonymName1, sec);
532 // Synonym synonym2 = Synonym.NewInstance(synonymName2, sec);
534 // SynonymRelationship rel1 = taxon1.addSynonym(synonym1, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
535 // SynonymRelationship rel = taxon2.addSynonym(synonym1, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
536 // rel.setProParte(true);
537 // rel1.setProParte(true);
539 // service.save(taxon1);
540 // service.save(synonym2);
542 // this.setComplete();
543 // this.endTransaction();
546 int nSynonyms
= service
.count(Synonym
.class);
547 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
548 int nNames
= nameService
.count(TaxonNameBase
.class);
549 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
551 // UUID uuidTaxon1=UUID.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
552 // UUID uuidTaxon2=UUID.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
553 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
554 // UUID uuidSynonym2=UUID.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
556 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
557 service
.deleteSynonym(synonym1
, null, true, true);
559 this.commitAndStartNewTransaction(tableNames
);
561 nSynonyms
= service
.count(Synonym
.class);
562 Assert
.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms
);
563 nNames
= nameService
.count(TaxonNameBase
.class);
564 Assert
.assertEquals("There should be 3 names left in the database", 3, nNames
);
565 int nRelations
= service
.countAllRelationships();
566 Assert
.assertEquals("There should be no relationship left in the database", 0, nRelations
);
570 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
571 public final void testDeleteSynonymSynonymTaxonBooleanRelToOneTaxon(){
572 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
573 "SynonymRelationship","SynonymRelationship_AUD",
574 "HomotypicalGroup","HomotypicalGroup_AUD"};
576 int nSynonyms
= service
.count(Synonym
.class);
577 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
578 int nNames
= nameService
.count(TaxonNameBase
.class);
579 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
581 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
582 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
583 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
584 // UUID uuidSynonym2=UUID.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
586 Taxon taxon2
= (Taxon
)service
.load(uuidTaxon2
);
589 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
591 taxon2
.removeSynonym(synonym1
, false);
592 service
.saveOrUpdate(taxon2
);
594 commitAndStartNewTransaction(null);
596 nSynonyms
= service
.count(Synonym
.class);
597 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
598 nNames
= nameService
.count(TaxonNameBase
.class);
599 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
600 int nRelations
= service
.countAllRelationships();
601 Assert
.assertEquals("There should be 1 relationship left in the database", 1, nRelations
);
603 taxon2
= (Taxon
)service
.load(uuidTaxon2
);
604 synonym1
= (Synonym
)service
.load(uuidSynonym1
);
606 service
.deleteSynonym(synonym1
, null, true, true);
608 commitAndStartNewTransaction(tableNames
);
610 nSynonyms
= service
.count(Synonym
.class);
611 Assert
.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms
);
612 nNames
= nameService
.count(TaxonNameBase
.class);
613 Assert
.assertEquals("There should be 3 names left in the database", 3, nNames
);
614 nRelations
= service
.countAllRelationships();
615 Assert
.assertEquals("There should be no relationship left in the database", 0, nRelations
);
620 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
621 public final void testDeleteSynonymSynonymTaxonBooleanDeleteOneTaxon(){
622 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
623 "SynonymRelationship","SynonymRelationship_AUD",
624 "HomotypicalGroup","HomotypicalGroup_AUD"};
626 // printDataSet(System.err, new String[]{"TaxonNode"});
629 int nSynonyms
= service
.count(Synonym
.class);
630 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
631 int nNames
= nameService
.count(TaxonNameBase
.class);
632 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
634 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
635 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
636 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
637 UUID uuidSynonym2
=UUID
.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
639 Taxon taxon1
= (Taxon
)service
.load(uuidTaxon1
);
640 Taxon taxon2
= (Taxon
)service
.load(uuidTaxon2
);
641 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
643 service
.deleteSynonym(synonym1
, taxon1
, true, true);
645 this.commitAndStartNewTransaction(tableNames
);
647 nSynonyms
= service
.count(Synonym
.class);
648 Assert
.assertEquals("There should still be 2 synonyms left in the database (synonym is related to taxon2)", 2, nSynonyms
);
649 nNames
= nameService
.count(TaxonNameBase
.class);
650 Assert
.assertEquals("There should be 4 names left in the database (name not deleted as synonym was not deleted)", 4, nNames
);
651 int nRelations
= service
.countAllRelationships();
652 Assert
.assertEquals("There should be 1 relationship left in the database", 1, nRelations
);
657 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
658 public final void testDeleteSynonymSynonymTaxonBooleanWithRelatedName(){
659 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
660 "SynonymRelationship","SynonymRelationship_AUD",
661 "HomotypicalGroup","HomotypicalGroup_AUD"};
663 int nSynonyms
= service
.count(Synonym
.class);
664 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
665 int nNames
= nameService
.count(TaxonNameBase
.class);
666 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
668 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
669 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
670 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
671 UUID uuidSynonym2
=UUID
.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
672 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
674 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
675 TaxonNameBase name2
= (TaxonNameBase
)nameService
.load(uuidSynonymName2
);
676 synonym1
.getName().addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null);
678 service
.deleteSynonym(synonym1
, null, true, true);
680 this.commitAndStartNewTransaction(tableNames
);
682 nSynonyms
= service
.count(Synonym
.class);
683 Assert
.assertEquals("There should still be 1 synonyms left in the database", 1, nSynonyms
);
684 nNames
= nameService
.count(TaxonNameBase
.class);
685 Assert
.assertEquals("There should be 4 names left in the database (name is related to synonymName2)", 4, nNames
);
686 int nRelations
= service
.countAllRelationships();
687 //may change with better implementation of countAllRelationships (see #2653)
688 Assert
.assertEquals("There should be 1 relationship left in the database (the name relationship)", 1, nRelations
);
691 name2
= (TaxonNameBase
)nameService
.load(uuidSynonymName2
);
692 NameRelationship rel
= CdmBase
.deproxy(name2
.getNameRelations().iterator().next(), NameRelationship
.class);
693 name2
.removeNameRelationship(rel
);
694 nameService
.save(name2
);
696 this.endTransaction();
701 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
702 public final void testDeleteSynonymSynonymTaxonBooleanWithRollback(){
703 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
704 "SynonymRelationship","SynonymRelationship_AUD",
705 "HomotypicalGroup","HomotypicalGroup_AUD"};
707 int nSynonyms
= service
.count(Synonym
.class);
708 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
709 int nNames
= nameService
.count(TaxonNameBase
.class);
710 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
711 int nRelations
= service
.countAllRelationships();
712 //may change with better implementation of countAllRelationships (see #2653)
713 Assert
.assertEquals("There should be 2 relationship in the database (the 2 synonym relationship) but no name relationship", 2, nRelations
);
715 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
716 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
718 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
719 TaxonNameBase name2
= (TaxonNameBase
)nameService
.load(uuidSynonymName2
);
720 synonym1
.getName().addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null);
722 service
.deleteSynonym(synonym1
, null, true, true);
725 // printDataSet(System.out, tableNames);
726 this.startNewTransaction();
728 nSynonyms
= service
.count(Synonym
.class);
729 Assert
.assertEquals("There should still be 2 synonyms left in the database", 2, nSynonyms
);
730 nNames
= nameService
.count(TaxonNameBase
.class);
731 Assert
.assertEquals("There should be 4 names left in the database", 4, nNames
);
732 nRelations
= service
.countAllRelationships();
733 //may change with better implementation of countAllRelationships (see #2653)
734 Assert
.assertEquals("There should be 2 relationship in the database (the 2 synonym relationship) but no name relationship", 2, nRelations
);
739 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
740 public final void testDeleteSynonymSynonymTaxonBooleanWithoutTransaction(){
741 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
742 "SynonymRelationship","SynonymRelationship_AUD",
743 "HomotypicalGroup","HomotypicalGroup_AUD"};
745 int nSynonyms
= service
.count(Synonym
.class);
746 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
747 int nNames
= nameService
.count(TaxonNameBase
.class);
748 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
749 int nRelations
= service
.countAllRelationships();
750 //may change with better implementation of countAllRelationships (see #2653)
751 Assert
.assertEquals("There should be 2 relationship in the database (the 2 synonym relationship) but no name relationship", 2, nRelations
);
753 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
754 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
756 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
757 TaxonNameBase name2
= (TaxonNameBase
)nameService
.load(uuidSynonymName2
);
758 synonym1
.getName().addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null);
760 service
.saveOrUpdate(synonym1
);
763 this.endTransaction();
765 printDataSet(System
.out
, tableNames
);
767 //out of wrapping transaction
768 service
.deleteSynonym(synonym1
, null, true, true);
770 this.startNewTransaction();
772 nSynonyms
= service
.count(Synonym
.class);
773 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
);
774 nNames
= nameService
.count(TaxonNameBase
.class);
775 Assert
.assertEquals("There should be 4 names left in the database", 4, nNames
);
776 nRelations
= service
.countAllRelationships();
777 //may change with better implementation of countAllRelationships (see #2653)
778 Assert
.assertEquals("There should be 1 name relationship and no synonym relationship in the database", 1, nRelations
);
783 @DataSet("TaxonServiceImplTest.testInferredSynonyms.xml")
785 public void testCreateInferredSynonymy(){
787 UUID classificationUuid
= UUID
.fromString("aeee7448-5298-4991-b724-8d5b75a0a7a9");
788 Classification tree
= classificationService
.find(classificationUuid
);
789 UUID taxonUuid
= UUID
.fromString("bc09aca6-06fd-4905-b1e7-cbf7cc65d783");
790 TaxonBase taxonBase
= service
.find(taxonUuid
);
791 List
<TaxonBase
> synonyms
= service
.list(Synonym
.class, null, null, null, null);
792 assertEquals("Number of synonyms should be 2",2,synonyms
.size());
793 Taxon taxon
= (Taxon
)taxonBase
;
794 //synonyms = taxonDao.getAllSynonyms(null, null);
795 //assertEquals("Number of synonyms should be 2",2,synonyms.size());
796 List
<Synonym
> inferredSynonyms
= service
.createInferredSynonyms(taxon
, tree
, SynonymRelationshipType
.INFERRED_EPITHET_OF());
797 assertNotNull("there should be a new synonym ", inferredSynonyms
);
798 System
.err
.println(inferredSynonyms
.size());
799 assertEquals ("the name of inferred epithet should be SynGenus lachesis", inferredSynonyms
.get(0).getTitleCache(), "SynGenus lachesis sec. ");
800 inferredSynonyms
= service
.createInferredSynonyms(taxon
, tree
, SynonymRelationshipType
.INFERRED_GENUS_OF());
801 assertNotNull("there should be a new synonym ", inferredSynonyms
);
802 System
.err
.println(inferredSynonyms
.get(0).getTitleCache());
803 assertEquals ("the name of inferred epithet should be SynGenus lachesis", inferredSynonyms
.get(0).getTitleCache(), "Acherontia ciprosus sec. ");
804 inferredSynonyms
= service
.createInferredSynonyms(taxon
, tree
, SynonymRelationshipType
.POTENTIAL_COMBINATION_OF());
805 assertNotNull("there should be a new synonym ", inferredSynonyms
);
806 assertEquals ("the name of inferred epithet should be SynGenus lachesis", inferredSynonyms
.get(0).getTitleCache(), "SynGenus ciprosus sec. ");
807 //assertTrue("set of synonyms should contain an inferred Synonym ", synonyms.contains(arg0))
811 @DataSet("TaxonServiceImplTest.testDeleteTaxonConfig.xml")
812 @Ignore //not fully working yet
813 public final void testDeleteTaxonConfig(){
814 final String
[]tableNames
= {
815 "Classification", "Classification_AUD",
816 "TaxonBase","TaxonBase_AUD",
817 "TaxonNode","TaxonNode_AUD",
818 "TaxonNameBase","TaxonNameBase_AUD",
819 "SynonymRelationship","SynonymRelationship_AUD",
820 "TaxonRelationship", "TaxonRelationship_AUD",
821 "TaxonDescription", "TaxonDescription_AUD",
822 "HomotypicalGroup","HomotypicalGroup_AUD",
823 "PolytomousKey","PolytomousKey_AUD",
824 "PolytomousKeyNode","PolytomousKeyNode_AUD",
826 "WorkingSet","WorkingSet_AUD",
827 "DescriptionElementBase","DescriptionElementBase_AUD"};
829 UUID uuidParent
=UUID
.fromString("b5271d4f-e203-4577-941f-00d76fa9f4ca");
830 UUID uuidChild1
=UUID
.fromString("326167f9-0b97-4e7d-b1bf-4ca47b82e21e");
831 UUID uuidSameAs
=UUID
.fromString("c2bb0f01-f2dd-43fb-ba12-2a85727ccb8d");
833 int nTaxa
= service
.count(Taxon
.class);
834 Assert
.assertEquals("There should be 3 taxa in the database", 3, nTaxa
);
835 Taxon parent
= (Taxon
)service
.find(uuidParent
);
836 Assert
.assertNotNull("Parent taxon should exist", parent
);
837 Taxon child1
= (Taxon
)service
.find(uuidChild1
);
838 Assert
.assertNotNull("Child taxon should exist", child1
);
842 // commitAndStartNewTransaction(tableNames);
843 service
.deleteTaxon(child1
, new TaxonDeletionConfigurator());
844 Assert
.fail("Delete should throw an error as long as name is used in classification.");
845 } catch (ReferencedObjectUndeletableException e
) {
846 if (e
.getMessage().contains("Taxon can't be deleted as it is used in a classification node")){
848 commitAndStartNewTransaction(tableNames
);
850 Assert
.fail("Unexpected error occurred when trying to delete taxon: " + e
.getMessage());
854 nTaxa
= service
.count(Taxon
.class);
855 Assert
.assertEquals("There should be 3 taxa in the database", 3, nTaxa
);
856 child1
= (Taxon
)service
.find(uuidChild1
);
857 Assert
.assertNotNull("Child taxon should exist", child1
);
858 Assert
.assertEquals("Child should belong to 1 node", 1, child1
.getTaxonNodes().size());
860 TaxonNode node
= child1
.getTaxonNodes().iterator().next();
861 node
.getParent().deleteChildNode(node
);
862 service
.save(node
.getTaxon());
863 commitAndStartNewTransaction(tableNames
);
865 child1
= (Taxon
)service
.find(uuidChild1
);
867 service
.deleteTaxon(child1
, new TaxonDeletionConfigurator());
868 } catch (ReferencedObjectUndeletableException e
) {
869 Assert
.fail("Delete should not throw an exception anymore");
873 // nNames = nameService.count(TaxonNameBase.class);
874 // Assert.assertEquals("There should be 3 names left in the database", 3, nNames);
875 // int nRelations = service.countAllRelationships();
876 // Assert.assertEquals("There should be no relationship left in the database", 0, nRelations);
881 // public final void testDeleteTaxonCreateData(){
882 // final String[]tableNames = {"TaxonBase","TaxonBase_AUD",
883 // "TaxonNode","TaxonNode_AUD",
884 // "TaxonNameBase","TaxonNameBase_AUD",
885 // "SynonymRelationship","SynonymRelationship_AUD",
886 // "TaxonRelationship", "TaxonRelationship_AUD",
887 // "TaxonDescription", "TaxonDescription_AUD",
888 // "HomotypicalGroup","HomotypicalGroup_AUD",
889 // "PolytomousKey","PolytomousKey_AUD",
890 // "PolytomousKeyNode","PolytomousKeyNode_AUD",
891 // "Media","Media_AUD",
892 // "WorkingSet","WorkingSet_AUD",
893 // "DescriptionElementBase","DescriptionElementBase_AUD",
894 // "Classification","Classification_AUD"};
897 // BotanicalName taxonName1 = BotanicalName.NewInstance(Rank.GENUS());
898 // taxonName1.setTitleCache("parent",true);
899 // BotanicalName taxonName2 = BotanicalName.NewInstance(Rank.SPECIES());
900 // taxonName2.setTitleCache("child1",true);
901 // BotanicalName synonymName1 = BotanicalName.NewInstance(Rank.SPECIES());
902 // synonymName1.setTitleCache("Synonym1",true);
903 // BotanicalName sameAsName = BotanicalName.NewInstance(Rank.SPECIES());
904 // sameAsName.setTitleCache("sameAs",true);
906 // Reference<?> sec = null;
907 // Taxon parent = Taxon.NewInstance(taxonName1, sec);
908 // Taxon child1 = Taxon.NewInstance(taxonName2, sec);
909 // Synonym synonym1 = Synonym.NewInstance(synonymName1, sec);
910 // Taxon sameAs = Taxon.NewInstance(sameAsName, sec);
912 // child1.addSynonym(synonym1, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
913 // Classification classification1 = Classification.NewInstance("classification1");
914 // classification1.addParentChild(parent, child1, null, null);
917 // child1.addTaxonRelation(sameAs, TaxonRelationshipType.CONGRUENT_TO(), null, null);
919 // service.save(child1);
921 // this.commitAndStartNewTransaction(tableNames);