Project

General

Profile

Download (3.77 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
10

    
11
import java.util.HashSet;
12
import java.util.Set;
13
import java.util.UUID;
14

    
15
import org.eclipse.core.commands.ExecutionException;
16
import org.junit.Assert;
17
import org.junit.BeforeClass;
18
import org.junit.Test;
19

    
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;
26

    
27
/**
28
 * @author n.hoffmann
29
 * @created 08.04.2009
30
 */
31
public class MoveTaxonOperationTest extends AbstractTaxeditorOperationTestBase {
32

    
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;
39

    
40
	static RemotingCdmUpdateOperation navigatorOperation;
41

    
42
	@BeforeClass
43
	public static void setUpBeforeClass() throws Exception {
44

    
45
		taxon = Taxon.NewInstance(null, null);
46

    
47
		oldParentTaxon = Taxon.NewInstance(null, null);
48
		newParentTaxon = Taxon.NewInstance(null, null);
49

    
50
		tree = Classification.NewInstance(null);
51
		oldParentTaxonNode = tree.addChildTaxon(oldParentTaxon, null, null);
52
		newParentTaxonNode = tree.addChildTaxon(newParentTaxon, null, null);
53

    
54
		taxonNode = oldParentTaxonNode.addChildTaxon(taxon, null, null);
55

    
56
		Set<UUID> taxonNodeUuidSet = new HashSet<>();
57
		//TODO ??
58
		taxonNodeUuidSet.add(taxonNode.getUuid());
59
		navigatorOperation = new RemotingMoveTaxonOperation(null, true, taxonNodeUuidSet, newParentTaxonNode.getUuid(),  MovingType.CHILD);
60
	}
61

    
62
	/**
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
65
	 */
66
	@Test
67
	public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
68
	    navigatorOperation.execute(monitor, info);
69

    
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());
73
	}
74

    
75

    
76
	/**
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
79
	 */
80
	@Test
81
	public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
82
	    navigatorOperation.undo(monitor, info);
83

    
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());
87
	}
88

    
89
	@Test
90
	public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
91
	    navigatorOperation.redo(monitor, info);
92

    
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());
96
	}
97
}
    (1-1/1)