Project

General

Profile

Download (4.72 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.name.TaxonNameBase;
21
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
22
import eu.etaxonomy.cdm.model.taxon.Synonym;
23
import eu.etaxonomy.cdm.model.taxon.SynonymType;
24
import eu.etaxonomy.cdm.model.taxon.Taxon;
25
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
26
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
27
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation;
28
import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTestBase;
29

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

    
39
	private static TaxonRelationshipType taxonRelationshipType;
40

    
41
	private static Synonym synonym;
42

    
43
	
44
	/**
45
	 * @throws java.lang.Exception
46
	 */
47
	@BeforeClass
48
	public static void setUpBeforeClass() throws Exception {
49
		
50
		taxon = Taxon.NewInstance(null, null);
51
		synonym = Synonym.NewInstance(TaxonNameFactory.NewNonViralInstance(null), null);
52
		taxonRelationshipType = TaxonRelationshipType.CONTRADICTION();
53
		
54
		taxon.addSynonym(synonym, SynonymType.SYNONYM_OF());
55
		
56
		operation = new ChangeSynonymToConceptOperation("Change Synonym To Concept", null, taxon, synonym, taxonRelationshipType, postOperation);
57
	}
58

    
59
	/**
60
	 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
61
	 * @throws ExecutionException 
62
	 */
63
	@Test
64
	public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
65
		operation.execute(monitor, info);
66
		
67
		Assert.assertTrue("Synonym should be deleted from taxon.", taxon.getSynonyms().size() == 0);
68
		Assert.assertTrue("Taxon should have taxon relationships now.", taxon.getRelationsToThisTaxon().size() > 0);
69
		Assert.assertEquals("Relationship is not the expected", taxonRelationshipType, taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getType());
70
		Assert.assertEquals("Name of synonym and newly created related taxon should be equal", synonym.getName(), taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getFromTaxon().getName());
71
	}
72

    
73
	/**
74
	 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
75
	 * @throws ExecutionException 
76
	 */
77
	@Test
78
	public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
79
		operation.undo(monitor, info);
80
		
81
		Assert.assertTrue("There should be synonyms now.", taxon.getSynonyms().size() > 0);
82
		Assert.assertEquals("Synonym is not the expected.", synonym, taxon.getSynonyms().toArray(new Synonym[0]));
83
		Assert.assertTrue("There should not be taxon relationships.", taxon.getRelationsToThisTaxon().size() == 0);
84
	}
85
	
86
	/**
87
	 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
88
	 * @throws ExecutionException 
89
	 */
90
	@Test
91
	public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
92
		operation.redo(monitor, info);
93
				
94
		Assert.assertTrue("Synonym should be deleted from taxon.", taxon.getSynonyms().size() == 0);
95
		Assert.assertTrue("Taxon should have taxon relationships now.", taxon.getRelationsToThisTaxon().size() > 0);
96
		Assert.assertEquals("Relationship is not the expected", taxonRelationshipType, taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getType());
97
		Assert.assertEquals("Name of synonym and newly created related taxon should be equal", synonym.getName(), taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getFromTaxon().getName());
98
	}
99

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