Project

General

Profile

Download (3.4 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.store.operations;
12

    
13
import static org.junit.Assert.fail;
14
import junit.framework.Assert;
15

    
16
import org.apache.log4j.Logger;
17
import org.eclipse.core.commands.ExecutionException;
18
import org.eclipse.core.commands.operations.IUndoContext;
19
import org.junit.BeforeClass;
20
import org.junit.Test;
21

    
22
import eu.etaxonomy.cdm.model.common.CdmBase;
23
import eu.etaxonomy.cdm.model.name.NonViralName;
24
import eu.etaxonomy.cdm.model.taxon.Synonym;
25
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
26
import eu.etaxonomy.cdm.model.taxon.Taxon;
27

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

    
37
	private static AbstractPostOperation operation;
38

    
39
	private static Taxon taxon;
40

    
41
	private static Synonym synonym;
42

    
43
	private static SynonymRelationshipType synonymRelationshipType;
44

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

    
61
	/**
62
	 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.ChangeSynonymToTaxonOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
63
	 * @throws ExecutionException 
64
	 */
65
	@Test
66
	public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
67
		operation.execute(null, null);
68
		
69
		Assert.assertTrue("Synonym should be deleted from taxon", taxon.getSynonyms().size() == 0);
70
	}
71
	
72
	/**
73
	 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.ChangeSynonymToTaxonOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
74
	 * @throws ExecutionException 
75
	 */
76
	@Test
77
	public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
78
		operation.undo(null, null);
79
		
80
		Assert.assertTrue("Taxon should have a synonym.", taxon.getSynonyms().size() > 0);
81
		Assert.assertEquals("Synonym is not the expexted.", synonym, taxon.getSynonyms().toArray(new Synonym[0])[0]);
82
	}
83
	
84
	/**
85
	 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.ChangeSynonymToTaxonOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
86
	 * @throws ExecutionException 
87
	 */
88
	@Test
89
	public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
90
		operation.redo(null, null);
91
		
92
		Assert.assertTrue("Synonym should be deleted from taxon", taxon.getSynonyms().size() == 0);
93
	}
94

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