Move MoveTaxonOperationTest to navigation package and try to enable
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / test / java / eu / etaxonomy / taxeditor / navigation / navigator / operation / MoveTaxonOperationTest.java
diff --git a/eu.etaxonomy.taxeditor.navigation/src/test/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/MoveTaxonOperationTest.java b/eu.etaxonomy.taxeditor.navigation/src/test/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/MoveTaxonOperationTest.java
new file mode 100644 (file)
index 0000000..9624b0e
--- /dev/null
@@ -0,0 +1,108 @@
+/**
+* Copyright (C) 2007 EDIT
+* 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.navigation.navigator.operation;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.navigation.navigator.TreeNodeDropAdapter.MovingType;
+import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTestBase;
+
+/**
+ * @author n.hoffmann
+ * @created 08.04.2009
+ */
+public class MoveTaxonOperationTest extends AbstractTaxeditorOperationTestBase {
+
+       private static Taxon oldParentTaxon;
+       private static Taxon newParentTaxon;
+       private static Classification tree;
+       private static TaxonNode oldParentTaxonNode;
+       private static TaxonNode newParentTaxonNode;
+       private static TaxonNode taxonNode;
+       
+       /**
+        * @throws java.lang.Exception
+        */
+       @BeforeClass
+       public static void setUpBeforeClass() throws Exception {
+
+               
+               taxon = Taxon.NewInstance(null, null);
+
+               oldParentTaxon = Taxon.NewInstance(null, null);
+               newParentTaxon = Taxon.NewInstance(null, null);
+               
+               tree = Classification.NewInstance(null);
+               oldParentTaxonNode = tree.addChildTaxon(oldParentTaxon, null, null);
+               newParentTaxonNode = tree.addChildTaxon(newParentTaxon, null, null);
+               
+               taxonNode = oldParentTaxonNode.addChildTaxon(taxon, null, null);
+               
+               Set<UUID> taxonNodeUuidSet = new HashSet<UUID>();
+               //TODO ??
+               IConversationEnabled conversationEnabled = null;
+               taxonNodeUuidSet.add(taxonNode.getUuid());
+               operation = new MoveTaxonOperation("Move Taxon To Different Parent", 
+                               undoContext, taxonNodeUuidSet, newParentTaxonNode, postOperation, 
+                               conversationEnabled, MovingType.CHILD);
+       }
+
+       /**
+        * Test method for {@link eu.etaxonomy.taxeditor.navigation.operation.MoveTaxonOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
+        * @throws ExecutionException 
+        */
+       @Test
+       public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
+               operation.execute(monitor, info);
+               
+               Assert.assertEquals(newParentTaxon ,taxon.getTaxonNodes().iterator().next().getParent().getTaxon());
+               Assert.assertEquals(taxon, newParentTaxon.getTaxonNodes().iterator().next().getChildNodes().iterator().next());
+               Assert.assertEquals(0, oldParentTaxon.getTaxonNodes().iterator().next().getChildNodes().size());
+       }
+
+
+       /**
+        * Test method for {@link eu.etaxonomy.taxeditor.navigation.operation.MoveTaxonOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
+        * @throws ExecutionException 
+        */
+       @Test
+       public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
+               operation.undo(monitor, info);
+               
+               Assert.assertEquals(oldParentTaxon ,taxon.getTaxonNodes().iterator().next().getParent().getTaxon());
+               Assert.assertEquals(0, newParentTaxon.getTaxonNodes().iterator().next().getChildNodes().size());
+               Assert.assertEquals(taxon, oldParentTaxon.getTaxonNodes().iterator().next().getChildNodes().iterator().next());
+       }
+       
+       /**
+        * Test method for {@link eu.etaxonomy.taxeditor.navigation.operation.MoveTaxonOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
+        * @throws ExecutionException 
+        */
+       @Test
+       public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
+               operation.redo(monitor, info);
+               
+               Assert.assertEquals(newParentTaxon ,taxon.getTaxonNodes().iterator().next().getParent().getTaxon());
+               Assert.assertEquals(taxon, newParentTaxon.getTaxonNodes().iterator().next().getChildNodes().iterator().next());
+               Assert.assertEquals(0, oldParentTaxon.getTaxonNodes().iterator().next().getChildNodes().size());
+
+       }
+}