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