Project

General

Profile

« Previous | Next » 

Revision 0d726c87

Added by Andreas Müller over 7 years ago

Move MoveTaxonOperationTest to navigation package and try to enable

View differences:

eu.etaxonomy.taxeditor.editor/src/test/java/eu/etaxonomy/taxeditor/editor/name/operation/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.editor.name.operation;
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.Classification;
19
import eu.etaxonomy.cdm.model.taxon.Taxon;
20
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
21
import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTestBase;
22

  
23
/**
24
 * @author n.hoffmann
25
 * @created 08.04.2009
26
 * @version 1.0
27
 */
28
public class MoveTaxonOperationTest extends AbstractTaxeditorOperationTestBase {
29

  
30
	private static Taxon oldParentTaxon;
31
	private static Taxon newParentTaxon;
32
	private static Classification tree;
33
	private static TaxonNode oldParentTaxonNode;
34
	private static TaxonNode newParentTaxonNode;
35
	private static TaxonNode taxonNode;
36
	
37
	/**
38
	 * @throws java.lang.Exception
39
	 */
40
	@BeforeClass
41
	public static void setUpBeforeClass() throws Exception {
42

  
43
		
44
		taxon = Taxon.NewInstance(null, null);
45
		
46
		
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
		operation = null;//new MoveTaxonOperation("Move Taxon To Different Parent", undoContext, taxonNode, newParentTaxonNode, postOperation);
58
	}
59

  
60
	/**
61
	 * Test method for {@link eu.etaxonomy.taxeditor.navigation.operation.MoveTaxonOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
62
	 * @throws ExecutionException 
63
	 */
64
	@Test
65
	public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
66
		operation.execute(monitor, info);
67
		
68
		Assert.assertEquals(newParentTaxon ,taxon.getTaxonNodes().iterator().next().getParent().getTaxon());
69
		Assert.assertEquals(taxon, newParentTaxon.getTaxonNodes().iterator().next().getChildNodes().iterator().next());
70
		Assert.assertEquals(0, oldParentTaxon.getTaxonNodes().iterator().next().getChildNodes().size());
71
	}
72

  
73

  
74
	/**
75
	 * Test method for {@link eu.etaxonomy.taxeditor.navigation.operation.MoveTaxonOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
76
	 * @throws ExecutionException 
77
	 */
78
	@Test
79
	public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
80
		operation.undo(monitor, info);
81
		
82
//		Assert.assertEquals(oldParentTaxon ,taxon.getTaxonomicParent());
83
//		Assert.assertTrue(newParentTaxon.getTaxonomicChildren().size() == 0);
84
//		Assert.assertEquals(taxon, oldParentTaxon.getTaxonomicChildren().toArray(new Taxon[0])[0]);
85

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

  
90
	
91
	}
92
	
93
	/**
94
	 * Test method for {@link eu.etaxonomy.taxeditor.navigation.operation.MoveTaxonOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
95
	 * @throws ExecutionException 
96
	 */
97
	@Test
98
	public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
99
		operation.redo(monitor, info);
100
		
101
		Assert.assertEquals(newParentTaxon ,taxon.getTaxonNodes().iterator().next().getParent().getTaxon());
102
		Assert.assertEquals(taxon, newParentTaxon.getTaxonNodes().iterator().next().getChildNodes().iterator().next());
103
		Assert.assertEquals(0, oldParentTaxon.getTaxonNodes().iterator().next().getChildNodes().size());
104

  
105
	}
106
}
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/MoveTaxonOperation.java
60 60
	 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
61 61
	 */
