Project

General

Profile

Download (4.21 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.INonViralName;
22
import eu.etaxonomy.cdm.model.name.TaxonName;
23
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
24
import eu.etaxonomy.cdm.model.taxon.Synonym;
25
import eu.etaxonomy.cdm.model.taxon.Taxon;
26
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
27
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation;
28
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
29
import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTestBase;
30

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

    
44
	private static AbstractPostOperation operation;
45

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

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

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

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