@SuppressWarnings("unused")\r
private static final Logger logger = Logger.getLogger(TaxonNodeTest.class);\r
private static String viewName1;\r
- private static Classification taxonomicView1;\r
- private static Classification taxonomicView2;\r
+ private static Classification classification1;\r
+ private static Classification classification2;\r
private static Taxon taxon1;\r
private static Taxon taxon2;\r
private static Taxon taxon3;\r
@Before\r
public void setUp() throws Exception {\r
viewName1 = "Greuther, 1993";\r
- taxonomicView1 = Classification.NewInstance(viewName1);\r
- taxonomicView2 = Classification.NewInstance("Test View 2");\r
+ classification1 = Classification.NewInstance(viewName1);\r
+ classification2 = Classification.NewInstance("Test View 2");\r
taxonName1 = BotanicalName.NewInstance(Rank.SPECIES());\r
taxonName1 = BotanicalName.NewInstance(Rank.SUBSPECIES());\r
taxonName3 = BotanicalName.NewInstance(Rank.SPECIES());\r
@Test\r
public void testNewTaxonTaxonomicView() {\r
TaxonNode testNode = new TaxonNode(taxon1);\r
- taxonomicView1.addChildNode(testNode, null, null);\r
+ classification1.addChildNode(testNode, null, null);\r
\r
assertNotNull("test node should not be null", testNode);\r
assertEquals(taxon1,testNode.getTaxon());\r
- assertEquals(taxonomicView1,testNode.getClassification());\r
- assertTrue("taxon1 must become part of taxonomicView1", taxonomicView1.isTaxonInTree(taxon1));\r
+ assertEquals(classification1,testNode.getClassification());\r
+ assertTrue("taxon1 must become part of taxonomicView1", classification1.isTaxonInTree(taxon1));\r
}\r
\r
/**\r
*/\r
@Test\r
public void testAddChild() {\r
- TaxonNode root = taxonomicView1.addChildTaxon(taxon1, null, null);\r
- assertEquals("Number of all nodes in view should be 1", 1, taxonomicView1.getAllNodes().size());\r
+ TaxonNode root = classification1.addChildTaxon(taxon1, null, null);\r
+ assertEquals("Number of all nodes in view should be 1", 1, classification1.getAllNodes().size());\r
\r
TaxonNode child = root.addChildTaxon(taxon2, ref2, "p33"); \r
child.setSynonymToBeUsed(syn1); //originally synToBeUsed was part of addChildTaxon\r
assertSame("taxa must be the same", taxon2, childList.iterator().next().getTaxon());\r
\r
//test view properties\r
- List<TaxonNode> rootNodes = taxonomicView1.getChildNodes();\r
+ List<TaxonNode> rootNodes = classification1.getChildNodes();\r
assertEquals("Number of root nodes should be 1", 1, rootNodes.size());\r
- Set<TaxonNode> allNodes = taxonomicView1.getAllNodes();\r
+ Set<TaxonNode> allNodes = classification1.getAllNodes();\r
assertEquals("Number of all nodes should be 2", 2, allNodes.size());\r
assertTrue("Taxonomic view should include child", allNodes.contains(child));\r
\r
@Test\r
public void testSetTaxon() {\r
TaxonNode node = new TaxonNode(taxon1);\r
- taxonomicView1.addChildNode(node, null, null);\r
+ classification1.addChildNode(node, null, null);\r
assertNotNull(taxon2);\r
node.setTaxon(taxon2);\r
assertSame("taxon must be the same", taxon2, node.getTaxon());\r
assertNotNull(taxon2);\r
TaxonNode parent = new TaxonNode(taxon2);\r
assertSame("Taxon must be the same", taxon2, parent.getTaxon());\r
- taxonomicView1.addChildNode(parent, null, null);\r
+ classification1.addChildNode(parent, null, null);\r
node.setParent(parent);\r
assertSame("taxon2 must contain node", parent, node.getParent());\r
assertTrue("setParent must not handle child list of parent", parent.getChildNodes().isEmpty());\r
*/\r
@Test\r
public void testGetChildNodes() {\r
- TaxonNode root = taxonomicView1.addChildTaxon(taxon1, null, null);\r
- assertEquals("Number of all nodes in view should be 1", 1, taxonomicView1.getAllNodes().size());\r
+ TaxonNode root = classification1.addChildTaxon(taxon1, null, null);\r
+ assertEquals("Number of all nodes in view should be 1", 1, classification1.getAllNodes().size());\r
\r
TaxonNode child = root.addChildTaxon(taxon2, ref2, "p33");\r
child.setSynonymToBeUsed(syn1);\r
\r
@Test\r
public void testGetCountChildren(){\r
- TaxonNode root = taxonomicView1.addChildTaxon(taxon1, null, null);\r
+ TaxonNode root = classification1.addChildTaxon(taxon1, null, null);\r
assertEquals("Count of children must be 0", 0, root.getCountChildren());\r
TaxonNode child = root.addChildTaxon(taxon2, ref2, "p33");\r
child.setSynonymToBeUsed(syn1);\r
\r
@Test\r
public void testDelete(){\r
- TaxonNode root = taxonomicView1.addChildTaxon(taxon1, null, null);\r
- assertEquals("Number of all nodes in view should be 1", 1, taxonomicView1.getAllNodes().size());\r
+ TaxonNode root = classification1.addChildTaxon(taxon1, null, null);\r
+ assertEquals("Number of all nodes in view should be 1", 1, classification1.getAllNodes().size());\r
\r
\r
TaxonNode childNode = root.addChildTaxon(taxon2, null, null);\r
\r
\r
root.delete();\r
- assertEquals("Number of all nodes in view should be 0", 0, taxonomicView1.getAllNodes().size());\r
+ assertEquals("Number of all nodes in view should be 0", 0, classification1.getAllNodes().size());\r
\r
\r
}\r
\r
@Test\r
public void testMoveTaxonNodeToOtherTree(){\r
- TaxonNode node = taxonomicView1.addChildTaxon(taxon1, null, null);\r
- assertEquals("The node should be in the classification we added it to", taxonomicView1, node.getClassification());\r
+ TaxonNode node = classification1.addChildTaxon(taxon1, null, null);\r
+ assertEquals("The node should be in the classification we added it to", classification1, node.getClassification());\r
\r
- TaxonNode movedNode = taxonomicView2.addChildNode(node, null, null);\r
- assertEquals("The node should be in the classification we moved it to", taxonomicView2, movedNode.getClassification());\r
- assertEquals("The old tree should be empty now", 0, taxonomicView1.getChildNodes().size());\r
+ TaxonNode movedNode = classification2.addChildNode(node, null, null);\r
+ assertEquals("The node should be in the classification we moved it to", classification2, movedNode.getClassification());\r
+ assertEquals("The old tree should be empty now", 0, classification1.getChildNodes().size());\r
}\r
\r
@Test\r
public void testMoveTaxonNodeToOtherTaxonNodeInDifferentTree(){\r
- TaxonNode node1 = taxonomicView1.addChildTaxon(taxon1, null, null);\r
+ TaxonNode node1 = classification1.addChildTaxon(taxon1, null, null);\r
TaxonNode node2 = node1.addChildTaxon(taxon3, null, null);\r
\r
assertEquals("The node should have exactly one child", 1, node1.getChildNodes().size());\r
- assertEquals("The child is not in the correct tree", taxonomicView1, node2.getClassification());\r
- assertEquals("The Classification should contain exactly two nodes", 2, taxonomicView1.getAllNodes().size());\r
+ assertEquals("The child is not in the correct tree", classification1, node2.getClassification());\r
+ assertEquals("The Classification should contain exactly two nodes", 2, classification1.getAllNodes().size());\r
\r
- TaxonNode node3 = taxonomicView2.addChildTaxon(taxon3, null, null);\r
+ TaxonNode node3 = classification2.addChildTaxon(taxon3, null, null);\r
\r
// move node2 to node3 in other tree\r
node3.addChildNode(node2, null, null);\r
\r
assertEquals("Old node should not have child nodes", 0, node1.getChildNodes().size());\r
- assertEquals("Old tree should contain only one node now", 1, taxonomicView1.getAllNodes().size());\r
- assertEquals("Moved node not in expected tree", taxonomicView2, node2.getClassification());\r
- assertEquals("Count of nodes in new tree:", 2, taxonomicView2.getAllNodes().size());\r
+ assertEquals("Old tree should contain only one node now", 1, classification1.getAllNodes().size());\r
+ assertEquals("Moved node not in expected tree", classification2, node2.getClassification());\r
+ assertEquals("Count of nodes in new tree:", 2, classification2.getAllNodes().size());\r
\r
}\r
\r
*/\r
@Test\r
public void testMoveTaxonNodesRecursivelyToOtherTaxonNodeInDifferentTree(){\r
- TaxonNode node1 = taxonomicView1.addChildTaxon(taxon1, null, null);\r
+ TaxonNode node1 = classification1.addChildTaxon(taxon1, null, null);\r
TaxonNode node2 = node1.addChildTaxon(taxon2, null, null); \r
TaxonNode node3 = node2.addChildTaxon(taxon3, null, null);\r
\r
//move the branch to a different tree \r
- taxonomicView2.addChildNode(node1, null, null);\r
+ classification2.addChildNode(node1, null, null);\r
\r
- assertEquals("Old tree should be empty:", 0, taxonomicView1.getAllNodes().size());\r
- assertEquals("Moved node not in expected tree:", taxonomicView2, node1.getClassification());\r
- assertEquals("Recursively moved node not in expected tree:", taxonomicView2, node2.getClassification());\r
- assertEquals("Recursively moved node not in expected tree:", taxonomicView2, node3.getClassification());\r
+ assertEquals("Old tree should be empty:", 0, classification1.getAllNodes().size());\r
+ assertEquals("Moved node not in expected tree:", classification2, node1.getClassification());\r
+ assertEquals("Recursively moved node not in expected tree:", classification2, node2.getClassification());\r
+ assertEquals("Recursively moved node not in expected tree:", classification2, node3.getClassification());\r
\r
- assertEquals("Count of nodes in new tree:", 3, taxonomicView2.getAllNodes().size());\r
+ assertEquals("Count of nodes in new tree:", 3, classification2.getAllNodes().size());\r
+ \r
+ }\r
+ \r
+ @Test\r
+ public void testAddChildNode(){\r
+ TaxonNode root = classification1.addChildTaxon(taxon1, null, null);\r
+ assertEquals("Number of all nodes in cla should be 1", 1, classification1.getAllNodes().size());\r
+ \r
+ TaxonNode child = root.addChildTaxon(taxon2, ref2, "p33"); \r
+ child.setSynonymToBeUsed(syn1); //originally synToBeUsed was part of addChildTaxon\r
+ //test child properties\r
+ assertNotNull("Child should not be null", child);\r
+ assertEquals("Child taxon should be taxon2", taxon2, child.getTaxon());\r
+ assertEquals("Parent taxon should be taxon1", taxon1, (child.getParent()).getTaxon());\r
+ assertEquals("Reference should be ref2", ref2, child.getReference());\r
+ assertEquals("Microreference should be 'p33'", "p33", child.getMicroReference());\r
+ assertEquals("Synonym should be syn1", syn1, child.getSynonymToBeUsed());\r
+ \r
+ //test parent properties\r
+ List<TaxonNode> childList = root.getChildNodes();\r
+ assertFalse("parent child list must not be empty",childList.isEmpty());\r
+ assertEquals("size of child list be 1", 1, childList.size());\r
+ assertSame("taxa must be the same", taxon2, childList.iterator().next().getTaxon());\r
+ \r
+ //test view properties\r
+ List<TaxonNode> rootNodes = classification1.getChildNodes();\r
+ assertEquals("Number of root nodes should be 1", 1, rootNodes.size());\r
+ Set<TaxonNode> allNodes = classification1.getAllNodes();\r
+ assertEquals("Number of all nodes should be 2", 2, allNodes.size());\r
+ assertTrue("Taxonomic view should include child", allNodes.contains(child));\r
\r
}\r
\r