Moving editor sources back into trunk
[taxeditor.git] / taxeditor-store / src / test / java / eu / etaxonomy / taxeditor / store / operations / MoveTaxonOperationTest.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.store.operations;
12
13 import static org.junit.Assert.*;
14
15 import org.apache.log4j.Logger;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.core.commands.operations.IUndoContext;
18 import org.eclipse.core.runtime.IAdaptable;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.junit.Assert;
21 import org.junit.BeforeClass;
22 import org.junit.Test;
23
24 import eu.etaxonomy.cdm.model.common.CdmBase;
25 import eu.etaxonomy.cdm.model.taxon.Taxon;
26
27 /**
28 * @author n.hoffmann
29 * @created 08.04.2009
30 * @version 1.0
31 */
32 public class MoveTaxonOperationTest extends AbstractTaxeditorOperationTest {
33 private static final Logger logger = Logger
34 .getLogger(MoveTaxonOperationTest.class);
35
36 private static Taxon oldParentTaxon;
37 private static Taxon newParentTaxon;
38
39 /**
40 * @throws java.lang.Exception
41 */
42 @BeforeClass
43 public static void setUpBeforeClass() throws Exception {
44 taxon = Taxon.NewInstance(null, null);
45 oldParentTaxon = Taxon.NewInstance(null, null);
46 newParentTaxon = Taxon.NewInstance(null, null);
47 // oldParentTaxon.addTaxonomicChild(taxon, null, null);
48 taxon.setTaxonomicParent(oldParentTaxon, null, null);
49
50 operation = new MoveTaxonOperation("Move Taxon To Different Parent", undoContext, taxon, newParentTaxon);
51 }
52
53 /**
54 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.MoveTaxonOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
55 * @throws ExecutionException
56 */
57 @Test
58 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
59 operation.execute(monitor, info);
60
61 Assert.assertEquals(newParentTaxon ,taxon.getTaxonomicParent());
62 Assert.assertEquals(taxon, newParentTaxon.getTaxonomicChildren().toArray(new Taxon[0])[0]);
63 Assert.assertTrue(oldParentTaxon.getTaxonomicChildrenCount() == 0);
64 }
65
66
67 /**
68 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.MoveTaxonOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
69 * @throws ExecutionException
70 */
71 @Test
72 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
73 operation.undo(monitor, info);
74
75 Assert.assertEquals(oldParentTaxon ,taxon.getTaxonomicParent());
76 Assert.assertTrue(newParentTaxon.getTaxonomicChildren().size() == 0);
77 Assert.assertEquals(taxon, oldParentTaxon.getTaxonomicChildren().toArray(new Taxon[0])[0]);
78 }
79
80 /**
81 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.MoveTaxonOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
82 * @throws ExecutionException
83 */
84 @Test
85 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
86 operation.redo(monitor, info);
87
88 Assert.assertEquals(newParentTaxon ,taxon.getTaxonomicParent());
89 Assert.assertEquals(taxon, newParentTaxon.getTaxonomicChildren().toArray(new Taxon[0])[0]);
90 Assert.assertTrue(oldParentTaxon.getTaxonomicChildrenCount() == 0);
91 }
92 }