1
|
/**
|
2
|
* Copyright (C) 2015 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
|
package eu.etaxonomy.taxeditor.operation;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.HashSet;
|
13
|
import java.util.List;
|
14
|
import java.util.Set;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.eclipse.core.commands.ExecutionException;
|
19
|
import org.junit.Assert;
|
20
|
import org.junit.Test;
|
21
|
import org.unitils.dbunit.annotation.DataSet;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
24
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
25
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
26
|
import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling;
|
27
|
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
|
28
|
import eu.etaxonomy.cdm.api.service.config.TaxonNodeDeletionConfigurator;
|
29
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
30
|
import eu.etaxonomy.cdm.model.common.Language;
|
31
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
32
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
33
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
34
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
35
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
36
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
37
|
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TreeNodeDropAdapterE4.MovingType;
|
38
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingChangeAcceptedTaxonToSynonymOperation;
|
39
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingDeleteTaxonNodeOperation;
|
40
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveFactualDataOperation;
|
41
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveTaxonOperation;
|
42
|
|
43
|
/**
|
44
|
* @author cmathew
|
45
|
* @date 9 Mar 2015
|
46
|
*
|
47
|
*/
|
48
|
@DataSet
|
49
|
public class TaxonNavigatorTest extends BaseOperationTest {
|
50
|
|
51
|
@SuppressWarnings("unused")
|
52
|
private static final Logger logger = Logger.getLogger(TaxonNameEditorTest.class);
|
53
|
|
54
|
ITaxonNodeService taxonNodeService = getRemoteApplicationController().getTaxonNodeService();
|
55
|
ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
|
56
|
IClassificationService classificationService = getRemoteApplicationController().getClassificationService();
|
57
|
|
58
|
Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
|
59
|
|
60
|
|
61
|
|
62
|
@Test
|
63
|
public void testChangeAcceptedTaxonToSynonym() throws ExecutionException {
|
64
|
|
65
|
|
66
|
UUID oldTaxonNodeNodeUuid = UUID.fromString("b85b5b78-6760-409f-ac91-bb89e95ff2a1");
|
67
|
UUID newAcceptedTaxonNodeUuid = UUID.fromString("6ad8e9e2-f5f6-41ad-aa30-f62a903650db");
|
68
|
|
69
|
TaxonNode oldTaxonNode = taxonNodeService.load(oldTaxonNodeNodeUuid);
|
70
|
TaxonName name = oldTaxonNode.getTaxon().getName();
|
71
|
|
72
|
|
73
|
TaxonNode newAcceptedTaxonNode = taxonNodeService.load(newAcceptedTaxonNodeUuid);
|
74
|
int countTargetSynonyms = newAcceptedTaxonNode.getTaxon().getSynonyms().size();
|
75
|
sessionOwner.addExpectedUpdatedObject(oldTaxonNode.getParent());
|
76
|
sessionOwner.addExpectedUpdatedObject(newAcceptedTaxonNode);
|
77
|
|
78
|
operation = new RemotingChangeAcceptedTaxonToSynonymOperation(sessionOwner,
|
79
|
false,
|
80
|
oldTaxonNode.getUuid(),
|
81
|
newAcceptedTaxonNode.getUuid());
|
82
|
operation.execute(monitor, info);
|
83
|
newAcceptedTaxonNode = taxonNodeService.load(newAcceptedTaxonNodeUuid);
|
84
|
oldTaxonNode = taxonNodeService.load(oldTaxonNodeNodeUuid);
|
85
|
Assert.assertNull(oldTaxonNode);
|
86
|
Assert.assertEquals(countTargetSynonyms + 1,newAcceptedTaxonNode.getTaxon().getSynonyms().size());
|
87
|
Assert.assertEquals(name, newAcceptedTaxonNode.getTaxon().getSynonyms().iterator().next().getName());
|
88
|
|
89
|
|
90
|
}
|
91
|
|
92
|
@Test
|
93
|
public void testMoveTaxon() throws ExecutionException {
|
94
|
|
95
|
UUID taxonNodeToMoveUuid = UUID.fromString("b8439f51-6b96-445a-b401-7a836ba1cf58");
|
96
|
UUID newParentTreeNodeUuid = UUID.fromString("2f05d429-632d-4230-b9cb-70299360b470");
|
97
|
MovingType moveToParentNode = MovingType.CHILD;
|
98
|
|
99
|
TaxonNode taxonNodeToMove = taxonNodeService.load(taxonNodeToMoveUuid);
|
100
|
TaxonNode oldParent = taxonNodeToMove.getParent();
|
101
|
Set<UUID>uuids = new HashSet<>();
|
102
|
uuids.add(taxonNodeToMoveUuid);
|
103
|
sessionOwner.addExpectedUpdatedObject(oldParent);
|
104
|
int childCount = oldParent.getCountChildren();
|
105
|
TaxonNode newParentTreeNode = taxonNodeService.load(newParentTreeNodeUuid);
|
106
|
sessionOwner.addExpectedUpdatedObject(newParentTreeNode);
|
107
|
operation = new RemotingMoveTaxonOperation(sessionOwner,
|
108
|
false,
|
109
|
uuids,
|
110
|
newParentTreeNode.getUuid(),
|
111
|
moveToParentNode);
|
112
|
operation.execute(monitor, info);
|
113
|
Assert.assertEquals(childCount-1, oldParent.getCountChildren());
|
114
|
Assert.assertTrue(!oldParent.getChildNodes().contains(taxonNodeToMove));
|
115
|
Assert.assertTrue(newParentTreeNode.getChildNodes().contains(taxonNodeToMove));
|
116
|
}
|
117
|
|
118
|
@Test
|
119
|
public void testMoveFactualData() throws ExecutionException {
|
120
|
UUID sourceTaxonUuid = UUID.fromString("e40854d7-143f-4054-b229-6ed4cedb4bff");
|
121
|
UUID targetTaxonUuid = UUID.fromString("b8402dc4-5050-4882-a147-01b71e0e47d6");
|
122
|
|
123
|
Taxon sourceTaxon = CdmBase.deproxy(taxonService.load(sourceTaxonUuid), Taxon.class);
|
124
|
Set<TaxonDescription> sourceDescriptions = new HashSet(sourceTaxon.getDescriptions());
|
125
|
sessionOwner.addExpectedUpdatedObject(sourceTaxon);
|
126
|
|
127
|
Taxon targetTaxon = CdmBase.deproxy(taxonService.load(targetTaxonUuid), Taxon.class);
|
128
|
int countTargetDescriptions = targetTaxon.getDescriptions().size();
|
129
|
sessionOwner.addExpectedUpdatedObject(targetTaxon);
|
130
|
|
131
|
operation = new RemotingMoveFactualDataOperation(sessionOwner,
|
132
|
false,
|
133
|
sourceTaxonUuid,
|
134
|
targetTaxonUuid);
|
135
|
operation.execute(monitor, info);
|
136
|
Assert.assertEquals(0, sourceTaxon.getDescriptions().size());
|
137
|
Assert.assertEquals(sourceDescriptions.size() + countTargetDescriptions, targetTaxon.getDescriptions().size());
|
138
|
Assert.assertTrue(targetTaxon.getDescriptions().containsAll(sourceDescriptions));
|
139
|
}
|
140
|
|
141
|
@Test
|
142
|
public void testDeleteTaxonNodeWithDeleteChildren() throws ExecutionException {
|
143
|
UUID taxonNodeUuid = UUID.fromString("2f05d429-632d-4230-b9cb-70299360b470");
|
144
|
TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
|
145
|
List<TaxonNode> childNodes = taxonNode.getChildNodes();
|
146
|
List<UUID> childNodeUuids = new ArrayList<UUID>();
|
147
|
for(TaxonNode childNode : childNodes) {
|
148
|
childNodeUuids.add(childNode.getUuid());
|
149
|
}
|
150
|
Assert.assertTrue(taxonNode.getCountChildren() > 0);
|
151
|
|
152
|
Set<TaxonNodeDto> nodes = new HashSet();
|
153
|
nodes.add(new TaxonNodeDto(taxonNode));
|
154
|
|
155
|
TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator();
|
156
|
configNodes.setChildHandling(ChildHandling.DELETE);
|
157
|
TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
|
158
|
config.setTaxonNodeConfig(configNodes);
|
159
|
|
160
|
sessionOwner.addExpectedUpdatedObject(taxonNode.getParent());
|
161
|
|
162
|
operation = new RemotingDeleteTaxonNodeOperation(sessionOwner,
|
163
|
false,
|
164
|
nodes,
|
165
|
null,
|
166
|
config);
|
167
|
operation.execute(monitor, info);
|
168
|
TaxonNode reloadedNode = taxonNodeService.load(taxonNode.getUuid());
|
169
|
Assert.assertNull(reloadedNode);
|
170
|
for(UUID childNodeUuid : childNodeUuids) {
|
171
|
TaxonNode reloadedChildNode = taxonNodeService.load(childNodeUuid);
|
172
|
Assert.assertNull(reloadedChildNode);
|
173
|
}
|
174
|
}
|
175
|
|
176
|
@Test
|
177
|
public void testDeleteTaxonNodes() throws ExecutionException {
|
178
|
UUID taxonNode1Uuid = UUID.fromString("99f03b56-67cd-4e01-9ceb-2362d48f9d07");
|
179
|
UUID taxonNode2Uuid = UUID.fromString("91698cec-615f-4472-9002-feda1a6acded");
|
180
|
UUID taxonNode3Uuid = UUID.fromString("4fe03763-b966-4361-8334-352f6f777588");
|
181
|
|
182
|
TaxonNode taxonNode1 = taxonNodeService.load(taxonNode1Uuid);
|
183
|
TaxonNode taxonNode2 = taxonNodeService.load(taxonNode2Uuid);
|
184
|
TaxonNode taxonNode3 = taxonNodeService.load(taxonNode3Uuid);
|
185
|
|
186
|
Set<TaxonNodeDto> nodes = new HashSet();
|
187
|
nodes.add(new TaxonNodeDto(taxonNode1));
|
188
|
nodes.add(new TaxonNodeDto(taxonNode2));
|
189
|
nodes.add(new TaxonNodeDto(taxonNode3));
|
190
|
|
191
|
TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
|
192
|
|
193
|
|
194
|
sessionOwner.addExpectedUpdatedObject(taxonNode1.getParent());
|
195
|
sessionOwner.addExpectedUpdatedObject(taxonNode2.getParent());
|
196
|
sessionOwner.addExpectedUpdatedObject(taxonNode3.getParent());
|
197
|
operation = new RemotingDeleteTaxonNodeOperation(sessionOwner,
|
198
|
false,
|
199
|
nodes,
|
200
|
null,
|
201
|
config);
|
202
|
operation.execute(monitor, info);
|
203
|
TaxonNode reloadedNode1 = taxonNodeService.load(taxonNode1.getUuid());
|
204
|
TaxonNode reloadedNode2 = taxonNodeService.load(taxonNode2.getUuid());
|
205
|
TaxonNode reloadedNode3 = taxonNodeService.load(taxonNode3.getUuid());
|
206
|
Assert.assertNull(reloadedNode1);
|
207
|
Assert.assertNull(reloadedNode2);
|
208
|
Assert.assertNull(reloadedNode3);
|
209
|
|
210
|
}
|
211
|
|
212
|
@Test
|
213
|
public void testDeleteTaxonNodeWithMovingChildrenToParentNode() throws ExecutionException {
|
214
|
UUID taxonNodeUuid = UUID.fromString("2f05d429-632d-4230-b9cb-70299360b470");
|
215
|
TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
|
216
|
TaxonNode parentTaxonNode = taxonNode.getParent();
|
217
|
List<TaxonNode> childNodes = taxonNode.getChildNodes();
|
218
|
List<UUID> childNodeUuids = new ArrayList<UUID>();
|
219
|
for(TaxonNode childNode : childNodes) {
|
220
|
childNodeUuids.add(childNode.getUuid());
|
221
|
}
|
222
|
Assert.assertTrue(taxonNode.getCountChildren() > 0);
|
223
|
|
224
|
Set<TaxonNodeDto> nodes = new HashSet();
|
225
|
nodes.add(new TaxonNodeDto(taxonNode));
|
226
|
|
227
|
TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator();
|
228
|
configNodes.setChildHandling(ChildHandling.MOVE_TO_PARENT);
|
229
|
TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
|
230
|
config.setTaxonNodeConfig(configNodes);
|
231
|
|
232
|
sessionOwner.addExpectedUpdatedObject(taxonNode.getParent());
|
233
|
operation = new RemotingDeleteTaxonNodeOperation(sessionOwner,
|
234
|
false,
|
235
|
nodes,
|
236
|
null,
|
237
|
config);
|
238
|
operation.execute(monitor, info);
|
239
|
TaxonNode reloadedNode = taxonNodeService.load(taxonNode.getUuid());
|
240
|
Assert.assertNull(reloadedNode);
|
241
|
List<TaxonNode> parentChildNodes = parentTaxonNode.getChildNodes();
|
242
|
List<UUID> parentChildNodeUuids = new ArrayList<UUID>();
|
243
|
for(TaxonNode parentChildNode : parentChildNodes) {
|
244
|
parentChildNodeUuids.add(parentChildNode.getUuid());
|
245
|
}
|
246
|
parentChildNodeUuids.containsAll(childNodeUuids);
|
247
|
|
248
|
}
|
249
|
|
250
|
@Test
|
251
|
@DataSet("TaxonNavigatorTest.testDeleteClassificationWithDeleteChildren.xml")
|
252
|
public void testDeleteClassificationWithDeleteChildren() throws ExecutionException {
|
253
|
UUID classificationUuid = UUID.fromString("0c2b5d25-7b15-4401-8b51-dd4be0ee5cab");
|
254
|
Classification classification = classificationService.load(classificationUuid);
|
255
|
TaxonNode rootNode = classification.getRootNode();
|
256
|
Set<TaxonNodeDto> nodes = new HashSet();
|
257
|
nodes.add(new TaxonNodeDto(classification.getRootNode()));
|
258
|
|
259
|
TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator();
|
260
|
configNodes.setChildHandling(ChildHandling.DELETE);
|
261
|
TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
|
262
|
config.setTaxonNodeConfig(configNodes);
|
263
|
|
264
|
operation = new RemotingDeleteTaxonNodeOperation(sessionOwner,
|
265
|
false,
|
266
|
nodes,
|
267
|
null,
|
268
|
config);
|
269
|
operation.execute(monitor, info);
|
270
|
|
271
|
Classification reloadedClassification = classificationService.load(classification.getUuid());
|
272
|
Assert.assertNull(reloadedClassification);
|
273
|
TaxonNode reloadedRootNode = taxonNodeService.load(rootNode.getUuid());
|
274
|
Assert.assertNull(reloadedRootNode);
|
275
|
|
276
|
}
|
277
|
|
278
|
|
279
|
}
|