JAL-2799 rearranged AptxInit code
[jalview.git] / test / jalview / ext / archaeopteryx / AptxPhylogenyTreeTest.java
1 package jalview.ext.archaeopteryx;
2
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertTrue;
5
6 import jalview.gui.Desktop;
7
8 import org.forester.archaeopteryx.Archaeopteryx;
9 import org.forester.archaeopteryx.MainFrame;
10 import org.forester.archaeopteryx.TreePanel;
11 import org.forester.phylogeny.Phylogeny;
12 import org.forester.phylogeny.PhylogenyNode;
13 import org.testng.annotations.BeforeClass;
14 import org.testng.annotations.Test;
15
16 public class AptxPhylogenyTreeTest extends TreeViewTest
17 {
18   final Phylogeny inputTree = new Phylogeny();
19
20   final PhylogenyNode rootNode = new PhylogenyNode("root");
21
22   final PhylogenyNode ancestor1Node = new PhylogenyNode("ancestor 1");
23
24   final PhylogenyNode ancestor2Node = new PhylogenyNode("leaf 2");
25
26   final PhylogenyNode leaf1aNode = new PhylogenyNode("leaf 1a");
27
28   final PhylogenyNode leaf1bNode = new PhylogenyNode("leaf 1b");
29
30   final PhylogenyNode leaf1cNode = new PhylogenyNode("leaf 1c");
31
32   Phylogeny tree;
33
34   TreePanel treePanel;
35
36   MainFrame aptx;
37
38
39   @Override
40   @BeforeClass(alwaysRun = true)
41   public void setUpTree()
42   {
43     ancestor1Node.addAsChild(leaf1aNode);
44     ancestor1Node.addAsChild(leaf1bNode);
45     ancestor1Node.addAsChild(leaf1cNode);
46
47     rootNode.addAsChild(ancestor1Node);
48     rootNode.addAsChild(ancestor2Node);
49
50     leaf1aNode.setDistanceToParent(2);
51     leaf1bNode.setDistanceToParent(3);
52     leaf1cNode.setDistanceToParent(4);
53
54     ancestor1Node.setDistanceToParent(36);
55     ancestor2Node.setDistanceToParent(42);
56
57     inputTree.setName("test");
58     inputTree.setRoot(rootNode);
59     inputTree.setRooted(true);
60
61   }
62
63   @Override
64   @BeforeClass(dependsOnMethods = { "setUpJalview", "setUpTree" })
65   public void createTreeView()
66   {
67     treeView = Archaeopteryx.createApplication(inputTree);
68     aptx = (MainFrame) treeView; // pretty ugly
69     treePanel = aptx.getMainPanel().getCurrentTreePanel();
70     tree = treePanel.getPhylogeny();
71
72     Desktop.addInternalFrame(aptx, "Archaeopteryx", 500, 500);
73
74   }
75
76
77
78   @Test(groups = "Functional")
79   public void testMainPanelExists()
80   {
81     assertTrue(aptx.getMainPanel() != null);
82   }
83
84   @Test(groups = "Functional")
85   public void testTreePanelExists()
86   {
87     assertTrue(treePanel != null);
88   }
89
90   @Override
91   public void testTreeTitle()
92   {
93     assertTrue(tree.getName().equals("test"));
94
95   }
96
97   @Test(
98     groups = "Functional",
99     expectedExceptions = IllegalArgumentException.class)
100   public void testInvalidBranchName()
101   {
102     tree.getNode("I shouldn't exist");
103
104   }
105
106   @Override
107   public void testExistingBranchName()
108   {
109     tree.getNode("leaf 2");
110
111   }
112
113   @Override
114   public void testTreeLoaded()
115   {
116     assertTrue(tree != null);
117   }
118
119   @Override
120   public void testChildNodesCount()
121   {
122     assertEquals(tree.getNode("ancestor 1").getNumberOfExternalNodes(), 3);
123
124   }
125
126   @Override
127   public void testChildToParentBranchLength()
128   {
129     assertEquals(tree.getNode("leaf 1a").getDistanceToParent(), 2.0);
130
131   }
132
133   @Override
134   public void testNodeToRootBranchLength()
135   {
136     assertEquals(tree.getNode("leaf 2").getDistanceToParent(), 42.0);
137
138   }
139
140   @Override
141   public void testDistantNodeToRootBranchLength()
142   {
143     assertEquals(tree.getNode("leaf 1c").calculateDistanceToRoot(),
144             4.0 + 36.0);
145
146   }
147
148
149
150
151
152
153
154 }