3409912bb81734d93cfc997c1cb98c36dc8ceb2f
[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 org.eclipse.core.commands.ExecutionException;
14 import org.junit.Assert;
15 import org.junit.BeforeClass;
16 import org.junit.Test;
17
18 import eu.etaxonomy.cdm.model.taxon.Taxon;
19
20 /**
21 * @author n.hoffmann
22 * @created 08.04.2009
23 * @version 1.0
24 */
25 public class MoveTaxonOperationTest extends AbstractTaxeditorOperationTest {
26
27 private static Taxon oldParentTaxon;
28 private static Taxon newParentTaxon;
29
30 /**
31 * @throws java.lang.Exception
32 */
33 @BeforeClass
34 public static void setUpBeforeClass() throws Exception {
35 taxon = Taxon.NewInstance(null, null);
36 oldParentTaxon = Taxon.NewInstance(null, null);
37 newParentTaxon = Taxon.NewInstance(null, null);
38 // oldParentTaxon.addTaxonomicChild(taxon, null, null);
39 taxon.setTaxonomicParent(oldParentTaxon, null, null);
40
41 operation = new MoveTaxonOperation("Move Taxon To Different Parent", undoContext, taxon, newParentTaxon);
42 }
43
44 /**
45 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.MoveTaxonOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
46 * @throws ExecutionException
47 */
48 @Test
49 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
50 operation.execute(monitor, info);
51
52 Assert.assertEquals(newParentTaxon ,taxon.getTaxonomicParent());
53 Assert.assertEquals(taxon, newParentTaxon.getTaxonomicChildren().toArray(new Taxon[0])[0]);
54 Assert.assertTrue(oldParentTaxon.getTaxonomicChildrenCount() == 0);
55 }
56
57
58 /**
59 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.MoveTaxonOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
60 * @throws ExecutionException
61 */
62 @Test
63 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
64 operation.undo(monitor, info);
65
66 Assert.assertEquals(oldParentTaxon ,taxon.getTaxonomicParent());
67 Assert.assertTrue(newParentTaxon.getTaxonomicChildren().size() == 0);
68 Assert.assertEquals(taxon, oldParentTaxon.getTaxonomicChildren().toArray(new Taxon[0])[0]);
69 }
70
71 /**
72 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.MoveTaxonOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
73 * @throws ExecutionException
74 */
75 @Test
76 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
77 operation.redo(monitor, info);
78
79 Assert.assertEquals(newParentTaxon ,taxon.getTaxonomicParent());
80 Assert.assertEquals(taxon, newParentTaxon.getTaxonomicChildren().toArray(new Taxon[0])[0]);
81 Assert.assertTrue(oldParentTaxon.getTaxonomicChildrenCount() == 0);
82 }
83 }