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.cdm.model.taxon.TaxonRelationship;
|
24
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
25
|
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation;
|
26
|
import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTestBase;
|
27
|
|
28
|
/**
|
29
|
* @author n.hoffmann
|
30
|
* @created 07.04.2009
|
31
|
* @version 1.0
|
32
|
*/
|
33
|
public class ChangeSynonymToConceptOperationTest extends AbstractTaxeditorOperationTestBase{
|
34
|
private static final Logger logger = Logger
|
35
|
.getLogger(ChangeSynonymToConceptOperationTest.class);
|
36
|
|
37
|
private static TaxonRelationshipType taxonRelationshipType;
|
38
|
|
39
|
private static Synonym synonym;
|
40
|
|
41
|
|
42
|
/**
|
43
|
* @throws java.lang.Exception
|
44
|
*/
|
45
|
@BeforeClass
|
46
|
public static void setUpBeforeClass() throws Exception {
|
47
|
|
48
|
taxon = Taxon.NewInstance(null, null);
|
49
|
synonym = Synonym.NewInstance(NonViralName.NewInstance(null), null);
|
50
|
taxonRelationshipType = TaxonRelationshipType.CONTRADICTION();
|
51
|
|
52
|
taxon.addSynonym(synonym, SynonymType.SYNONYM_OF());
|
53
|
|
54
|
operation = new ChangeSynonymToConceptOperation("Change Synonym To Concept", null, taxon, synonym, taxonRelationshipType, postOperation);
|
55
|
}
|
56
|
|
57
|
/**
|
58
|
* Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
|
59
|
* @throws ExecutionException
|
60
|
*/
|
61
|
@Test
|
62
|
public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
|
63
|
operation.execute(monitor, info);
|
64
|
|
65
|
Assert.assertTrue("Synonym should be deleted from taxon.", taxon.getSynonyms().size() == 0);
|
66
|
Assert.assertTrue("Taxon should have taxon relationships now.", taxon.getRelationsToThisTaxon().size() > 0);
|
67
|
Assert.assertEquals("Relationship is not the expected", taxonRelationshipType, taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getType());
|
68
|
Assert.assertEquals("Name of synonym and newly created related taxon should be equal", synonym.getName(), taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getFromTaxon().getName());
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation#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(monitor, info);
|
78
|
|
79
|
Assert.assertTrue("There should be synonyms now.", taxon.getSynonyms().size() > 0);
|
80
|
Assert.assertEquals("Synonym is not the expected.", synonym, taxon.getSynonyms().toArray(new Synonym[0]));
|
81
|
Assert.assertTrue("There should not be taxon relationships.", taxon.getRelationsToThisTaxon().size() == 0);
|
82
|
}
|
83
|
|
84
|
/**
|
85
|
* Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation#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(monitor, info);
|
91
|
|
92
|
Assert.assertTrue("Synonym should be deleted from taxon.", taxon.getSynonyms().size() == 0);
|
93
|
Assert.assertTrue("Taxon should have taxon relationships now.", taxon.getRelationsToThisTaxon().size() > 0);
|
94
|
Assert.assertEquals("Relationship is not the expected", taxonRelationshipType, taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getType());
|
95
|
Assert.assertEquals("Name of synonym and newly created related taxon should be equal", synonym.getName(), taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getFromTaxon().getName());
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* Test method for {@link eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation#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
|
}
|