Project

General

Profile

Download (4.1 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

    
10
package eu.etaxonomy.taxeditor.editor.name.operation;
11

    
12
import junit.framework.Assert;
13

    
14
import org.apache.log4j.Logger;
15
import org.eclipse.core.commands.ExecutionException;
16
import org.junit.BeforeClass;
17
import org.junit.Test;
18

    
19
import eu.etaxonomy.cdm.model.common.ICdmBase;
20
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
21
import eu.etaxonomy.cdm.model.name.NonViralName;
22
import eu.etaxonomy.cdm.model.taxon.Synonym;
23
import eu.etaxonomy.cdm.model.taxon.Taxon;
24
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
25
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation;
26
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
27
import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTestBase;
28

    
29
/**
30
 * @author n.hoffmann
31
 * @created 07.04.2009
32
 * @version 1.0
33
 */
34
public class ChangeConceptToSynonymOperationTest extends AbstractTaxeditorOperationTestBase {
35
	private static final Logger logger = Logger
36
			.getLogger(ChangeConceptToSynonymOperationTest.class);
37
	
38
	private static Taxon taxon;
39
	
40
	private static Taxon concept;
41

    
42
	private static AbstractPostOperation operation;
43

    
44
	private static HomotypicalGroup homotypicalGroup;
45
	
46
	private Synonym[] synonymType = new Synonym[0];
47
	private Taxon[] taxonType = new Taxon[0];
48
	
49
	/**
50
	 * @throws java.lang.Exception
51
	 */
52
	@BeforeClass
53
	public static void setUpBeforeClass() throws Exception {
54
		taxon = Taxon.NewInstance(null, null);
55
		concept = Taxon.NewInstance(NonViralName.NewInstance(null), null);
56
		homotypicalGroup = HomotypicalGroup.NewInstance();
57
		
58
		concept.addTaxonRelation(taxon, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), null, null);
59
		
60
		operation = new ChangeConceptToSynonymOperation("Change misapplication to synonym", null, taxon, concept, homotypicalGroup, postOperation);
61
	}
62

    
63
	/**
64
	 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
65
	 * @throws ExecutionException 
66
	 */
67
	@Test
68
	public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
69
		operation.execute(null, null);
70
		
71
		Assert.assertTrue(taxon.getSynonyms().size() == 1);
72
		Assert.assertTrue(concept.getRelationsFromThisTaxon().size() == 0);
73
		Assert.assertEquals(concept.getName(), taxon.getSynonyms().toArray(synonymType)[0].getName());
74
		
75
	}
76

    
77
	/**
78
	 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
79
	 * @throws ExecutionException 
80
	 */
81
	@Test
82
	public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
83
		operation.undo(null, null);
84
		
85
		Assert.assertTrue("There shouldn't be synonyms after undo operations", taxon.getSynonyms().size() == 0);
86
		Assert.assertTrue(concept.getRelationsFromThisTaxon().size() > 0);
87
		Assert.assertEquals(taxon, concept.getRelationsFromThisTaxon().toArray(taxonType)[0]);
88
	}
89
	
90
	/**
91
	 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
92
	 * @throws ExecutionException 
93
	 */
94
	@Test
95
	public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
96
		operation.redo(null, null);
97
		
98
		Assert.assertTrue(taxon.getSynonyms().size() == 1);
99
		Assert.assertTrue(concept.getRelationsFromThisTaxon().size() == 0);
100
		Assert.assertEquals(concept.getName(), taxon.getSynonyms().toArray(synonymType)[0].getName());
101
	}
102

    
103
	/**
104
	 * Test method for {@link eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation#postExecute(ICdmBase)}.
105
	 */
106
	@Test
107
	public void testPostExecute() {
108
		// TODO there is not post operation functionality for this class
109
		// at the moment. Implement test when there is.
110
		logger.warn("No post operation functionality for this class");
111
	}
112
}
(2-2/16)