Project

General

Profile

Download (3.57 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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.description;
10

    
11
import static org.junit.Assert.assertNotNull;
12
import static org.junit.Assert.assertNotSame;
13
import static org.junit.Assert.assertTrue;
14

    
15
import java.io.PrintStream;
16

    
17
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
18
import org.junit.Assert;
19
import org.junit.Before;
20
import org.junit.Test;
21

    
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23
import eu.etaxonomy.cdm.test.unit.EntityTestBase;
24

    
25
public class PolytomousKeyTest extends EntityTestBase {
26

    
27
	private static Logger logger = LogManager.getLogger(PolytomousKeyTest.class);
28

    
29
	private PolytomousKey key1;
30
	private Taxon taxon1;
31

    
32
	@Before
33
	public void setUp() throws Exception {
34
		key1 = PolytomousKey.NewInstance();
35
		key1.setTitleCache("My Test Key", true);
36
		PolytomousKeyNode root = key1.getRoot();
37
		root.setQuestion(KeyStatement.NewInstance("Is this Aus bus?"));
38
		// child1
39
		taxon1 = Taxon.NewInstance(null, null);
40
		taxon1.setTitleCache("Aus bus L.", true);
41
		PolytomousKeyNode child1 = PolytomousKeyNode.NewInstance("Yes", null,
42
				taxon1, null);
43
		Feature feature1 = Feature.NewInstance(null, "Leaf", null);
44
		child1.setFeature(feature1);
45
		root.addChild(child1);
46

    
47
		// child2
48
		Taxon taxon2 = Taxon.NewInstance(null, null);
49
		taxon2.setTitleCache("Cus dus Mill.", true);
50
		PolytomousKeyNode child2 = PolytomousKeyNode.NewInstance("No");
51
		child2.setTaxon(taxon2);
52
		root.addChild(child2);
53
		// child3
54
		Taxon taxon3 = Taxon.NewInstance(null, null);
55
		taxon3.setTitleCache("Cus dus subs. rus L.", true);
56
		PolytomousKeyNode child3 = PolytomousKeyNode
57
				.NewInstance("Long and wide");
58
		child3.setTaxon(taxon3);
59
		child1.addChild(child3);
60
		// child4
61
		Taxon taxon4 = Taxon.NewInstance(null, null);
62
		taxon4.setTitleCache("Cus dus subs. zus L.", true);
63
		PolytomousKeyNode child4 = PolytomousKeyNode
64
				.NewInstance("Small and narrow");
65
		child4.setTaxon(taxon4);
66
		child1.addChild(child4);
67

    
68
		PolytomousKey key2 = PolytomousKey.NewTitledInstance("Second Key");
69
		child3.setSubkey(key2);
70

    
71
		child4.setOtherNode(key2.getRoot());
72

    
73
	}
74

    
75
	// ********************* Tests
76
	// *******************************************************/
77

    
78
	@Test
79
	public void testNewInstance() {
80
		PolytomousKey newKey = PolytomousKey.NewInstance();
81
		Assert.assertNotNull(newKey);
82
	}
83

    
84
	@Test
85
	public void testNewTitledInstance() {
86
		logger.warn("testNewTitledInstance Not yet implemented");
87
	}
88

    
89
	@Test
90
	public void testPolytomousKey() {
91
		PolytomousKey newKey = new PolytomousKey();
92
		Assert.assertNotNull(newKey);
93
	}
94

    
95
	@Test
96
	public void testPrint() {
97
		PrintStream stream = null;
98
		String strKey = key1.print(stream);
99
//		System.out.println(strKey);
100
		Assert.assertEquals(
101
				"",
102
				"My Test Key\n"
103
				+ "  1. Is this Aus bus?\n"
104
				+ "    a) Yes ... 2, Aus bus L.\n"
105
				+ "    b) No ... Cus dus Mill.\n"
106
				+ "  2. Leaf\n"
107
				+ "    a) Long and wide ... Cus dus subs. rus L., Second Key\n"
108
				+ "    b) Small and narrow ... Cus dus subs. zus L., Second Key 1\n",
109
				strKey);
110
	}
111

    
112

    
113
	@Test
114
	public void testClone() {
115
		PolytomousKey clone = key1.clone();
116
		assertNotNull(clone.getRoot());
117
		assertNotSame(clone.getRoot(), key1.getRoot());
118
		assertTrue(clone.getRoot().getChildren().size() == 0);
119
		assertTrue(key1.getRoot().getChildren().size()> 0);
120
	}
121
}
(5-5/9)