Project

General

Profile

Download (4.22 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 org.apache.log4j.Logger;
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.common.ICdmBase;
19
import eu.etaxonomy.cdm.model.name.NonViralName;
20
import eu.etaxonomy.cdm.model.taxon.Synonym;
21
import eu.etaxonomy.cdm.model.taxon.SynonymType;
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
24
import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTestBase;
25

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

    
35
	private static Synonym synonym;
36

    
37
	private static Taxon taxon;
38

    
39
	private static AbstractPostOperation operation;
40

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

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

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

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

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