2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
;
11 import java
.util
.HashSet
;
13 import java
.util
.UUID
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.junit
.Assert
;
17 import org
.junit
.BeforeClass
;
18 import org
.junit
.Test
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
23 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.e4
.TreeNodeDropAdapterE4
.MovingType
;
24 import eu
.etaxonomy
.taxeditor
.operation
.RemotingCdmUpdateOperation
;
25 import eu
.etaxonomy
.taxeditor
.store
.operations
.AbstractTaxeditorOperationTestBase
;
31 public class MoveTaxonOperationTest
extends AbstractTaxeditorOperationTestBase
{
33 private static Taxon oldParentTaxon
;
34 private static Taxon newParentTaxon
;
35 private static Classification tree
;
36 private static TaxonNode oldParentTaxonNode
;
37 private static TaxonNode newParentTaxonNode
;
38 private static TaxonNode taxonNode
;
40 static RemotingCdmUpdateOperation navigatorOperation
;
43 public static void setUpBeforeClass() throws Exception
{
45 taxon
= Taxon
.NewInstance(null, null);
47 oldParentTaxon
= Taxon
.NewInstance(null, null);
48 newParentTaxon
= Taxon
.NewInstance(null, null);
50 tree
= Classification
.NewInstance(null);
51 oldParentTaxonNode
= tree
.addChildTaxon(oldParentTaxon
, null, null);
52 newParentTaxonNode
= tree
.addChildTaxon(newParentTaxon
, null, null);
54 taxonNode
= oldParentTaxonNode
.addChildTaxon(taxon
, null, null);
56 Set
<UUID
> taxonNodeUuidSet
= new HashSet
<>();
58 taxonNodeUuidSet
.add(taxonNode
.getUuid());
59 navigatorOperation
= new RemotingMoveTaxonOperation(null, true, taxonNodeUuidSet
, newParentTaxonNode
.getUuid(), MovingType
.CHILD
);
63 * Test method for {@link eu.etaxonomy.taxeditor.navigation.operation.MoveTaxonOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
64 * @throws ExecutionException
67 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException
{
68 navigatorOperation
.execute(monitor
, info
);
70 Assert
.assertEquals(newParentTaxon
,taxon
.getTaxonNodes().iterator().next().getParent().getTaxon());
71 Assert
.assertEquals(taxon
, newParentTaxon
.getTaxonNodes().iterator().next().getChildNodes().iterator().next());
72 Assert
.assertEquals(0, oldParentTaxon
.getTaxonNodes().iterator().next().getChildNodes().size());
77 * Test method for {@link eu.etaxonomy.taxeditor.navigation.operation.MoveTaxonOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
78 * @throws ExecutionException
81 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException
{
82 navigatorOperation
.undo(monitor
, info
);
84 Assert
.assertEquals(oldParentTaxon
,taxon
.getTaxonNodes().iterator().next().getParent().getTaxon());
85 Assert
.assertEquals(0, newParentTaxon
.getTaxonNodes().iterator().next().getChildNodes().size());
86 Assert
.assertEquals(taxon
, oldParentTaxon
.getTaxonNodes().iterator().next().getChildNodes().iterator().next());
90 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException
{
91 navigatorOperation
.redo(monitor
, info
);
93 Assert
.assertEquals(newParentTaxon
,taxon
.getTaxonNodes().iterator().next().getParent().getTaxon());
94 Assert
.assertEquals(taxon
, newParentTaxon
.getTaxonNodes().iterator().next().getChildNodes().iterator().next());
95 Assert
.assertEquals(0, oldParentTaxon
.getTaxonNodes().iterator().next().getChildNodes().size());