1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 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
|
|
11
|
package eu.etaxonomy.cdm.api.service;
|
12
|
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.junit.Assert;
|
16
|
import org.junit.Before;
|
17
|
import org.junit.Test;
|
18
|
import org.unitils.dbunit.annotation.DataSet;
|
19
|
import org.unitils.spring.annotation.SpringApplicationContext;
|
20
|
import org.unitils.spring.annotation.SpringBeanByType;
|
21
|
|
22
|
import eu.etaxonomy.cdm.model.common.ITreeNode;
|
23
|
import eu.etaxonomy.cdm.model.description.Feature;
|
24
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
25
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
26
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
27
|
|
28
|
/**
|
29
|
* @author a.mueller
|
30
|
* @created 2013-09-28
|
31
|
*/
|
32
|
//@SpringApplicationContext("file:./target/test-classes/eu/etaxonomy/cdm/applicationContext-test.xml")
|
33
|
public class FeatureNodeServiceImplTest extends CdmTransactionalIntegrationTest{
|
34
|
|
35
|
private static final String sep = ITreeNode.separator;
|
36
|
private static final String pref = ITreeNode.treePrefix;
|
37
|
|
38
|
@SpringBeanByType
|
39
|
private IFeatureNodeService featureNodeService;
|
40
|
|
41
|
@SpringBeanByType
|
42
|
private IFeatureTreeService featureTreeService;
|
43
|
|
44
|
@SpringBeanByType
|
45
|
private ITermService termService;
|
46
|
|
47
|
|
48
|
// private static final UUID t2Uuid = UUID.fromString("55c3e41a-c629-40e6-aa6a-ff274ac6ddb1");
|
49
|
// private static final UUID t3Uuid = UUID.fromString("2659a7e0-ff35-4ee4-8493-b453756ab955");
|
50
|
private static final UUID featureTreeUuid = UUID.fromString("6c2bc8d9-ee62-4222-be89-4a8e31770878");
|
51
|
private static final UUID featureTree2Uuid = UUID.fromString("43d67247-936f-42a3-a739-bbcde372e334");
|
52
|
private static final UUID node2Uuid= UUID.fromString("484a1a77-689c-44be-8e65-347d835f47e8");
|
53
|
private static final UUID node3Uuid = UUID.fromString("2d41f0c2-b785-4f73-a436-cc2d5e93cc5b");
|
54
|
// private static final UUID node4Uuid = UUID.fromString("fdaec4bd-c78e-44df-ae87-28f18110968c");
|
55
|
private static final UUID node5Uuid = UUID.fromString("c4d5170a-7967-4dac-ab76-ae2019eefde5");
|
56
|
private static final UUID node6Uuid = UUID.fromString("b419ba5e-9c8b-449c-ad86-7abfca9a7340");
|
57
|
|
58
|
private Feature t1;
|
59
|
private Feature t2;
|
60
|
// private Synonym s1;
|
61
|
private FeatureNode node3;
|
62
|
private FeatureNode node2;
|
63
|
|
64
|
/**
|
65
|
* @throws java.lang.Exception
|
66
|
*/
|
67
|
@Before
|
68
|
public void setUp() throws Exception {
|
69
|
}
|
70
|
|
71
|
@Test
|
72
|
public final void testIndexCreatRoot() {
|
73
|
FeatureTree featureTree = FeatureTree.NewInstance();
|
74
|
featureTreeService.save(featureTree);
|
75
|
|
76
|
Feature feature = (Feature)termService.find(914);
|
77
|
FeatureNode newNode = FeatureNode.NewInstance(feature);
|
78
|
featureTree.getRoot().addChild(newNode);
|
79
|
|
80
|
featureTreeService.save(featureTree);
|
81
|
|
82
|
featureNodeService.saveOrUpdate(newNode);
|
83
|
|
84
|
commitAndStartNewTransaction(new String[]{"FeatureNode"});
|
85
|
newNode = featureNodeService.load(newNode.getUuid());
|
86
|
Assert.assertEquals("", sep + pref+featureTree.getId()+sep + featureTree.getRoot().getId()+ sep + newNode.getId() + sep, newNode.treeIndex());
|
87
|
}
|
88
|
|
89
|
|
90
|
@Test
|
91
|
@DataSet(value="FeatureNodeServiceImplTest-indexing.xml")
|
92
|
public final void testIndexCreateNode() {
|
93
|
Feature feature = (Feature)termService.find(914);
|
94
|
|
95
|
node2 = featureNodeService.load(node2Uuid);
|
96
|
String oldTreeIndex = node2.treeIndex();
|
97
|
|
98
|
FeatureNode newNode = FeatureNode.NewInstance(feature);
|
99
|
node2.addChild(newNode);
|
100
|
featureNodeService.saveOrUpdate(node2);
|
101
|
|
102
|
commitAndStartNewTransaction(new String[]{"FeatureNode"});
|
103
|
newNode = featureNodeService.load(newNode.getUuid());
|
104
|
Assert.assertEquals("", oldTreeIndex + newNode.getId() + sep, newNode.treeIndex());
|
105
|
}
|
106
|
|
107
|
|
108
|
@Test
|
109
|
@DataSet(value="FeatureNodeServiceImplTest-indexing.xml")
|
110
|
public final void testIndexMoveNode() {
|
111
|
//in feature tree
|
112
|
FeatureTree featureTree = featureTreeService.load(featureTreeUuid);
|
113
|
node2 = featureNodeService.load(node2Uuid);
|
114
|
node3 = featureNodeService.load(node3Uuid);
|
115
|
node3.addChild(node2);
|
116
|
featureNodeService.saveOrUpdate(node2);
|
117
|
commitAndStartNewTransaction(new String[]{"FeatureNode"});
|
118
|
FeatureNode node6 = featureNodeService.load(node6Uuid);
|
119
|
Assert.assertEquals("Node6 treeindex is not correct", node3.treeIndex() + "2#4#6#", node6.treeIndex());
|
120
|
|
121
|
//root of new feature tree
|
122
|
FeatureTree featureTree2 = featureTreeService.load(featureTree2Uuid);
|
123
|
node2 = featureNodeService.load(node2Uuid);
|
124
|
featureTree2.getRoot().addChild(node2);
|
125
|
featureNodeService.saveOrUpdate(node2);
|
126
|
commitAndStartNewTransaction(new String[]{"TaxonNode"});
|
127
|
node2 = featureNodeService.load(node2Uuid);
|
128
|
Assert.assertEquals("Node2 treeindex is not correct", "#t2#7#2#", node2.treeIndex());
|
129
|
node6 = featureNodeService.load(node6Uuid);
|
130
|
Assert.assertEquals("Node6 treeindex is not correct", "#t2#7#2#4#6#", node6.treeIndex());
|
131
|
|
132
|
//into new classification
|
133
|
node3 = featureNodeService.load(node3Uuid);
|
134
|
FeatureNode node5 = featureNodeService.load(node5Uuid);
|
135
|
node5.addChild(node3);
|
136
|
featureNodeService.saveOrUpdate(node5);
|
137
|
commitAndStartNewTransaction(new String[]{"TaxonNode"});
|
138
|
node3 = featureNodeService.load(node3Uuid);
|
139
|
Assert.assertEquals("Node3 treeindex is not correct", "#t2#7#2#5#3#", node3.treeIndex());
|
140
|
|
141
|
}
|
142
|
|
143
|
@Test //here we may have a test for testing delete of a node and attaching the children
|
144
|
//to its parents, however this depends on the way delete is implemented and therefore needs
|
145
|
//to wait until this is finally done
|
146
|
public final void testIndexDeleteNode() {
|
147
|
// node2 = taxonNodeService.load(node2Uuid);
|
148
|
// node2.getParent().deleteChildNode(node2);
|
149
|
//
|
150
|
// node5.addChildNode(node3, null, null);
|
151
|
// taxonNodeService.saveOrUpdate(node5);
|
152
|
// commitAndStartNewTransaction(new String[]{"TaxonNode"});
|
153
|
// node3 = taxonNodeService.load(node3Uuid);
|
154
|
// Assert.assertEquals("Node3 treeindex is not correct", "#t2#2#5#3#", node3.getTreeIndex());
|
155
|
}
|
156
|
|
157
|
|
158
|
|
159
|
|
160
|
|
161
|
}
|