Project

General

Profile

Download (4.42 KB) Statistics
| Branch: | Tag: | Revision:
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.apache.log4j.Logger;
14
import org.eclipse.core.commands.ExecutionException;
15
import org.junit.Assert;
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.NonViralName;
21
import eu.etaxonomy.cdm.model.taxon.Synonym;
22
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
23
import eu.etaxonomy.cdm.model.taxon.Taxon;
24
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToMisapplicationOperation;
25
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
26
import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTest;
27

    
28
/**
29
 * @author n.hoffmann
30
 * @created 07.04.2009
31
 * @version 1.0
32
 */
33
public class ChangeSynonymToMisapplicationOperationTest extends AbstractTaxeditorOperationTest {
34
	private static final Logger logger = Logger
35
			.getLogger(ChangeSynonymToMisapplicationOperationTest.class);
36

    
37
	private static Synonym synonym;
38

    
39
	private static Taxon taxon;
40

    
41
	private static AbstractPostOperation operation;
42

    
43
	private static SynonymRelationshipType synonymRelationshipType;
44
	
45
	/**
46
	 * @throws java.lang.Exception
47
	 */
48
	@BeforeClass
49
	public static void setUpBeforeClass() throws Exception {
50
		taxon = Taxon.NewInstance(null, null);
51
		synonym = Synonym.NewInstance(NonViralName.NewInstance(null), null);
52
		synonymRelationshipType = SynonymRelationshipType.SYNONYM_OF();
53
		taxon.addSynonym(synonym, synonymRelationshipType);
54
		
55
		operation = new ChangeSynonymToMisapplicationOperation("Change Synonym To Misapplication", null, taxon, synonym, postOperation);
56
	}
57

    
58
	/**
59
	 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToMisapplicationOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
60
	 * @throws ExecutionException 
61
	 */
62
	@Test
63
	public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
64
		operation.execute(null, null);
65
		
66
		Assert.assertTrue("Synonym should be deleted from taxon", taxon.getSynonyms().size() == 0);
67
		Assert.assertTrue("Taxon should have misapplications", taxon.getMisappliedNames().size() > 0);
68
		Assert.assertEquals("The name of synonym and misapplication should be equal", synonym.getName(), taxon.getMisappliedNames().toArray(new Taxon[0])[0].getName());
69
	}
70

    
71
	/**
72
	 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToMisapplicationOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
73
	 * @throws ExecutionException 
74
	 */
75
	@Test
76
	public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
77
		operation.undo(null, null);
78
		
79
		Assert.assertTrue("Taxon should have synonyms.", taxon.getSynonyms().size() > 0);
80
		Assert.assertTrue("Taxon should not have taxon relationship.", taxon.getTaxonRelations().size() == 0);
81
		Assert.assertEquals("Not the expected synonym.", synonym, taxon.getSynonyms().toArray(new Synonym[0])[0]);
82
		Assert.assertEquals("SynonymRelationshipType is not the expected.", synonymRelationshipType, taxon.getSynonyms().toArray(new Synonym[0])[0].getRelationType(taxon));
83
	}
84
	
85
	/**
86
	 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToMisapplicationOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
87
	 * @throws ExecutionException 
88
	 */
89
	@Test
90
	public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
91
		operation.redo(null, null);
92

    
93
		Assert.assertTrue("Synonym should be deleted from taxon", taxon.getSynonyms().size() == 0);
94
		Assert.assertTrue("Taxon should have misapplications", taxon.getMisappliedNames().size() > 0);
95
		Assert.assertEquals("The name of synonym and misapplication should be equal", synonym.getName(), taxon.getMisappliedNames().toArray(new Taxon[0])[0].getName());
96
	}
97

    
98
	/**
99
	 * Test method for {@link eu.etaxonomy.taxeditor.operation.AbstractPostOperation#postExecute(ICdmBase)}.
100
	 */
101
	@Test
102
	public void testPostExecute() {
103
		// TODO there is not post operation functionality for this class
104
		// at the moment. Implement test when there is.
105
		logger.warn("No post operation functionality for this class");
106
	}
107
}
(7-7/17)