62 62
	public MoveTaxonOperation(String label, IUndoContext undoContext,
63
			Set<UUID> taxonNodesUUIDToMove, ITaxonTreeNode newParentTreeNode, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled, MovingType moveToParentNode) {
63
			Set<UUID> taxonNodesUUIDToMove, ITaxonTreeNode newParentTreeNode, 
64
			IPostOperationEnabled postOperationEnabled, 
65
			IConversationEnabled conversationEnabled, MovingType moveToParentNode) {
64 66
		super(label, undoContext, postOperationEnabled, conversationEnabled);
65 67

  
66 68
		this.taxonNodesUuid = taxonNodesUUIDToMove;
eu.etaxonomy.taxeditor.navigation/src/test/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/MoveTaxonOperationTest.java
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

  
10
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
11

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

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

  
21
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
22
import eu.etaxonomy.cdm.model.taxon.Classification;
23
import eu.etaxonomy.cdm.model.taxon.Taxon;
24
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
25
import eu.etaxonomy.taxeditor.navigation.navigator.TreeNodeDropAdapter.MovingType;
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
	/**
42
	 * @throws java.lang.Exception
43
	 */
44
	@BeforeClass
45
	public static void setUpBeforeClass() throws Exception {
46

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

  
50
		oldParentTaxon = Taxon.NewInstance(null, null);
51
		newParentTaxon = Taxon.NewInstance(null, null);
52
		
53
		tree = Classification.NewInstance(null);
54
		oldParentTaxonNode = tree.addChildTaxon(oldParentTaxon, null, null);
55
		newParentTaxonNode = tree.addChildTaxon(newParentTaxon, null, null);
56
		
57
		taxonNode = oldParentTaxonNode.addChildTaxon(taxon, null, null);
58
		
59
		Set<UUID> taxonNodeUuidSet = new HashSet<UUID>();
60
		//TODO ??
61
		IConversationEnabled conversationEnabled = null;
62
		taxonNodeUuidSet.add(taxonNode.getUuid());
63
		operation = new MoveTaxonOperation("Move Taxon To Different Parent", 
64
				undoContext, taxonNodeUuidSet, newParentTaxonNode, postOperation, 
65
				conversationEnabled, MovingType.CHILD);
66
	}
67

  
68
	/**
69
	 * Test method for {@link eu.etaxonomy.taxeditor.navigation.operation.MoveTaxonOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
70
	 * @throws ExecutionException 
71
	 */
72
	@Test
73
	public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
74
		operation.execute(monitor, info);
75
		
76
		Assert.assertEquals(newParentTaxon ,taxon.getTaxonNodes().iterator().next().getParent().getTaxon());
77
		Assert.assertEquals(taxon, newParentTaxon.getTaxonNodes().iterator().next().getChildNodes().iterator().next());
78
		Assert.assertEquals(0, oldParentTaxon.getTaxonNodes().iterator().next().getChildNodes().size());
79
	}
80

  
81

  
82
	/**
83
	 * Test method for {@link eu.etaxonomy.taxeditor.navigation.operation.MoveTaxonOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
84
	 * @throws ExecutionException 
85
	 */
86
	@Test
87
	public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
88
		operation.undo(monitor, info);
89
		
90
		Assert.assertEquals(oldParentTaxon ,taxon.getTaxonNodes().iterator().next().getParent().getTaxon());
91
		Assert.assertEquals(0, newParentTaxon.getTaxonNodes().iterator().next().getChildNodes().size());
92
		Assert.assertEquals(taxon, oldParentTaxon.getTaxonNodes().iterator().next().getChildNodes().iterator().next());
93
	}
94
	
95
	/**
96
	 * Test method for {@link eu.etaxonomy.taxeditor.navigation.operation.MoveTaxonOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
97
	 * @throws ExecutionException 
98
	 */
99
	@Test
100
	public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
101
		operation.redo(monitor, info);
102
		
103
		Assert.assertEquals(newParentTaxon ,taxon.getTaxonNodes().iterator().next().getParent().getTaxon());
104
		Assert.assertEquals(taxon, newParentTaxon.getTaxonNodes().iterator().next().getChildNodes().iterator().next());
105
		Assert.assertEquals(0, oldParentTaxon.getTaxonNodes().iterator().next().getChildNodes().size());
106

  
107
	}
108
}

Also available in: Unified diff