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.cdm.model;
|
11
|
|
12
|
import java.util.HashSet;
|
13
|
import java.util.Set;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
import org.eclipse.core.commands.ExecutionException;
|
18
|
import org.junit.Assert;
|
19
|
import org.junit.Test;
|
20
|
import org.unitils.dbunit.annotation.DataSet;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
23
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
24
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
25
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
26
|
import eu.etaxonomy.cdm.model.common.Language;
|
27
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
28
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
29
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
30
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
31
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingChangeAcceptedTaxonToSynonymOperation;
|
32
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveFactualDataOperation;
|
33
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveTaxonOperation;
|
34
|
import eu.etaxonomy.taxeditor.operations.BaseOperationTest;
|
35
|
|
36
|
/**
|
37
|
* @author cmathew
|
38
|
* @date 9 Mar 2015
|
39
|
*
|
40
|
*/
|
41
|
@DataSet
|
42
|
public class TaxonNavigatorTest extends BaseOperationTest {
|
43
|
|
44
|
private static final Logger logger = Logger.getLogger(TaxonNameEditorTest.class);
|
45
|
|
46
|
ITaxonNodeService taxonNodeService = getRemoteApplicationController().getTaxonNodeService();
|
47
|
ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
|
48
|
IClassificationService classificationService = getRemoteApplicationController().getClassificationService();
|
49
|
|
50
|
Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
|
51
|
|
52
|
|
53
|
|
54
|
@Test
|
55
|
public void testChangeAcceptedTaxonToSynonym() throws ExecutionException {
|
56
|
|
57
|
|
58
|
UUID oldTaxonNodeNodeUuid = UUID.fromString("b85b5b78-6760-409f-ac91-bb89e95ff2a1");
|
59
|
UUID newAcceptedTaxonNodeUuid = UUID.fromString("6ad8e9e2-f5f6-41ad-aa30-f62a903650db");
|
60
|
|
61
|
TaxonNode oldTaxonNode = taxonNodeService.load(oldTaxonNodeNodeUuid);
|
62
|
TaxonNameBase name = oldTaxonNode.getTaxon().getName();
|
63
|
|
64
|
|
65
|
TaxonNode newAcceptedTaxonNode = taxonNodeService.load(newAcceptedTaxonNodeUuid);
|
66
|
int countTargetSynonyms = newAcceptedTaxonNode.getTaxon().getSynonyms().size();
|
67
|
sessionOwner.addExpectedUpdatedObject(oldTaxonNode.getParent());
|
68
|
|
69
|
|
70
|
operation = new RemotingChangeAcceptedTaxonToSynonymOperation(sessionOwner,
|
71
|
false,
|
72
|
oldTaxonNode.getUuid(),
|
73
|
newAcceptedTaxonNode.getUuid());
|
74
|
operation.execute(monitor, info);
|
75
|
newAcceptedTaxonNode = taxonNodeService.load(newAcceptedTaxonNodeUuid);
|
76
|
sessionOwner.addExpectedUpdatedObject(newAcceptedTaxonNode);
|
77
|
|
78
|
oldTaxonNode = taxonNodeService.load(oldTaxonNodeNodeUuid);
|
79
|
Assert.assertNull(oldTaxonNode);
|
80
|
Assert.assertEquals(countTargetSynonyms + 1,newAcceptedTaxonNode.getTaxon().getSynonyms().size());
|
81
|
Assert.assertEquals(name, newAcceptedTaxonNode.getTaxon().getSynonyms().iterator().next().getName());
|
82
|
|
83
|
|
84
|
}
|
85
|
|
86
|
@Test
|
87
|
public void testMoveTaxon() throws ExecutionException {
|
88
|
|
89
|
UUID taxonNodeToMoveUuid = UUID.fromString("b8439f51-6b96-445a-b401-7a836ba1cf58");
|
90
|
UUID newParentTreeNodeUuid = UUID.fromString("2f05d429-632d-4230-b9cb-70299360b470");
|
91
|
boolean moveToParentNode = true;
|
92
|
|
93
|
TaxonNode taxonNodeToMove = taxonNodeService.load(taxonNodeToMoveUuid);
|
94
|
TaxonNode oldParent = taxonNodeToMove.getParent();
|
95
|
sessionOwner.addExpectedUpdatedObject(oldParent);
|
96
|
int childCount = oldParent.getCountChildren();
|
97
|
TaxonNode newParentTreeNode = taxonNodeService.load(newParentTreeNodeUuid);
|
98
|
sessionOwner.addExpectedUpdatedObject(newParentTreeNode);
|
99
|
operation = new RemotingMoveTaxonOperation(sessionOwner,
|
100
|
false,
|
101
|
taxonNodeToMove.getUuid(),
|
102
|
newParentTreeNode.getUuid(),
|
103
|
moveToParentNode);
|
104
|
operation.execute(monitor, info);
|
105
|
Assert.assertEquals(childCount-1, oldParent.getCountChildren());
|
106
|
Assert.assertTrue(!oldParent.getChildNodes().contains(taxonNodeToMove));
|
107
|
Assert.assertTrue(newParentTreeNode.getChildNodes().contains(taxonNodeToMove));
|
108
|
}
|
109
|
|
110
|
@Test
|
111
|
public void testMoveFactualData() throws ExecutionException {
|
112
|
UUID sourceTaxonUuid = UUID.fromString("e40854d7-143f-4054-b229-6ed4cedb4bff");
|
113
|
UUID targetTaxonUuid = UUID.fromString("b8402dc4-5050-4882-a147-01b71e0e47d6");
|
114
|
|
115
|
Taxon sourceTaxon = CdmBase.deproxy(taxonService.load(sourceTaxonUuid), Taxon.class);
|
116
|
Set<TaxonDescription> sourceDescriptions = new HashSet(sourceTaxon.getDescriptions());
|
117
|
sessionOwner.addExpectedUpdatedObject(sourceTaxon);
|
118
|
|
119
|
Taxon targetTaxon = CdmBase.deproxy(taxonService.load(targetTaxonUuid), Taxon.class);
|
120
|
int countTargetDescriptions = targetTaxon.getDescriptions().size();
|
121
|
sessionOwner.addExpectedUpdatedObject(targetTaxon);
|
122
|
|
123
|
operation = new RemotingMoveFactualDataOperation(sessionOwner,
|
124
|
false,
|
125
|
sourceTaxonUuid,
|
126
|
targetTaxonUuid);
|
127
|
operation.execute(monitor, info);
|
128
|
Assert.assertEquals(0, sourceTaxon.getDescriptions().size());
|
129
|
Assert.assertEquals(sourceDescriptions.size() + countTargetDescriptions, targetTaxon.getDescriptions().size());
|
130
|
Assert.assertTrue(targetTaxon.getDescriptions().containsAll(sourceDescriptions));
|
131
|
}
|
132
|
|
133
|
|
134
|
}
|