Project

General

Profile

Download (3.85 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.metadata.SecReferenceHandlingEnum;
21
import eu.etaxonomy.cdm.model.taxon.Classification;
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
24
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TreeNodeDropAdapterE4.MovingType;
25
import eu.etaxonomy.taxeditor.operation.CdmUpdateOperation;
26
import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTestBase;
27

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

    
34
	private static Taxon oldParentTaxon;
35
	private static Taxon newParentTaxon;
36
	private static Classification tree;
37
	private static TaxonNode oldParentTaxonNode;
38
	private static TaxonNode newParentTaxonNode;
39
	private static TaxonNode taxonNode;
40

    
41
	static CdmUpdateOperation navigatorOperation;
42

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

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

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

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

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

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

    
63
	/**
64
	 * Test method for {@link eu.etaxonomy.taxeditor.navigation.operation.MoveTaxonOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
65
	 * @throws ExecutionException
66
	 */
67
	@Test
68
	public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
69
	    navigatorOperation.execute(monitor, info);
70

    
71
		Assert.assertEquals(newParentTaxon ,taxon.getTaxonNodes().iterator().next().getParent().getTaxon());
72
		Assert.assertEquals(taxon, newParentTaxon.getTaxonNodes().iterator().next().getChildNodes().iterator().next());
73
		Assert.assertEquals(0, oldParentTaxon.getTaxonNodes().iterator().next().getChildNodes().size());
74
	}
75

    
76

    
77
	/**
78
	 * Test method for {@link eu.etaxonomy.taxeditor.navigation.operation.MoveTaxonOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
79
	 * @throws ExecutionException
80
	 */
81
	@Test
82
	public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
83
	    navigatorOperation.undo(monitor, info);
84

    
85
		Assert.assertEquals(oldParentTaxon ,taxon.getTaxonNodes().iterator().next().getParent().getTaxon());
86
		Assert.assertEquals(0, newParentTaxon.getTaxonNodes().iterator().next().getChildNodes().size());
87
		Assert.assertEquals(taxon, oldParentTaxon.getTaxonNodes().iterator().next().getChildNodes().iterator().next());
88
	}
89

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

    
94
		Assert.assertEquals(newParentTaxon ,taxon.getTaxonNodes().iterator().next().getParent().getTaxon());
95
		Assert.assertEquals(taxon, newParentTaxon.getTaxonNodes().iterator().next().getChildNodes().iterator().next());
96
		Assert.assertEquals(0, oldParentTaxon.getTaxonNodes().iterator().next().getChildNodes().size());
97
	}
98
}
    (1-1/1)