2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.model
.term
;
11 import static org
.junit
.Assert
.assertEquals
;
12 import static org
.junit
.Assert
.assertNotSame
;
14 import java
.util
.List
;
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
;
21 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
22 import eu
.etaxonomy
.cdm
.test
.unit
.EntityTestBase
;
24 public class TermTreeTest
extends EntityTestBase
{
26 @SuppressWarnings("unused")
27 private static final Logger logger
= LogManager
.getLogger(TermTreeTest
.class);
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
;
36 public void setUp() throws Exception
{
37 testTree
= TermTree
.NewFeatureInstance();
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());
46 // public void testSetRoot(){
47 // testTree.setRoot(node2);
48 // assertNotNull(testTree.getRoot());
49 // assertEquals(testTree.getRoot(), node2);
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
);
60 @SuppressWarnings("unused")
62 public void testTermTreeTermType(){
65 Assert
.fail("Term type must never be null");
66 } catch (Exception e
) {
72 public void testClone(){
73 TermNode
<Feature
> node21
= node1
.addChild(Feature
.ADDITIONAL_PUBLICATION(), 1);
74 TermTree
<Feature
> clone
= testTree
.clone();
76 assertEquals (clone
.getRoot().getTerm(), testTree
.getRoot().getTerm());
77 assertNotSame(clone
.getRoot(), testTree
.getRoot());
78 List
<TermNode
<Feature
>> children
= clone
.getRootChildren();
80 assertEquals(children
.get(0).getTerm(), node1
.getTerm());
81 assertNotSame(children
.get(0), node1
);
82 children
= children
.get(0).getChildNodes();
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
);