ref #5974 Remove synonym relationships (rename synRelType to synRel and others)
[taxeditor.git] / eu.etaxonomy.taxeditor.test / src / test / java / eu / etaxonomy / taxeditor / operation / TaxonNameEditorTest.java
index 76e9242bf77ccdb23d1dacd3459220acafa8b8bf..a0dce5b8f96a9d707e553b06e8b672798c39322c 100644 (file)
@@ -18,6 +18,7 @@ import java.util.UUID;
 import org.apache.log4j.Logger;
 import org.eclipse.core.commands.ExecutionException;
 import org.junit.Assert;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.unitils.dbunit.annotation.DataSet;
 
@@ -25,6 +26,11 @@ import eu.etaxonomy.cdm.api.service.IClassificationService;
 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
 import eu.etaxonomy.cdm.api.service.ITaxonService;
 import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.common.OriginalSourceType;
+import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.TaxonDescription;
+import eu.etaxonomy.cdm.model.description.TextData;
 import eu.etaxonomy.cdm.model.name.BotanicalName;
 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
 import eu.etaxonomy.cdm.model.name.NonViralName;
@@ -33,6 +39,7 @@ import eu.etaxonomy.cdm.model.taxon.Synonym;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
  * @author cmathew
@@ -109,7 +116,7 @@ public class TaxonNameEditorTest extends BaseOperationTest {
 
         Set<Synonym> synonyms = taxon.getSynonyms();
         for(Synonym synonym : synonyms) {
-            taxonService.deleteSynonym(synonym.getUuid(), taxon.getUuid(), null);
+            taxonService.deleteSynonym(synonym.getUuid(), null);
         }
 
         taxonNodeService.merge(taxonNode);
@@ -151,5 +158,55 @@ public class TaxonNameEditorTest extends BaseOperationTest {
         taxonService.merge(taxon);
     }
 
+    @Ignore
+    @Test
+    public void addDescription() {
+        UUID taxonNodeUuid = UUID.fromString("ce54c396-3694-47f2-abb0-1d7b7e057985");
+
+        TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
+        Taxon taxon = taxonNode.getTaxon();
+        TaxonDescription description = TaxonDescription.NewInstance(taxon);
+
+
+        TextData textData = TextData.NewInstance();
+
+        textData.setFeature(Feature.ECOLOGY());
+        description.addElement(textData);
+
+        DescriptionElementSource descriptionElementSource = DescriptionElementSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
+        textData.addSource(descriptionElementSource);
+
+
+        CdmStore.getService(ITaxonNodeService.class).merge(taxonNode);
+
+        description.getId();
+    }
+
+
+    @Test
+    public void addTaxonNodeCascadeProblem() {
+        UUID taxonNodeUuid = UUID.fromString("ce54c396-3694-47f2-abb0-1d7b7e057985");
+
+        TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
+        Taxon childTaxon = Taxon.NewInstance(null, null);
+        TaxonNode childTaxonNode = taxonNode.addChildTaxon(childTaxon, null, null);
+        Taxon grandChildTaxon = Taxon.NewInstance(null, null);
+        TaxonNode grandChildTaxonNode = childTaxonNode.addChildTaxon(grandChildTaxon, null, null);
+
+        CdmStore.getService(ITaxonNodeService.class).merge(grandChildTaxonNode,true);
+
+        Assert.assertEquals(taxonNode.getChildNodes().get(0).getId(), childTaxonNode.getId());
+
+        Assert.assertTrue(childTaxonNode.treeIndex() != null);
+        Assert.assertEquals(taxonNode.getChildNodes().get(0).treeIndex(), childTaxonNode.treeIndex());
+        Assert.assertFalse(childTaxon.getId() == 0);
+        Assert.assertEquals(taxonNode.getChildNodes().get(0).getTaxon().getId(), childTaxon.getId());
+
+        Assert.assertTrue(grandChildTaxonNode.treeIndex() != null);
+        Assert.assertEquals(taxonNode.getChildNodes().get(0).getChildNodes().get(0).getId(), grandChildTaxonNode.getId());
+        Assert.assertFalse(grandChildTaxon.getId() == 0);
+        Assert.assertEquals(taxonNode.getChildNodes().get(0).getChildNodes().get(0).getTaxon().getId(), grandChildTaxon.getId());
+    }
+
 }