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