3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.cdm
.model
.taxon
;
13 import static org
.junit
.Assert
.*;
17 import org
.apache
.log4j
.Logger
;
18 import org
.junit
.After
;
19 import org
.junit
.AfterClass
;
20 import org
.junit
.Before
;
21 import org
.junit
.BeforeClass
;
22 import org
.junit
.Test
;
24 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
25 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
26 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
27 import eu
.etaxonomy
.cdm
.model
.reference
.Journal
;
28 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
35 public class TaxonomicViewTest
{
36 @SuppressWarnings("unused")
37 private static final Logger logger
= Logger
.getLogger(TaxonomicViewTest
.class);
39 private static String viewName1
;
40 private static TaxonomicView taxonomicView1
;
41 private static TaxonNode taxonNode1
;
42 private static TaxonNode taxonNode2
;
43 private static TaxonNode taxonNode3
;
44 private static Taxon taxon1
;
45 private static Taxon taxon2
;
46 private static TaxonNameBase
<?
,?
> taxonName1
;
47 private static ReferenceBase ref1
;
52 * @throws java.lang.Exception
55 public static void setUpBeforeClass() throws Exception
{
59 * @throws java.lang.Exception
62 public static void tearDownAfterClass() throws Exception
{
66 * @throws java.lang.Exception
69 public void setUp() throws Exception
{
70 viewName1
= "Greuther, 1993";
71 taxonomicView1
= TaxonomicView
.NewInstance(viewName1
);
72 taxonName1
= BotanicalName
.NewInstance(Rank
.SPECIES());
73 ref1
= Journal
.NewInstance();
74 taxon1
= Taxon
.NewInstance(taxonName1
, ref1
);
75 //taxonNode1 = new TaxonNode(taxon1, taxonomicView1);
79 * @throws java.lang.Exception
82 public void tearDown() throws Exception
{
85 //****************************** TESTS *****************************************/
88 * Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonomicView#addRoot(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.reference.ReferenceBase, java.lang.String, eu.etaxonomy.cdm.model.taxon.Synonym)}.
91 public void testAddRoot() {
92 TaxonNameBase
<?
,?
> synonymName
= BotanicalName
.NewInstance(Rank
.SPECIES());
93 Synonym synonym
= Synonym
.NewInstance(synonymName
, ref1
);
94 TaxonNode taxonNode1
= taxonomicView1
.addRoot(taxon1
, synonym
);
97 Set
<TaxonNode
> rootNodes
= taxonomicView1
.getRootNodes();
98 assertFalse("List of root nodes should not be empty", rootNodes
.isEmpty());
99 assertEquals("Number of root nodes should be 1", 1, rootNodes
.size());
100 TaxonNode root
= rootNodes
.iterator().next();
101 assertEquals(taxon1
, root
.getTaxon());
102 assertSame(taxonNode1
, root
);
103 assertNull(root
.getReferenceForParentChildRelation());
104 assertNull(root
.getMicroReferenceForParentChildRelation());
105 assertEquals(synonym
, root
.getSynonymToBeUsed());
108 Set
<TaxonNode
> allNodes
= taxonomicView1
.getRootNodes();
109 assertFalse("List of root nodes should not be empty", allNodes
.isEmpty());
110 assertEquals("Number of root nodes should be 1", 1, allNodes
.size());
111 TaxonNode anyNode
= allNodes
.iterator().next();
112 assertSame("Taxon for TaxonNode should be the same added to the view", taxon1
, anyNode
.getTaxon());
113 assertSame("TaxonNode should be the same added to the view", taxonNode1
, anyNode
);
117 * Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonomicView#isTaxonInView(eu.etaxonomy.cdm.model.taxon.Taxon)}.
120 public void testIsTaxonInView() {
121 taxonomicView1
.addRoot(taxon1
, null);
123 assertTrue(taxonomicView1
.isTaxonInView(taxon1
));
124 Taxon anyTaxon
= Taxon
.NewInstance(null, null);
125 assertFalse(taxonomicView1
.isTaxonInView(anyTaxon
));
130 * Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonomicView#makeRootChildOfOtherNode(eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.model.reference.ReferenceBase, java.util.String)}.
133 public void testMakeRootChildOfOtherNode() {
134 TaxonNode root1
= taxonomicView1
.addRoot(taxon1
, null);
135 TaxonNode root2
= taxonomicView1
.addRoot(taxon2
, null);
136 Taxon taxon3
= Taxon
.NewInstance(null, null);
137 root2
.addChild(taxon3
);
138 String microRef
= "p55";
140 assertFalse("Root1 must not yet be child of root 2", root2
.getChildNodes().contains(root1
));
141 assertNotSame("Root2 must not yet be parent of root 1", root2
, root1
.getParent());
142 assertEquals("view must contain 3 nodes", 3, taxonomicView1
.getAllNodes().size());
143 assertEquals("view must still contain 2 root", 2, taxonomicView1
.getRootNodes().size());
144 assertEquals("root2 must have 1 child", 1, root2
.getChildNodes().size());
146 taxonomicView1
.makeRootChildOfOtherNode(root1
, root2
, ref1
, microRef
);
147 assertTrue("Root1 must be child of root 2", root2
.getChildNodes().contains(root1
));
148 assertSame("Root2 must be parent of root 1", root2
, root1
.getParent());
149 assertEquals("view must contain 3 nodes", 3, taxonomicView1
.getAllNodes().size());
150 assertEquals("view must contain 1 root", 1, taxonomicView1
.getRootNodes().size());
151 assertEquals("new child node must have the expected reference for parent child relationship", ref1
, root1
.getReferenceForParentChildRelation());
152 assertEquals("new child node must have the expected micro reference for parent child relationship", microRef
, root1
.getMicroReferenceForParentChildRelation());
153 assertEquals("root2 must have 2 children", 2, root2
.getChildNodes().size());
158 * Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonomicView#generateTitle()}.
161 public void testGenerateTitle() {
162 TaxonomicView taxonomicViewLocal
= TaxonomicView
.NewInstance(viewName1
);
163 //Maybe changed if title cache is generated in a different way
164 assertEquals(viewName1
, taxonomicViewLocal
.getTitleCache());