1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.model.term;
|
10
|
|
11
|
import static org.junit.Assert.assertEquals;
|
12
|
import static org.junit.Assert.assertNotSame;
|
13
|
|
14
|
import java.util.List;
|
15
|
|
16
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
17
|
import org.junit.Assert;
|
18
|
import org.junit.Before;
|
19
|
import org.junit.Test;
|
20
|
|
21
|
import eu.etaxonomy.cdm.model.description.Feature;
|
22
|
import eu.etaxonomy.cdm.test.unit.EntityTestBase;
|
23
|
|
24
|
public class TermTreeTest extends EntityTestBase {
|
25
|
|
26
|
@SuppressWarnings("unused")
|
27
|
private static final Logger logger = LogManager.getLogger(TermTreeTest.class);
|
28
|
|
29
|
private TermTree<Feature> testTree;
|
30
|
private TermNode<Feature> node1;
|
31
|
private TermNode<Feature> node2;
|
32
|
private TermNode<Feature> node3;
|
33
|
private TermNode<Feature> node4;
|
34
|
|
35
|
@Before
|
36
|
public void setUp() throws Exception {
|
37
|
testTree = TermTree.NewFeatureInstance();
|
38
|
|
39
|
node1 = testTree.getRoot().addChild(Feature.ANATOMY());
|
40
|
node2 = node1.addChild(Feature.BIOLOGY_ECOLOGY());
|
41
|
node3 = node2.addChild(Feature.DESCRIPTION());
|
42
|
node4 = node3.addChild(Feature.DISCUSSION());
|
43
|
}
|
44
|
|
45
|
// @Test
|
46
|
// public void testSetRoot(){
|
47
|
// testTree.setRoot(node2);
|
48
|
// assertNotNull(testTree.getRoot());
|
49
|
// assertEquals(testTree.getRoot(), node2);
|
50
|
// }
|
51
|
|
52
|
@Test
|
53
|
public void testAddChild(){
|
54
|
TermNode<Feature> node21 = node1.addChild(Feature.ANATOMY(), 1);
|
55
|
assertEquals(node1.getChildNodes().size(), 2);
|
56
|
assertEquals(node1.getChildNodes().get(1), node21);
|
57
|
assertEquals(node21.getParent(), node1);
|
58
|
}
|
59
|
|
60
|
@SuppressWarnings("unused")
|
61
|
@Test
|
62
|
public void testTermTreeTermType(){
|
63
|
try {
|
64
|
new TermTree<>(null);
|
65
|
Assert.fail("Term type must never be null");
|
66
|
} catch (Exception e) {
|
67
|
//OK
|
68
|
}
|
69
|
}
|
70
|
|
71
|
@Test
|
72
|
public void testClone(){
|
73
|
TermNode<Feature> node21 = node1.addChild(Feature.ADDITIONAL_PUBLICATION(), 1);
|
74
|
TermTree<Feature> clone = testTree.clone();
|
75
|
|
76
|
assertEquals (clone.getRoot().getTerm(), testTree.getRoot().getTerm());
|
77
|
assertNotSame(clone.getRoot(), testTree.getRoot());
|
78
|
List<TermNode<Feature>> children = clone.getRootChildren();
|
79
|
|
80
|
assertEquals(children.get(0).getTerm(), node1.getTerm());
|
81
|
assertNotSame(children.get(0), node1);
|
82
|
children = children.get(0).getChildNodes();
|
83
|
|
84
|
assertEquals(children.get(0).getTerm(), node2.getTerm());
|
85
|
assertNotSame(children.get(0), node2);
|
86
|
assertEquals(children.get(1).getTerm(), node21.getTerm());
|
87
|
assertNotSame(children.get(1), node21);
|
88
|
assertEquals(children.get(0).getChildAt(0).getTerm(), node3.getTerm());
|
89
|
assertNotSame(children.get(0).getChildAt(0), node3);
|
90
|
}
|
91
|
}
|