1 package jalview.ext.archaeopteryx;
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertTrue;
6 import jalview.gui.JvOptionPane;
8 import org.forester.archaeopteryx.MainFrame;
9 import org.forester.archaeopteryx.TreePanel;
10 import org.forester.phylogeny.Phylogeny;
11 import org.forester.phylogeny.PhylogenyNode;
12 import org.testng.annotations.BeforeClass;
13 import org.testng.annotations.Test;
15 public class AptxPhylogenyTreeTest extends TreeViewTest
17 final Phylogeny inputTree = new Phylogeny();
19 final PhylogenyNode rootNode = new PhylogenyNode("root");
21 final PhylogenyNode ancestor1Node = new PhylogenyNode("ancestor 1");
23 final PhylogenyNode ancestor2Node = new PhylogenyNode("leaf 2");
25 final PhylogenyNode leaf1aNode = new PhylogenyNode("leaf 1a");
27 final PhylogenyNode leaf1bNode = new PhylogenyNode("leaf 1b");
29 final PhylogenyNode leaf1cNode = new PhylogenyNode("leaf 1c");
39 @BeforeClass(alwaysRun = true)
40 public void setUpTree()
42 ancestor1Node.addAsChild(leaf1aNode);
43 ancestor1Node.addAsChild(leaf1bNode);
44 ancestor1Node.addAsChild(leaf1cNode);
46 rootNode.addAsChild(ancestor1Node);
47 rootNode.addAsChild(ancestor2Node);
49 leaf1aNode.setDistanceToParent(2);
50 leaf1bNode.setDistanceToParent(3);
51 leaf1cNode.setDistanceToParent(4);
53 ancestor1Node.setDistanceToParent(36);
54 ancestor2Node.setDistanceToParent(42);
56 inputTree.setRoot(rootNode);
57 inputTree.setRooted(true);
62 @BeforeClass(dependsOnMethods = { "setUpJalview", "setUpTree" })
63 public void createTreeView()
66 treeView = ArchaeopteryxInit.createInstance(inputTree);
67 aptx = (MainFrame) treeView; // pretty ugly
68 treePanel = aptx.getMainPanel().getCurrentTreePanel();
69 tree = treePanel.getPhylogeny();
73 @BeforeClass(alwaysRun = true)
74 public void setUpJvOptionPane()
76 JvOptionPane.setInteractiveMode(false);
77 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
80 @Test(groups = "Functional")
81 public void testMainPanelExists()
83 assertTrue(aptx.getMainPanel() != null);
86 @Test(groups = "Functional")
87 public void testTreePanelExists()
89 assertTrue(aptx.getMainPanel().getCurrentTreePanel() != null);
94 groups = "Functional",
95 expectedExceptions = IllegalArgumentException.class)
96 public void testInvalidBranchName()
98 tree.getNode("I shouldn't exist");
103 @Test(groups = "Functional")
104 public void testExistingBranchName()
106 tree.getNode("leaf 2");
111 @Test(groups = "Functional")
112 public void testTreeLoaded()
114 assertTrue(aptx.getMainPanel().getCurrentTreePanel()
115 .getPhylogeny() != null);
119 @Test(groups = "Functional")
120 public void testChildNodesCount()
122 assertEquals(tree.getNode("ancestor 1").getNumberOfExternalNodes(), 3);
127 @Test(groups = "Functional")
128 public void testChildToParentBranchLength()
130 assertEquals(tree.getNode("leaf 1a").getDistanceToParent(), 2.0);
135 @Test(groups = "Functional")
136 public void testNodeToRootBranchLength()
138 assertEquals(tree.getNode("leaf 2").getDistanceToParent(), 42.0);
143 @Test(groups = "Functional")
144 public void testDistantNodeToRootBranchLength()
146 assertEquals(tree.getNode("leaf 1c").calculateDistanceToRoot(),