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