1
|
package eu.etaxonomy.cdm.model.term;
|
2
|
|
3
|
|
4
|
|
5
|
import static org.junit.Assert.assertEquals;
|
6
|
import static org.junit.Assert.assertNotSame;
|
7
|
|
8
|
import java.util.List;
|
9
|
|
10
|
import org.apache.log4j.Logger;
|
11
|
import org.junit.Before;
|
12
|
import org.junit.BeforeClass;
|
13
|
import org.junit.Test;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.description.Feature;
|
16
|
import eu.etaxonomy.cdm.model.term.DefaultTermInitializer;
|
17
|
import eu.etaxonomy.cdm.model.term.FeatureNode;
|
18
|
import eu.etaxonomy.cdm.model.term.FeatureTree;
|
19
|
|
20
|
public class FeatureTreeTest {
|
21
|
@SuppressWarnings("unused")
|
22
|
private static final Logger logger = Logger.getLogger(FeatureTreeTest.class);
|
23
|
|
24
|
private FeatureTree testTree;
|
25
|
private FeatureNode node1;
|
26
|
private FeatureNode node2;
|
27
|
private FeatureNode node3;
|
28
|
private FeatureNode node4;
|
29
|
|
30
|
@BeforeClass
|
31
|
public static void setUpBeforeClass() {
|
32
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
33
|
vocabularyStore.initialize();
|
34
|
}
|
35
|
|
36
|
/**
|
37
|
* @throws java.lang.Exception
|
38
|
*/
|
39
|
@Before
|
40
|
public void setUp() throws Exception {
|
41
|
testTree = FeatureTree.NewInstance();
|
42
|
|
43
|
node1 = FeatureNode.NewInstance(Feature.ANATOMY());
|
44
|
node2 = FeatureNode.NewInstance(Feature.BIOLOGY_ECOLOGY());
|
45
|
node3 = FeatureNode.NewInstance(Feature.DESCRIPTION());
|
46
|
node4 = FeatureNode.NewInstance(Feature.DISCUSSION());
|
47
|
|
48
|
testTree.getRoot().addChild(node1);
|
49
|
node1.addChild(node2);
|
50
|
node2.addChild(node3);
|
51
|
node3.addChild(node4);
|
52
|
|
53
|
|
54
|
|
55
|
}
|
56
|
// @Test
|
57
|
// public void testSetRoot(){
|
58
|
// testTree.setRoot(node2);
|
59
|
// assertNotNull(testTree.getRoot());
|
60
|
// assertEquals(testTree.getRoot(), node2);
|
61
|
// }
|
62
|
@Test
|
63
|
public void testAddChild(){
|
64
|
FeatureNode node21 = FeatureNode.NewInstance();
|
65
|
node21.setTerm(Feature.ANATOMY());
|
66
|
node1.addChild(node21, 1);
|
67
|
|
68
|
assertEquals(node1.getChildNodes().size(), 2);
|
69
|
assertEquals(node1.getChildNodes().get(1), node21);
|
70
|
|
71
|
|
72
|
assertEquals(node21.getParent(), node1);
|
73
|
|
74
|
|
75
|
}
|
76
|
@Test
|
77
|
public void testClone(){
|
78
|
FeatureNode node21 = FeatureNode.NewInstance();
|
79
|
node21.setTerm(Feature.ADDITIONAL_PUBLICATION());
|
80
|
node1.addChild(node21, 1);
|
81
|
FeatureTree clone = (FeatureTree) testTree.clone();
|
82
|
assertEquals (clone.getRoot().getTerm(), testTree.getRoot().getTerm());
|
83
|
assertNotSame(clone.getRoot(), testTree.getRoot());
|
84
|
List<FeatureNode> children = clone.getRootChildren();
|
85
|
|
86
|
|
87
|
assertEquals(children.get(0).getTerm(), node1.getTerm());
|
88
|
assertNotSame(children.get(0), node1);
|
89
|
children = children.get(0).getChildNodes();
|
90
|
|
91
|
assertEquals(children.get(0).getTerm(), node2.getTerm());
|
92
|
assertNotSame(children.get(0), node2);
|
93
|
assertEquals(children.get(1).getTerm(), node21.getTerm());
|
94
|
assertNotSame(children.get(1), node21);
|
95
|
assertEquals(children.get(0).getChildAt(0).getTerm(), node3.getTerm());
|
96
|
assertNotSame(children.get(0).getChildAt(0), node3);
|
97
|
}
|
98
|
|
99
|
|
100
|
}
|