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
.TaxonDeletionConfigurator
;
28 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonNodeDeletionConfigurator
;
29 import eu
.etaxonomy
.cdm
.api
.service
.config
.NodeDeletionConfigurator
.ChildHandling
;
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
.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
;
49 public class TaxonNavigatorTest
extends BaseOperationTest
{
51 private static final Logger logger
= Logger
.getLogger(TaxonNameEditorTest
.class);
53 ITaxonNodeService taxonNodeService
= getRemoteApplicationController().getTaxonNodeService();
54 ITaxonService taxonService
= getRemoteApplicationController().getTaxonService();
55 IClassificationService classificationService
= getRemoteApplicationController().getClassificationService();
57 Language english
= Language
.getLanguageFromUuid(Language
.uuidEnglish
);
62 public void testChangeAcceptedTaxonToSynonym() throws ExecutionException
{
65 UUID oldTaxonNodeNodeUuid
= UUID
.fromString("b85b5b78-6760-409f-ac91-bb89e95ff2a1");
66 UUID newAcceptedTaxonNodeUuid
= UUID
.fromString("6ad8e9e2-f5f6-41ad-aa30-f62a903650db");
68 TaxonNode oldTaxonNode
= taxonNodeService
.load(oldTaxonNodeNodeUuid
);
69 TaxonNameBase name
= oldTaxonNode
.getTaxon().getName();
72 TaxonNode newAcceptedTaxonNode
= taxonNodeService
.load(newAcceptedTaxonNodeUuid
);
73 int countTargetSynonyms
= newAcceptedTaxonNode
.getTaxon().getSynonyms().size();
74 sessionOwner
.addExpectedUpdatedObject(oldTaxonNode
.getParent());
75 sessionOwner
.addExpectedUpdatedObject(newAcceptedTaxonNode
);
77 operation
= new RemotingChangeAcceptedTaxonToSynonymOperation(sessionOwner
,
79 oldTaxonNode
.getUuid(),
80 newAcceptedTaxonNode
.getUuid());
81 operation
.execute(monitor
, info
);
82 newAcceptedTaxonNode
= taxonNodeService
.load(newAcceptedTaxonNodeUuid
);
83 oldTaxonNode
= taxonNodeService
.load(oldTaxonNodeNodeUuid
);
84 Assert
.assertNull(oldTaxonNode
);
85 Assert
.assertEquals(countTargetSynonyms
+ 1,newAcceptedTaxonNode
.getTaxon().getSynonyms().size());
86 Assert
.assertEquals(name
, newAcceptedTaxonNode
.getTaxon().getSynonyms().iterator().next().getName());
92 public void testMoveTaxon() throws ExecutionException
{
94 UUID taxonNodeToMoveUuid
= UUID
.fromString("b8439f51-6b96-445a-b401-7a836ba1cf58");
95 UUID newParentTreeNodeUuid
= UUID
.fromString("2f05d429-632d-4230-b9cb-70299360b470");
96 boolean moveToParentNode
= true;
98 TaxonNode taxonNodeToMove
= taxonNodeService
.load(taxonNodeToMoveUuid
);
99 TaxonNode oldParent
= taxonNodeToMove
.getParent();
100 sessionOwner
.addExpectedUpdatedObject(oldParent
);
101 int childCount
= oldParent
.getCountChildren();
102 TaxonNode newParentTreeNode
= taxonNodeService
.load(newParentTreeNodeUuid
);
103 sessionOwner
.addExpectedUpdatedObject(newParentTreeNode
);
104 operation
= new RemotingMoveTaxonOperation(sessionOwner
,
106 taxonNodeToMove
.getUuid(),
107 newParentTreeNode
.getUuid(),
109 operation
.execute(monitor
, info
);
110 Assert
.assertEquals(childCount
-1, oldParent
.getCountChildren());
111 Assert
.assertTrue(!oldParent
.getChildNodes().contains(taxonNodeToMove
));
112 Assert
.assertTrue(newParentTreeNode
.getChildNodes().contains(taxonNodeToMove
));
116 public void testMoveFactualData() throws ExecutionException
{
117 UUID sourceTaxonUuid
= UUID
.fromString("e40854d7-143f-4054-b229-6ed4cedb4bff");
118 UUID targetTaxonUuid
= UUID
.fromString("b8402dc4-5050-4882-a147-01b71e0e47d6");
120 Taxon sourceTaxon
= CdmBase
.deproxy(taxonService
.load(sourceTaxonUuid
), Taxon
.class);
121 Set
<TaxonDescription
> sourceDescriptions
= new HashSet(sourceTaxon
.getDescriptions());
122 sessionOwner
.addExpectedUpdatedObject(sourceTaxon
);
124 Taxon targetTaxon
= CdmBase
.deproxy(taxonService
.load(targetTaxonUuid
), Taxon
.class);
125 int countTargetDescriptions
= targetTaxon
.getDescriptions().size();
126 sessionOwner
.addExpectedUpdatedObject(targetTaxon
);
128 operation
= new RemotingMoveFactualDataOperation(sessionOwner
,
132 operation
.execute(monitor
, info
);
133 Assert
.assertEquals(0, sourceTaxon
.getDescriptions().size());
134 Assert
.assertEquals(sourceDescriptions
.size() + countTargetDescriptions
, targetTaxon
.getDescriptions().size());
135 Assert
.assertTrue(targetTaxon
.getDescriptions().containsAll(sourceDescriptions
));
139 public void testDeleteTaxonNodeWithDeleteChildren() throws ExecutionException
{
140 UUID taxonNodeUuid
= UUID
.fromString("2f05d429-632d-4230-b9cb-70299360b470");
141 TaxonNode taxonNode
= taxonNodeService
.load(taxonNodeUuid
);
142 List
<TaxonNode
> childNodes
= taxonNode
.getChildNodes();
143 List
<UUID
> childNodeUuids
= new ArrayList
<UUID
>();
144 for(TaxonNode childNode
: childNodes
) {
145 childNodeUuids
.add(childNode
.getUuid());
147 Assert
.assertTrue(taxonNode
.getCountChildren() > 0);
149 Set
<ITaxonTreeNode
> nodes
= new HashSet
<ITaxonTreeNode
>();
150 nodes
.add(taxonNode
);
152 TaxonNodeDeletionConfigurator configNodes
= new TaxonNodeDeletionConfigurator();
153 configNodes
.setChildHandling(ChildHandling
.DELETE
);
154 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
155 config
.setTaxonNodeConfig(configNodes
);
157 sessionOwner
.addExpectedUpdatedObject(taxonNode
.getParent());
159 operation
= new RemotingDeleteTaxonNodeOperation(sessionOwner
,
163 operation
.execute(monitor
, info
);
164 TaxonNode reloadedNode
= taxonNodeService
.load(taxonNode
.getUuid());
165 Assert
.assertNull(reloadedNode
);
166 for(UUID childNodeUuid
: childNodeUuids
) {
167 TaxonNode reloadedChildNode
= taxonNodeService
.load(childNodeUuid
);
168 Assert
.assertNull(reloadedChildNode
);
173 public void testDeleteTaxonNodes() throws ExecutionException
{
174 UUID taxonNode1Uuid
= UUID
.fromString("99f03b56-67cd-4e01-9ceb-2362d48f9d07");
175 UUID taxonNode2Uuid
= UUID
.fromString("91698cec-615f-4472-9002-feda1a6acded");
176 UUID taxonNode3Uuid
= UUID
.fromString("4fe03763-b966-4361-8334-352f6f777588");
178 TaxonNode taxonNode1
= taxonNodeService
.load(taxonNode1Uuid
);
179 TaxonNode taxonNode2
= taxonNodeService
.load(taxonNode2Uuid
);
180 TaxonNode taxonNode3
= taxonNodeService
.load(taxonNode3Uuid
);
182 Set
<ITaxonTreeNode
> nodes
= new HashSet
<ITaxonTreeNode
>();
183 nodes
.add(taxonNode1
);
184 nodes
.add(taxonNode2
);
185 nodes
.add(taxonNode3
);
187 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
190 sessionOwner
.addExpectedUpdatedObject(taxonNode1
.getParent());
191 sessionOwner
.addExpectedUpdatedObject(taxonNode2
.getParent());
192 sessionOwner
.addExpectedUpdatedObject(taxonNode3
.getParent());
193 operation
= new RemotingDeleteTaxonNodeOperation(sessionOwner
,
197 operation
.execute(monitor
, info
);
198 TaxonNode reloadedNode1
= taxonNodeService
.load(taxonNode1
.getUuid());
199 TaxonNode reloadedNode2
= taxonNodeService
.load(taxonNode2
.getUuid());
200 TaxonNode reloadedNode3
= taxonNodeService
.load(taxonNode3
.getUuid());
201 Assert
.assertNull(reloadedNode1
);
202 Assert
.assertNull(reloadedNode2
);
203 Assert
.assertNull(reloadedNode3
);
208 public void testDeleteTaxonNodeWithMovingChildrenToParentNode() throws ExecutionException
{
209 UUID taxonNodeUuid
= UUID
.fromString("2f05d429-632d-4230-b9cb-70299360b470");
210 TaxonNode taxonNode
= taxonNodeService
.load(taxonNodeUuid
);
211 TaxonNode parentTaxonNode
= taxonNode
.getParent();
212 List
<TaxonNode
> childNodes
= taxonNode
.getChildNodes();
213 List
<UUID
> childNodeUuids
= new ArrayList
<UUID
>();
214 for(TaxonNode childNode
: childNodes
) {
215 childNodeUuids
.add(childNode
.getUuid());
217 Assert
.assertTrue(taxonNode
.getCountChildren() > 0);
219 Set
<ITaxonTreeNode
> nodes
= new HashSet
<ITaxonTreeNode
>();
220 nodes
.add(taxonNode
);
222 TaxonNodeDeletionConfigurator configNodes
= new TaxonNodeDeletionConfigurator();
223 configNodes
.setChildHandling(ChildHandling
.MOVE_TO_PARENT
);
224 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
225 config
.setTaxonNodeConfig(configNodes
);
227 sessionOwner
.addExpectedUpdatedObject(taxonNode
.getParent());
228 operation
= new RemotingDeleteTaxonNodeOperation(sessionOwner
,
232 operation
.execute(monitor
, info
);
233 TaxonNode reloadedNode
= taxonNodeService
.load(taxonNode
.getUuid());
234 Assert
.assertNull(reloadedNode
);
235 List
<TaxonNode
> parentChildNodes
= parentTaxonNode
.getChildNodes();
236 List
<UUID
> parentChildNodeUuids
= new ArrayList
<UUID
>();
237 for(TaxonNode parentChildNode
: parentChildNodes
) {
238 parentChildNodeUuids
.add(parentChildNode
.getUuid());
240 parentChildNodeUuids
.containsAll(childNodeUuids
);
245 @DataSet("TaxonNavigatorTest.testDeleteClassificationWithDeleteChildren.xml")
246 public void testDeleteClassificationWithDeleteChildren() throws ExecutionException
{
247 UUID classificationUuid
= UUID
.fromString("0c2b5d25-7b15-4401-8b51-dd4be0ee5cab");
248 Classification classification
= classificationService
.load(classificationUuid
);
249 TaxonNode rootNode
= classification
.getRootNode();
250 Set
<ITaxonTreeNode
> nodes
= new HashSet
<ITaxonTreeNode
>();
251 nodes
.add(classification
);
253 TaxonNodeDeletionConfigurator configNodes
= new TaxonNodeDeletionConfigurator();
254 configNodes
.setChildHandling(ChildHandling
.DELETE
);
255 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
256 config
.setTaxonNodeConfig(configNodes
);
258 operation
= new RemotingDeleteTaxonNodeOperation(sessionOwner
,
262 operation
.execute(monitor
, info
);
264 Classification reloadedClassification
= classificationService
.load(classification
.getUuid());
265 Assert
.assertNull(reloadedClassification
);
266 TaxonNode reloadedRootNode
= taxonNodeService
.load(rootNode
.getUuid());
267 Assert
.assertNull(reloadedRootNode
);