1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.operation;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.Iterator;
|
14
|
import java.util.List;
|
15
|
import java.util.Set;
|
16
|
import java.util.UUID;
|
17
|
|
18
|
import org.apache.log4j.Logger;
|
19
|
import org.eclipse.core.commands.ExecutionException;
|
20
|
import org.junit.Assert;
|
21
|
import org.junit.Ignore;
|
22
|
import org.junit.Test;
|
23
|
import org.unitils.dbunit.annotation.DataSet;
|
24
|
|
25
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
26
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
27
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
28
|
import eu.etaxonomy.cdm.model.common.Language;
|
29
|
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
|
30
|
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
|
31
|
import eu.etaxonomy.cdm.model.description.Feature;
|
32
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
33
|
import eu.etaxonomy.cdm.model.description.TextData;
|
34
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
35
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
36
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
37
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
38
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
39
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
40
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
41
|
import eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation;
|
42
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
43
|
|
44
|
/**
|
45
|
* @author cmathew
|
46
|
* @date 3 Feb 2015
|
47
|
*
|
48
|
*/
|
49
|
|
50
|
@DataSet
|
51
|
public class TaxonNameEditorTest extends BaseOperationTest {
|
52
|
|
53
|
private static final Logger logger = Logger.getLogger(TaxonNameEditorTest.class);
|
54
|
|
55
|
ITaxonNodeService taxonNodeService = getRemoteApplicationController().getTaxonNodeService();
|
56
|
ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
|
57
|
IClassificationService classificationService = getRemoteApplicationController().getClassificationService();
|
58
|
|
59
|
Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
|
60
|
|
61
|
|
62
|
@Test
|
63
|
public void testAddHomotypicSynonym() throws ExecutionException {
|
64
|
UUID taxonNodeUuid = UUID.fromString("ce54c396-3694-47f2-abb0-1d7b7e057985");
|
65
|
|
66
|
TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
|
67
|
Taxon taxon = taxonNode.getTaxon();
|
68
|
HomotypicalGroup group = taxon.getHomotypicGroup();
|
69
|
BotanicalName newSynonymName = BotanicalName.NewInstance(null);
|
70
|
newSynonymName.setTitleCache("New Synonym", true);
|
71
|
operation = new CreateSynonymInExistingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
|
72
|
undoContext, taxon, group, newSynonymName, postOperation);
|
73
|
|
74
|
operation.execute(monitor, info);
|
75
|
taxonNodeService.merge(taxonNode);
|
76
|
Assert.assertEquals(taxon.getHomotypicGroup().getTypifiedNames().size(), 2);
|
77
|
Assert.assertEquals(taxon.getSynonyms().size(), 1);
|
78
|
Iterator<Synonym> synonymItr = taxon.getSynonyms().iterator();
|
79
|
Synonym synonym = synonymItr.next();
|
80
|
Assert.assertTrue(taxon.getHomotypicGroup().getTypifiedNames().contains(synonym.getName()));
|
81
|
}
|
82
|
|
83
|
@Test
|
84
|
public void addHeterotypicSynonym() throws ExecutionException {
|
85
|
UUID taxonNodeUuid = UUID.fromString("ce54c396-3694-47f2-abb0-1d7b7e057985");
|
86
|
|
87
|
TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
|
88
|
Taxon taxon = taxonNode.getTaxon();
|
89
|
HomotypicalGroup group = taxon.getHomotypicGroup();
|
90
|
BotanicalName newSynonymName = BotanicalName.NewInstance(null);
|
91
|
newSynonymName.setTitleCache("New Synonym", true);
|
92
|
operation = new CreateSynonymInExistingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
|
93
|
undoContext, taxon, group, newSynonymName, postOperation);
|
94
|
|
95
|
operation.execute(monitor, info);
|
96
|
taxonNodeService.merge(taxonNode);
|
97
|
|
98
|
|
99
|
}
|
100
|
|
101
|
@Test
|
102
|
public void addDeleteAddHomotypicSynonym() throws ExecutionException {
|
103
|
UUID taxonNodeUuid = UUID.fromString("ce54c396-3694-47f2-abb0-1d7b7e057985");
|
104
|
|
105
|
TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
|
106
|
Taxon taxon = taxonNode.getTaxon();
|
107
|
HomotypicalGroup group = taxon.getHomotypicGroup();
|
108
|
BotanicalName newSynonymName = BotanicalName.NewInstance(null);
|
109
|
newSynonymName.setTitleCache("New Synonym", true);
|
110
|
operation = new CreateSynonymInExistingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
|
111
|
undoContext, taxon, group, newSynonymName, postOperation);
|
112
|
|
113
|
operation.execute(monitor, info);
|
114
|
taxonNodeService.merge(taxonNode);
|
115
|
Assert.assertEquals(taxon.getHomotypicGroup().getTypifiedNames().size(), 2);
|
116
|
|
117
|
Set<Synonym> synonyms = taxon.getSynonyms();
|
118
|
for(Synonym synonym : synonyms) {
|
119
|
taxonService.deleteSynonym(synonym.getUuid(), taxon.getUuid(), null);
|
120
|
}
|
121
|
|
122
|
taxonNodeService.merge(taxonNode);
|
123
|
|
124
|
newSynonymName = BotanicalName.NewInstance(null);
|
125
|
newSynonymName.setTitleCache("Another New Synonym", true);
|
126
|
operation = new CreateSynonymInExistingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
|
127
|
undoContext, taxon, group, newSynonymName, postOperation);
|
128
|
|
129
|
operation.execute(monitor, info);
|
130
|
taxonNodeService.merge(taxonNode);
|
131
|
}
|
132
|
|
133
|
@Test
|
134
|
public void swapSynonymWithAcceptedTaxon() throws ExecutionException {
|
135
|
List<TaxonNode> rootEntities = new ArrayList<TaxonNode>();
|
136
|
UUID taxonNodeUuid = UUID.fromString("d425a971-1abe-4895-9e1f-1e5c8ff1c84c");
|
137
|
TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
|
138
|
rootEntities.add(taxonNode);
|
139
|
|
140
|
UUID taxonUuid = UUID.fromString("9763e5f0-6cd4-4d96-b8a4-4420854f7727");
|
141
|
Taxon taxon = (Taxon)taxonService.load(taxonUuid);
|
142
|
TaxonNameBase taxonName = taxon.getName();
|
143
|
|
144
|
UUID synonymUuid = UUID.fromString("1eb173bd-b174-4162-8ff5-5136d8f1e746");
|
145
|
Synonym synonym = (Synonym)taxonService.load(synonymUuid);
|
146
|
TaxonNameBase synonymName = synonym.getName();
|
147
|
|
148
|
taxonService.swapSynonymAndAcceptedTaxon(synonym.getUuid(), taxon.getUuid());
|
149
|
|
150
|
Assert.assertEquals(taxonName, synonym.getName());
|
151
|
Assert.assertEquals(synonymName, taxon.getName());
|
152
|
}
|
153
|
|
154
|
@Test
|
155
|
public void addTaxon() {
|
156
|
NonViralName taxonName = NonViralName.NewInstance(null);
|
157
|
Taxon taxon = Taxon.NewInstance(taxonName, null);
|
158
|
taxonService.merge(taxon);
|
159
|
}
|
160
|
|
161
|
@Ignore
|
162
|
@Test
|
163
|
public void addDescription() {
|
164
|
UUID taxonNodeUuid = UUID.fromString("ce54c396-3694-47f2-abb0-1d7b7e057985");
|
165
|
|
166
|
TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
|
167
|
Taxon taxon = taxonNode.getTaxon();
|
168
|
TaxonDescription description = TaxonDescription.NewInstance(taxon);
|
169
|
|
170
|
|
171
|
TextData textData = TextData.NewInstance();
|
172
|
|
173
|
textData.setFeature(Feature.ECOLOGY());
|
174
|
description.addElement(textData);
|
175
|
|
176
|
DescriptionElementSource descriptionElementSource = DescriptionElementSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
|
177
|
textData.addSource(descriptionElementSource);
|
178
|
|
179
|
|
180
|
CdmStore.getService(ITaxonNodeService.class).merge(taxonNode);
|
181
|
|
182
|
description.getId();
|
183
|
}
|
184
|
|
185
|
|
186
|
@Test
|
187
|
public void addTaxonNodeCascadeProblem() {
|
188
|
UUID taxonNodeUuid = UUID.fromString("ce54c396-3694-47f2-abb0-1d7b7e057985");
|
189
|
|
190
|
TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
|
191
|
Taxon childTaxon = Taxon.NewInstance(null, null);
|
192
|
TaxonNode childTaxonNode = taxonNode.addChildTaxon(childTaxon, null, null);
|
193
|
Taxon grandChildTaxon = Taxon.NewInstance(null, null);
|
194
|
TaxonNode grandChildTaxonNode = childTaxonNode.addChildTaxon(grandChildTaxon, null, null);
|
195
|
|
196
|
|
197
|
CdmStore.getService(ITaxonNodeService.class).merge(taxonNode,true);
|
198
|
|
199
|
Assert.assertEquals(taxonNode.getChildNodes().get(0).getId(), childTaxonNode.getId());
|
200
|
|
201
|
Assert.assertTrue(childTaxonNode.treeIndex() != null);
|
202
|
Assert.assertEquals(taxonNode.getChildNodes().get(0).treeIndex(), childTaxonNode.treeIndex());
|
203
|
Assert.assertFalse(childTaxon.getId() == 0);
|
204
|
Assert.assertEquals(taxonNode.getChildNodes().get(0).getTaxon().getId(), childTaxon.getId());
|
205
|
|
206
|
Assert.assertTrue(grandChildTaxonNode.treeIndex() != null);
|
207
|
Assert.assertEquals(taxonNode.getChildNodes().get(0).getChildNodes().get(0).getId(), grandChildTaxonNode.getId());
|
208
|
Assert.assertFalse(grandChildTaxon.getId() == 0);
|
209
|
Assert.assertEquals(taxonNode.getChildNodes().get(0).getChildNodes().get(0).getTaxon().getId(), grandChildTaxon.getId());
|
210
|
}
|
211
|
|
212
|
}
|
213
|
|