Merge branch 'develop' into LibrAlign
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / test / java / eu / etaxonomy / taxeditor / editor / name / operation / SwapSynonymAndAcceptedOperationTest.java
index 37065b5d6f3d18f4f03e85ee7e2f88142703b0db..36a85811574fa0bdaf02dde2493827f68f323f2c 100644 (file)
@@ -1,18 +1,17 @@
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
 
 package eu.etaxonomy.taxeditor.editor.name.operation;
 
-import junit.framework.Assert;
-
 import org.apache.log4j.Logger;
 import org.eclipse.core.commands.ExecutionException;
+import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -22,23 +21,20 @@ import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
 import eu.etaxonomy.cdm.model.name.NonViralName;
 import eu.etaxonomy.cdm.model.taxon.Synonym;
-import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
+import eu.etaxonomy.cdm.model.taxon.SynonymType;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
-import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
-import eu.etaxonomy.taxeditor.editor.name.operation.SwapSynonymAndAcceptedOperation;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
 import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTestBase;
 
 /**
  * @author n.hoffmann
  * @created 02.04.2009
- * @version 1.0
  */
 public class SwapSynonymAndAcceptedOperationTest extends AbstractTaxeditorOperationTestBase {
        private static final Logger logger = Logger
                        .getLogger(SwapSynonymAndAcceptedOperationTest.class);
-       
+
        private static AbstractPostOperation operation;
 
        private static Taxon taxon;
@@ -65,125 +61,125 @@ public class SwapSynonymAndAcceptedOperationTest extends AbstractTaxeditorOperat
 
        private static NonViralName<?> oldTaxonName;
 
-       
+
        /**
         * @throws java.lang.Exception
         */
        @BeforeClass
        public static void setUpBeforeClass() throws Exception {
-               
+
                (new DefaultTermInitializer()).initialize();
-               
+
                // Create the original accepted taxon
                oldTaxonName = NonViralName.NewInstance(null);
                taxon = Taxon.NewInstance(oldTaxonName, null);
-               
-               // Create its parent taxon
-               parentTaxon = Taxon.NewInstance(NonViralName.NewInstance(null), null);
-               parentTaxon.addTaxonomicChild(taxon, null, null);
-
-               // Give it a child taxon
-               childTaxon = Taxon.NewInstance(NonViralName.NewInstance(null), null);
-               childTaxon.setTaxonomicParent(taxon, null, null);
-               
+
+//             // Create its parent taxon
+//             parentTaxon = Taxon.NewInstance(NonViralName.NewInstance(null), null);
+//             parentTaxon.addTaxonomicChild(taxon, null, null);
+//
+//             // Give it a child taxon
+//             childTaxon = Taxon.NewInstance(NonViralName.NewInstance(null), null);
+//             childTaxon.setTaxonomicParent(taxon, null, null);
+
                // Create a homotypic synonym for the accepted taxon
-               taxon.addHomotypicSynonymName(NonViralName.NewInstance(null), null, null);
+               taxon.addHomotypicSynonymName(NonViralName.NewInstance(null));
 //             homotypicSynonym = Synonym.NewInstance(NonViralName.NewInstance(null), null);
 //             HomotypicalGroup acceptedHomotypicalGroup = HomotypicalGroup.NewInstance();
 //             acceptedHomotypicalGroup.addTypifiedName(oldTaxon.getName());
 //             acceptedHomotypicalGroup.addTypifiedName(homotypicSynonym.getName());
-               
+
                // Create a heterotypic synonym that will be used to create the new accepted taxon
                oldSynonymName = NonViralName.NewInstance(null);
                oldHeterotypicSynonym = Synonym.NewInstance(oldSynonymName, null);
 //             oldTaxon.addS .addHeterotypicSynonym(oldHeterotypicSynonym, null, null);
                heteroypicalGroup = HomotypicalGroup.NewInstance();
                heteroypicalGroup.addTypifiedName(oldHeterotypicSynonym.getName());
-               taxon.addSynonym(oldHeterotypicSynonym, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
-               
+               taxon.addSynonym(oldHeterotypicSynonym, SynonymType.HETEROTYPIC_SYNONYM_OF());
+
                // Create a misapplication
                misapplication = Taxon.NewInstance(NonViralName.NewInstance(null), null);
-               taxon.addMisappliedName(misapplication, null, null);    
-               
+               taxon.addMisappliedName(misapplication, null, null);
+
                // Create a concept relation
                concept = Taxon.NewInstance(NonViralName.NewInstance(null), null);
                conceptRelationshipType = TaxonRelationshipType.CONGRUENT_TO();
-               concept.addTaxonRelation(taxon, conceptRelationshipType, null, null);   
-               
+               concept.addTaxonRelation(taxon, conceptRelationshipType, null, null);
+
                // Create a description
                description = TaxonDescription.NewInstance();
                taxon.addDescription(description);
-               
+
                operation = new SwapSynonymAndAcceptedOperation
-                               (null, undoContext, taxon, oldHeterotypicSynonym, postOperation);
+                               (null, undoContext, taxon, oldHeterotypicSynonym, postOperation, cdmEntitySessionEnabled);
        }
 
 
        /**
         * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
-        * @throws ExecutionException 
+        * @throws ExecutionException
         */
        @Test
        public void testExecute() throws ExecutionException {
                operation.execute(null, null);
-               
-               // New taxon has correct name?          
+
+               // New taxon has correct name?
                Assert.assertEquals(taxon.getName(), oldSynonymName);
-               
-               // New taxon has correct parent?
-               Assert.assertEquals(taxon.getTaxonomicParent(), parentTaxon);
-               
-               // New taxon has correct child?
-               Assert.assertTrue(taxon.getTaxonomicChildren().contains(childTaxon));
-               
+
+//             // New taxon has correct parent?
+//             Assert.assertEquals(taxon.getTaxonomicParent(), parentTaxon);
+//
+//             // New taxon has correct child?
+//             Assert.assertTrue(taxon.getTaxonomicChildren().contains(childTaxon));
+
                // New taxon has 2 synonyms?
                Assert.assertEquals(taxon.getSynonyms().size(), 2);
-               
+
                // New taxon has a synonym with the name of the previous accepted taxon?
                Assert.assertTrue(taxon.getSynonymNames().contains(oldTaxonName));
-               
+
                // New taxon has misapplication?
                Assert.assertTrue(taxon.getMisappliedNames().contains(misapplication));
-               
-               // New taxon has 1 concept relation?
-               int conceptRelCount = 0;
-               for (TaxonRelationship relation : taxon.getTaxonRelations()) {
-                       if (relation.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR()) ||
-                                       relation.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())) {
-                               continue;
-                       }
-                       conceptRelCount++;
-               }
-               Assert.assertEquals(conceptRelCount, 1);
-               
+
+//             // New taxon has 1 concept relation?
+//             int conceptRelCount = 0;
+//             for (TaxonRelationship relation : taxon.getTaxonRelations()) {
+//                     if (relation.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR()) ||
+//                                     relation.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())) {
+//                             continue;
+//                     }
+//                     conceptRelCount++;
+//             }
+//             Assert.assertEquals(conceptRelCount, 1);
+
                // New taxon has description?
                taxon.getDescriptions().contains(description);
        }
 
        /**
         * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
-        * @throws ExecutionException 
+        * @throws ExecutionException
         */
        @Test
        public void testUndo() throws ExecutionException {
                operation.undo(null, null);
-               
+
 //             Assert.assertEquals(oldHomotypicalGroup, synonym.getHomotypicGroup());
        }
-       
+
        /**
         * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
-        * @throws ExecutionException 
+        * @throws ExecutionException
         */
        @Test
        public void testRedo() throws ExecutionException {
                operation.redo(null, null);
-               
+
 //             Assert.assertEquals(newHomotypicalGroup, synonym.getHomotypicGroup());
        }
 
        /**
-        * Test method for {@link eu.etaxonomy.taxeditor.operation.AbstractPostOperation#postExecute(ICdmBase)}.
+        * Test method for {@link eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation#postExecute(ICdmBase)}.
         */
        @Test
        public void testPostExecute() {