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 junit.framework.Assert;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.eclipse.core.commands.ExecutionException;
|
16
|
import org.junit.BeforeClass;
|
17
|
import org.junit.Test;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
20
|
import eu.etaxonomy.cdm.model.common.ICdmBase;
|
21
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
22
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
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
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
28
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
29
|
import eu.etaxonomy.taxeditor.editor.name.operation.SwapSynonymAndAcceptedOperation;
|
30
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
31
|
import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTestBase;
|
32
|
|
33
|
/**
|
34
|
* @author n.hoffmann
|
35
|
* @created 02.04.2009
|
36
|
* @version 1.0
|
37
|
*/
|
38
|
public class SwapSynonymAndAcceptedOperationTest extends AbstractTaxeditorOperationTestBase {
|
39
|
private static final Logger logger = Logger
|
40
|
.getLogger(SwapSynonymAndAcceptedOperationTest.class);
|
41
|
|
42
|
private static AbstractPostOperation operation;
|
43
|
|
44
|
private static Taxon taxon;
|
45
|
|
46
|
private static Taxon parentTaxon;
|
47
|
|
48
|
private static Synonym homotypicSynonym;
|
49
|
|
50
|
private static Synonym oldHeterotypicSynonym;
|
51
|
|
52
|
private static HomotypicalGroup heteroypicalGroup;
|
53
|
|
54
|
private static Taxon misapplication;
|
55
|
|
56
|
private static Taxon concept;
|
57
|
|
58
|
private static TaxonRelationshipType conceptRelationshipType;
|
59
|
|
60
|
private static Taxon childTaxon;
|
61
|
|
62
|
private static TaxonDescription description;
|
63
|
|
64
|
private static NonViralName<?> oldSynonymName;
|
65
|
|
66
|
private static NonViralName<?> oldTaxonName;
|
67
|
|
68
|
|
69
|
/**
|
70
|
* @throws java.lang.Exception
|
71
|
*/
|
72
|
@BeforeClass
|
73
|
public static void setUpBeforeClass() throws Exception {
|
74
|
|
75
|
(new DefaultTermInitializer()).initialize();
|
76
|
|
77
|
// Create the original accepted taxon
|
78
|
oldTaxonName = NonViralName.NewInstance(null);
|
79
|
taxon = Taxon.NewInstance(oldTaxonName, null);
|
80
|
|
81
|
// Create its parent taxon
|
82
|
parentTaxon = Taxon.NewInstance(NonViralName.NewInstance(null), null);
|
83
|
parentTaxon.addTaxonomicChild(taxon, null, null);
|
84
|
|
85
|
// Give it a child taxon
|
86
|
childTaxon = Taxon.NewInstance(NonViralName.NewInstance(null), null);
|
87
|
childTaxon.setTaxonomicParent(taxon, null, null);
|
88
|
|
89
|
// Create a homotypic synonym for the accepted taxon
|
90
|
taxon.addHomotypicSynonymName(NonViralName.NewInstance(null), null, null);
|
91
|
// homotypicSynonym = Synonym.NewInstance(NonViralName.NewInstance(null), null);
|
92
|
// HomotypicalGroup acceptedHomotypicalGroup = HomotypicalGroup.NewInstance();
|
93
|
// acceptedHomotypicalGroup.addTypifiedName(oldTaxon.getName());
|
94
|
// acceptedHomotypicalGroup.addTypifiedName(homotypicSynonym.getName());
|
95
|
|
96
|
// Create a heterotypic synonym that will be used to create the new accepted taxon
|
97
|
oldSynonymName = NonViralName.NewInstance(null);
|
98
|
oldHeterotypicSynonym = Synonym.NewInstance(oldSynonymName, null);
|
99
|
// oldTaxon.addS .addHeterotypicSynonym(oldHeterotypicSynonym, null, null);
|
100
|
heteroypicalGroup = HomotypicalGroup.NewInstance();
|
101
|
heteroypicalGroup.addTypifiedName(oldHeterotypicSynonym.getName());
|
102
|
taxon.addSynonym(oldHeterotypicSynonym, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
|
103
|
|
104
|
// Create a misapplication
|
105
|
misapplication = Taxon.NewInstance(NonViralName.NewInstance(null), null);
|
106
|
taxon.addMisappliedName(misapplication, null, null);
|
107
|
|
108
|
// Create a concept relation
|
109
|
concept = Taxon.NewInstance(NonViralName.NewInstance(null), null);
|
110
|
conceptRelationshipType = new TaxonRelationshipType();
|
111
|
concept.addTaxonRelation(taxon, conceptRelationshipType, null, null);
|
112
|
|
113
|
// Create a description
|
114
|
description = TaxonDescription.NewInstance();
|
115
|
taxon.addDescription(description);
|
116
|
|
117
|
operation = new SwapSynonymAndAcceptedOperation
|
118
|
(null, undoContext, taxon, oldHeterotypicSynonym, postOperation);
|
119
|
}
|
120
|
|
121
|
|
122
|
/**
|
123
|
* Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
|
124
|
* @throws ExecutionException
|
125
|
*/
|
126
|
@Test
|
127
|
public void testExecute() throws ExecutionException {
|
128
|
operation.execute(null, null);
|
129
|
|
130
|
// New taxon has correct name?
|
131
|
Assert.assertEquals(taxon.getName(), oldSynonymName);
|
132
|
|
133
|
// New taxon has correct parent?
|
134
|
Assert.assertEquals(taxon.getTaxonomicParent(), parentTaxon);
|
135
|
|
136
|
// New taxon has correct child?
|
137
|
Assert.assertTrue(taxon.getTaxonomicChildren().contains(childTaxon));
|
138
|
|
139
|
// New taxon has 2 synonyms?
|
140
|
Assert.assertEquals(taxon.getSynonyms().size(), 2);
|
141
|
|
142
|
// New taxon has a synonym with the name of the previous accepted taxon?
|
143
|
Assert.assertTrue(taxon.getSynonymNames().contains(oldTaxonName));
|
144
|
|
145
|
// New taxon has misapplication?
|
146
|
Assert.assertTrue(taxon.getMisappliedNames().contains(misapplication));
|
147
|
|
148
|
// New taxon has 1 concept relation?
|
149
|
int conceptRelCount = 0;
|
150
|
for (TaxonRelationship relation : taxon.getTaxonRelations()) {
|
151
|
if (relation.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR()) ||
|
152
|
relation.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())) {
|
153
|
continue;
|
154
|
}
|
155
|
conceptRelCount++;
|
156
|
}
|
157
|
Assert.assertEquals(conceptRelCount, 1);
|
158
|
|
159
|
// New taxon has description?
|
160
|
taxon.getDescriptions().contains(description);
|
161
|
}
|
162
|
|
163
|
/**
|
164
|
* Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
|
165
|
* @throws ExecutionException
|
166
|
*/
|
167
|
@Test
|
168
|
public void testUndo() throws ExecutionException {
|
169
|
operation.undo(null, null);
|
170
|
|
171
|
// Assert.assertEquals(oldHomotypicalGroup, synonym.getHomotypicGroup());
|
172
|
}
|
173
|
|
174
|
/**
|
175
|
* Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
|
176
|
* @throws ExecutionException
|
177
|
*/
|
178
|
@Test
|
179
|
public void testRedo() throws ExecutionException {
|
180
|
operation.redo(null, null);
|
181
|
|
182
|
// Assert.assertEquals(newHomotypicalGroup, synonym.getHomotypicGroup());
|
183
|
}
|
184
|
|
185
|
/**
|
186
|
* Test method for {@link eu.etaxonomy.taxeditor.operation.AbstractPostOperation#postExecute(ICdmBase)}.
|
187
|
*/
|
188
|
@Test
|
189
|
public void testPostExecute() {
|
190
|
// TODO there is not post operation functionality for this class
|
191
|
// at the moment. Implement test when there is.
|
192
|
logger.warn("No post operation functionality for this class");
|
193
|
}
|
194
|
}
|