3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.operation
;
12 import java
.util
.ArrayList
;
13 import java
.util
.HashSet
;
14 import java
.util
.List
;
16 import java
.util
.UUID
;
18 import org
.apache
.log4j
.Logger
;
19 import org
.eclipse
.core
.commands
.ExecutionException
;
20 import org
.junit
.Assert
;
21 import org
.junit
.Test
;
22 import org
.unitils
.dbunit
.annotation
.DataSet
;
24 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
25 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
26 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
27 import eu
.etaxonomy
.cdm
.api
.service
.config
.NodeDeletionConfigurator
.ChildHandling
;
28 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
29 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonNodeDeletionConfigurator
;
30 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
31 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
32 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
33 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
37 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
38 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TreeNodeDropAdapter
.MovingType
;
39 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.RemotingChangeAcceptedTaxonToSynonymOperation
;
40 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.RemotingDeleteTaxonNodeOperation
;
41 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.RemotingMoveFactualDataOperation
;
42 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.RemotingMoveTaxonOperation
;
50 public class TaxonNavigatorTest
extends BaseOperationTest
{
52 @SuppressWarnings("unused")
53 private static final Logger logger
= Logger
.getLogger(TaxonNameEditorTest
.class);
55 ITaxonNodeService taxonNodeService
= getRemoteApplicationController().getTaxonNodeService();
56 ITaxonService taxonService
= getRemoteApplicationController().getTaxonService();
57 IClassificationService classificationService
= getRemoteApplicationController().getClassificationService();
59 Language english
= Language
.getLanguageFromUuid(Language
.uuidEnglish
);
64 public void testChangeAcceptedTaxonToSynonym() throws ExecutionException
{
67 UUID oldTaxonNodeNodeUuid
= UUID
.fromString("b85b5b78-6760-409f-ac91-bb89e95ff2a1");
68 UUID newAcceptedTaxonNodeUuid
= UUID
.fromString("6ad8e9e2-f5f6-41ad-aa30-f62a903650db");
70 TaxonNode oldTaxonNode
= taxonNodeService
.load(oldTaxonNodeNodeUuid
);
71 TaxonNameBase name
= oldTaxonNode
.getTaxon().getName();
74 TaxonNode newAcceptedTaxonNode
= taxonNodeService
.load(newAcceptedTaxonNodeUuid
);
75 int countTargetSynonyms
= newAcceptedTaxonNode
.getTaxon().getSynonyms().size();
76 sessionOwner
.addExpectedUpdatedObject(oldTaxonNode
.getParent());
77 sessionOwner
.addExpectedUpdatedObject(newAcceptedTaxonNode
);
79 operation
= new RemotingChangeAcceptedTaxonToSynonymOperation(sessionOwner
,
81 oldTaxonNode
.getUuid(),
82 newAcceptedTaxonNode
.getUuid());
83 operation
.execute(monitor
, info
);
84 newAcceptedTaxonNode
= taxonNodeService
.load(newAcceptedTaxonNodeUuid
);
85 oldTaxonNode
= taxonNodeService
.load(oldTaxonNodeNodeUuid
);
86 Assert
.assertNull(oldTaxonNode
);
87 Assert
.assertEquals(countTargetSynonyms
+ 1,newAcceptedTaxonNode
.getTaxon().getSynonyms().size());
88 Assert
.assertEquals(name
, newAcceptedTaxonNode
.getTaxon().getSynonyms().iterator().next().getName());
94 public void testMoveTaxon() throws ExecutionException
{
96 UUID taxonNodeToMoveUuid
= UUID
.fromString("b8439f51-6b96-445a-b401-7a836ba1cf58");
97 UUID newParentTreeNodeUuid
= UUID
.fromString("2f05d429-632d-4230-b9cb-70299360b470");
98 MovingType moveToParentNode
= MovingType
.CHILD
;
100 TaxonNode taxonNodeToMove
= taxonNodeService
.load(taxonNodeToMoveUuid
);
101 TaxonNode oldParent
= taxonNodeToMove
.getParent();
102 sessionOwner
.addExpectedUpdatedObject(oldParent
);
103 int childCount
= oldParent
.getCountChildren();
104 TaxonNode newParentTreeNode
= taxonNodeService
.load(newParentTreeNodeUuid
);
105 sessionOwner
.addExpectedUpdatedObject(newParentTreeNode
);
106 operation
= new RemotingMoveTaxonOperation(sessionOwner
,
108 taxonNodeToMove
.getUuid(),
109 newParentTreeNode
.getUuid(),
111 operation
.execute(monitor
, info
);
112 Assert
.assertEquals(childCount
-1, oldParent
.getCountChildren());
113 Assert
.assertTrue(!oldParent
.getChildNodes().contains(taxonNodeToMove
));
114 Assert
.assertTrue(newParentTreeNode
.getChildNodes().contains(taxonNodeToMove
));
118 public void testMoveFactualData() throws ExecutionException
{
119 UUID sourceTaxonUuid
= UUID
.fromString("e40854d7-143f-4054-b229-6ed4cedb4bff");
120 UUID targetTaxonUuid
= UUID
.fromString("b8402dc4-5050-4882-a147-01b71e0e47d6");
122 Taxon sourceTaxon
= CdmBase
.deproxy(taxonService
.load(sourceTaxonUuid
), Taxon
.class);
123 Set
<TaxonDescription
> sourceDescriptions
= new HashSet(sourceTaxon
.getDescriptions());
124 sessionOwner
.addExpectedUpdatedObject(sourceTaxon
);
126 Taxon targetTaxon
= CdmBase
.deproxy(taxonService
.load(targetTaxonUuid
), Taxon
.class);
127 int countTargetDescriptions
= targetTaxon
.getDescriptions().size();
128 sessionOwner
.addExpectedUpdatedObject(targetTaxon
);
130 operation
= new RemotingMoveFactualDataOperation(sessionOwner
,
134 operation
.execute(monitor
, info
);
135 Assert
.assertEquals(0, sourceTaxon
.getDescriptions().size());
136 Assert
.assertEquals(sourceDescriptions
.size() + countTargetDescriptions
, targetTaxon
.getDescriptions().size());
137 Assert
.assertTrue(targetTaxon
.getDescriptions().containsAll(sourceDescriptions
));
141 public void testDeleteTaxonNodeWithDeleteChildren() throws ExecutionException
{
142 UUID taxonNodeUuid
= UUID
.fromString("2f05d429-632d-4230-b9cb-70299360b470");
143 TaxonNode taxonNode
= taxonNodeService
.load(taxonNodeUuid
);
144 List
<TaxonNode
> childNodes
= taxonNode
.getChildNodes();
145 List
<UUID
> childNodeUuids
= new ArrayList
<UUID
>();
146 for(TaxonNode childNode
: childNodes
) {
147 childNodeUuids
.add(childNode
.getUuid());
149 Assert
.assertTrue(taxonNode
.getCountChildren() > 0);
151 Set
<ITaxonTreeNode
> nodes
= new HashSet
<ITaxonTreeNode
>();
152 nodes
.add(taxonNode
);
154 TaxonNodeDeletionConfigurator configNodes
= new TaxonNodeDeletionConfigurator();
155 configNodes
.setChildHandling(ChildHandling
.DELETE
);
156 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
157 config
.setTaxonNodeConfig(configNodes
);
159 sessionOwner
.addExpectedUpdatedObject(taxonNode
.getParent());
161 operation
= new RemotingDeleteTaxonNodeOperation(sessionOwner
,
165 operation
.execute(monitor
, info
);
166 TaxonNode reloadedNode
= taxonNodeService
.load(taxonNode
.getUuid());
167 Assert
.assertNull(reloadedNode
);
168 for(UUID childNodeUuid
: childNodeUuids
) {
169 TaxonNode reloadedChildNode
= taxonNodeService
.load(childNodeUuid
);
170 Assert
.assertNull(reloadedChildNode
);
175 public void testDeleteTaxonNodes() throws ExecutionException
{
176 UUID taxonNode1Uuid
= UUID
.fromString("99f03b56-67cd-4e01-9ceb-2362d48f9d07");
177 UUID taxonNode2Uuid
= UUID
.fromString("91698cec-615f-4472-9002-feda1a6acded");
178 UUID taxonNode3Uuid
= UUID
.fromString("4fe03763-b966-4361-8334-352f6f777588");
180 TaxonNode taxonNode1
= taxonNodeService
.load(taxonNode1Uuid
);
181 TaxonNode taxonNode2
= taxonNodeService
.load(taxonNode2Uuid
);
182 TaxonNode taxonNode3
= taxonNodeService
.load(taxonNode3Uuid
);
184 Set
<ITaxonTreeNode
> nodes
= new HashSet
<ITaxonTreeNode
>();
185 nodes
.add(taxonNode1
);
186 nodes
.add(taxonNode2
);
187 nodes
.add(taxonNode3
);
189 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
192 sessionOwner
.addExpectedUpdatedObject(taxonNode1
.getParent());
193 sessionOwner
.addExpectedUpdatedObject(taxonNode2
.getParent());
194 sessionOwner
.addExpectedUpdatedObject(taxonNode3
.getParent());
195 operation
= new RemotingDeleteTaxonNodeOperation(sessionOwner
,
199 operation
.execute(monitor
, info
);
200 TaxonNode reloadedNode1
= taxonNodeService
.load(taxonNode1
.getUuid());
201 TaxonNode reloadedNode2
= taxonNodeService
.load(taxonNode2
.getUuid());
202 TaxonNode reloadedNode3
= taxonNodeService
.load(taxonNode3
.getUuid());
203 Assert
.assertNull(reloadedNode1
);
204 Assert
.assertNull(reloadedNode2
);
205 Assert
.assertNull(reloadedNode3
);
210 public void testDeleteTaxonNodeWithMovingChildrenToParentNode() throws ExecutionException
{
211 UUID taxonNodeUuid
= UUID
.fromString("2f05d429-632d-4230-b9cb-70299360b470");
212 TaxonNode taxonNode
= taxonNodeService
.load(taxonNodeUuid
);
213 TaxonNode parentTaxonNode
= taxonNode
.getParent();
214 List
<TaxonNode
> childNodes
= taxonNode
.getChildNodes();
215 List
<UUID
> childNodeUuids
= new ArrayList
<UUID
>();
216 for(TaxonNode childNode
: childNodes
) {
217 childNodeUuids
.add(childNode
.getUuid());
219 Assert
.assertTrue(taxonNode
.getCountChildren() > 0);
221 Set
<ITaxonTreeNode
> nodes
= new HashSet
<ITaxonTreeNode
>();
222 nodes
.add(taxonNode
);
224 TaxonNodeDeletionConfigurator configNodes
= new TaxonNodeDeletionConfigurator();
225 configNodes
.setChildHandling(ChildHandling
.MOVE_TO_PARENT
);
226 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
227 config
.setTaxonNodeConfig(configNodes
);
229 sessionOwner
.addExpectedUpdatedObject(taxonNode
.getParent());
230 operation
= new RemotingDeleteTaxonNodeOperation(sessionOwner
,
234 operation
.execute(monitor
, info
);
235 TaxonNode reloadedNode
= taxonNodeService
.load(taxonNode
.getUuid());
236 Assert
.assertNull(reloadedNode
);
237 List
<TaxonNode
> parentChildNodes
= parentTaxonNode
.getChildNodes();
238 List
<UUID
> parentChildNodeUuids
= new ArrayList
<UUID
>();
239 for(TaxonNode parentChildNode
: parentChildNodes
) {
240 parentChildNodeUuids
.add(parentChildNode
.getUuid());
242 parentChildNodeUuids
.containsAll(childNodeUuids
);
247 @DataSet("TaxonNavigatorTest.testDeleteClassificationWithDeleteChildren.xml")
248 public void testDeleteClassificationWithDeleteChildren() throws ExecutionException
{
249 UUID classificationUuid
= UUID
.fromString("0c2b5d25-7b15-4401-8b51-dd4be0ee5cab");
250 Classification classification
= classificationService
.load(classificationUuid
);
251 TaxonNode rootNode
= classification
.getRootNode();
252 Set
<ITaxonTreeNode
> nodes
= new HashSet
<ITaxonTreeNode
>();
253 nodes
.add(classification
);
255 TaxonNodeDeletionConfigurator configNodes
= new TaxonNodeDeletionConfigurator();
256 configNodes
.setChildHandling(ChildHandling
.DELETE
);
257 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
258 config
.setTaxonNodeConfig(configNodes
);
260 operation
= new RemotingDeleteTaxonNodeOperation(sessionOwner
,
264 operation
.execute(monitor
, info
);
266 Classification reloadedClassification
= classificationService
.load(classification
.getUuid());
267 Assert
.assertNull(reloadedClassification
);
268 TaxonNode reloadedRootNode
= taxonNodeService
.load(rootNode
.getUuid());
269 Assert
.assertNull(reloadedRootNode
);