Project

General

Profile

Download (2.66 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.cdm.model.description;
2

    
3

    
4

    
5
import static org.junit.Assert.assertEquals;
6
import static org.junit.Assert.assertNotNull;
7
import static org.junit.Assert.assertNotSame;
8

    
9
import java.util.List;
10

    
11
import org.apache.log4j.Logger;
12
import org.junit.Before;
13
import org.junit.BeforeClass;
14
import org.junit.Test;
15

    
16
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
17

    
18
public class FeatureTreeTest {
19
	@SuppressWarnings("unused")
20
	private static final Logger logger = Logger.getLogger(FeatureTreeTest.class);
21

    
22
	private FeatureTree testTree;
23
	private FeatureNode node1;
24
	private FeatureNode node2;
25
	private FeatureNode node3;
26
	private FeatureNode node4;
27

    
28
	@BeforeClass
29
	public static void setUpBeforeClass() {
30
		DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
31
		vocabularyStore.initialize();
32
	}
33

    
34
	/**
35
	 * @throws java.lang.Exception
36
	 */
37
	@Before
38
	public void setUp() throws Exception {
39
		testTree = FeatureTree.NewInstance();
40
		node1 = FeatureNode.NewInstance();
41
		node1.setFeature(Feature.ANATOMY());
42
		node2 = FeatureNode.NewInstance();
43
		node2.setFeature(Feature.BIOLOGY_ECOLOGY());
44
		node3 = FeatureNode.NewInstance();
45
		node3.setFeature(Feature.DESCRIPTION());
46
		node4 = FeatureNode.NewInstance();
47
		node4.setFeature(Feature.DISCUSSION());
48
		
49
		testTree.setRoot(node1);
50
		node1.addChild(node2);
51
		node2.addChild(node3);
52
		node3.addChild(node4);
53
		
54
		
55
		
56
	}
57
	@Test
58
	public void testSetRoot(){
59
		testTree.setRoot(node2);
60
		assertNotNull(testTree.getRoot());
61
		assertEquals(testTree.getRoot(), node2);
62
	}
63
	@Test
64
	public void testAddChild(){
65
		FeatureNode node21 = FeatureNode.NewInstance();
66
		node21.setFeature(Feature.ANATOMY());
67
		node1.addChild(node21, 1);
68

    
69
		assertEquals(node1.getChildNodes().size(), 2);
70
		assertEquals(node1.getChildNodes().get(1), node21);
71

    
72

    
73
		assertEquals(node21.getParent(), node1);
74

    
75

    
76
	}
77
	@Test
78
	public void testClone(){
79
		FeatureNode node21 = FeatureNode.NewInstance();
80
		node21.setFeature(Feature.ADDITIONAL_PUBLICATION());
81
		node1.addChild(node21, 1);
82
		FeatureTree clone = (FeatureTree) testTree.clone();
83
		assertEquals (clone.getRoot().getFeature(), testTree.getRoot().getFeature());
84
		assertNotSame(clone.getRoot(), testTree.getRoot());
85
		List<FeatureNode> children = clone.getRootChildren();
86
		
87
		assertEquals(children.get(0).getFeature(), node2.getFeature());
88
		assertNotSame(children.get(0), node2);
89
		assertEquals(children.get(1).getFeature(), node21.getFeature());
90
		assertNotSame(children.get(1), node21);
91
		assertEquals(children.get(0).getChildAt(0).getFeature(), node3.getFeature());
92
		assertNotSame(children.get(0).getChildAt(0), node3);
93
	}
94

    
95

    
96
}
(3-3/10)