Added abstract class for tree viewer testing, rearranged existing tests
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Wed, 25 Oct 2017 14:50:40 +0000 (15:50 +0100)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Wed, 25 Oct 2017 14:50:40 +0000 (15:50 +0100)
test/jalview/ext/archaeopteryx/AptxJalviewTreeTest.java
test/jalview/ext/archaeopteryx/AptxPhylogenyTreeTest.java
test/jalview/ext/archaeopteryx/TreeViewTest.java [new file with mode: 0644]

index a5beee2..4fdc473 100644 (file)
@@ -1,14 +1,24 @@
 package jalview.ext.archaeopteryx;
 
+import jalview.analysis.NJTree;
 import jalview.analysis.TreeBuilder;
+import jalview.analysis.scoremodels.ScoreModels;
+import jalview.analysis.scoremodels.SimilarityParams;
+import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.SimilarityParamsI;
 import jalview.bin.Jalview;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+import jalview.gui.AlignViewport;
 
 import org.forester.archaeopteryx.MainFrame;
 import org.forester.archaeopteryx.TreePanel;
 import org.forester.phylogeny.Phylogeny;
 import org.testng.annotations.BeforeClass;
 
-public class AptxJalviewTreeTest
+public class AptxJalviewTreeTest extends TreeViewTest
 {
   TreeBuilder jalviewTree;
 
@@ -20,20 +30,70 @@ public class AptxJalviewTreeTest
 
   Jalview jalview;
   
+  @Override
   @BeforeClass(alwaysRun = true)
   public void setUpTree()
   {
+    SequenceI seq1 = new Sequence("Seq1", "ABCDEFGHIJ");
+    SequenceI seq2 = new Sequence("Seq2", "ABCDEFTHIJ");
+    SequenceI seq3 = new Sequence("Seq3", "BCFWDHIJ");
+    SequenceI seq4 = new Sequence("Seq4", "WTHISTHIS");
 
+    AlignmentI al = new Alignment(
+            new SequenceI[]
+            { seq1, seq2, seq3, seq4 });
+    AlignViewport alignViewport = new AlignViewport(al);
+
+    ScoreModelI scoreModel = ScoreModels.getInstance().getBlosum62();
+    SimilarityParamsI similarityParams = new SimilarityParams(true, true,
+            true, false);
+
+    jalviewTree = new NJTree(alignViewport, scoreModel,
+            similarityParams);
   }
 
   @BeforeClass(dependsOnMethods = { "setUpTree" })
-  public void setUpJalview()
+  public void createTreeView()
   {
-    String[] args = new String[0];
-    Jalview.main(args);
-    aptx = ArchaeopteryxInit.createInstance(jalviewTree);
+    treeView = ArchaeopteryxInit.createInstance(jalviewTree);
+    aptx = (MainFrame) treeView; // still pretty ugly
 
     treePanel = aptx.getMainPanel().getCurrentTreePanel();
     tree = treePanel.getPhylogeny();
   }
+
+  @Override
+  public void testChildNodesCount()
+  {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
+  public void testChildToParentBranchLength()
+  {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
+  public void testNodeToRootBranchLength()
+  {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
+  public void testDistantNodeToRootBranchLength()
+  {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
+  public void testTreeLoaded()
+  {
+    // TODO Auto-generated method stub
+
+  }
 }
index 6e324d7..5e00496 100644 (file)
@@ -3,8 +3,6 @@ package jalview.ext.archaeopteryx;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 
-import jalview.bin.Jalview;
-import jalview.gui.Desktop;
 import jalview.gui.JvOptionPane;
 
 import org.forester.archaeopteryx.MainFrame;
@@ -14,7 +12,7 @@ import org.forester.phylogeny.PhylogenyNode;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-public class AptxPhylogenyTreeTest
+public class AptxPhylogenyTreeTest extends TreeViewTest
 {
   final Phylogeny inputTree = new Phylogeny();
 
@@ -22,7 +20,7 @@ public class AptxPhylogenyTreeTest
 
   final PhylogenyNode ancestor1Node = new PhylogenyNode("ancestor 1");
 
-  final PhylogenyNode ancestor2Node = new PhylogenyNode("ancestor 2");
+  final PhylogenyNode ancestor2Node = new PhylogenyNode("leaf 2");
 
   final PhylogenyNode leaf1aNode = new PhylogenyNode("leaf 1a");
 
@@ -30,14 +28,14 @@ public class AptxPhylogenyTreeTest
 
   final PhylogenyNode leaf1cNode = new PhylogenyNode("leaf 1c");
 
-  TreePanel treePanel;
-
   Phylogeny tree;
 
+  TreePanel treePanel;
+
   MainFrame aptx;
 
-  Jalview jalview;
 
+  @Override
   @BeforeClass(alwaysRun = true)
   public void setUpTree()
   {
@@ -60,13 +58,12 @@ public class AptxPhylogenyTreeTest
 
   }
 
-  @BeforeClass(dependsOnMethods = { "setUpTree" })
-  public void setUpJalview()
+  @BeforeClass(dependsOnMethods = { "setUpJalview", "setUpTree" })
+  public void createTreeView()
   {
-    String[] args = new String[0];
-    Jalview.main(args);
-    aptx = ArchaeopteryxInit.createInstance(inputTree);
 
+    treeView = ArchaeopteryxInit.createInstance(inputTree);
+    aptx = (MainFrame) treeView; // pretty ugly
     treePanel = aptx.getMainPanel().getCurrentTreePanel();
     tree = treePanel.getPhylogeny();
   }
@@ -80,26 +77,6 @@ public class AptxPhylogenyTreeTest
   }
 
   @Test(groups = "Functional")
-  public void testAptxExists()
-  {
-    assertTrue(aptx != null);
-  }
-
-
-  @Test(groups = "Functional")
-  public void testAptxBoundToJalview()
-  {
-    assertTrue(aptx.getTopLevelAncestor() instanceof Desktop);
-  }
-
-  @Test(groups = "Functional")
-  public void testShowingAptx()
-  {
-    assertTrue(aptx.isShowing());
-
-  }
-
-  @Test(groups = "Functional")
   public void testMainPanelExists()
   {
     assertTrue(aptx.getMainPanel() != null);
@@ -111,12 +88,15 @@ public class AptxPhylogenyTreeTest
     assertTrue(aptx.getMainPanel().getCurrentTreePanel() != null);
   }
 
+  @Override
   @Test(groups = "Functional")
   public void testTreeLoaded()
   {
-    assertTrue(aptx.getMainPanel().getCurrentTreePanel() != null);
+    assertTrue(aptx.getMainPanel().getCurrentTreePanel()
+            .getPhylogeny() != null);
   }
 
+  @Override
   @Test(groups = "Functional")
   public void testChildNodesCount()
   {
@@ -124,22 +104,25 @@ public class AptxPhylogenyTreeTest
 
   }
 
+  @Override
   @Test(groups = "Functional")
-  public void testCorrectLeafToParentBranchLength()
+  public void testChildToParentBranchLength()
   {
     assertEquals(tree.getNode("leaf 1a").getDistanceToParent(), 2.0);
 
   }
 
+  @Override
   @Test(groups = "Functional")
-  public void testCorrectAncestorLeafToRootBranchLength()
+  public void testNodeToRootBranchLength()
   {
-    assertEquals(tree.getNode("ancestor 2").getDistanceToParent(), 42.0);
+    assertEquals(tree.getNode("leaf 2").getDistanceToParent(), 42.0);
 
   }
 
+  @Override
   @Test(groups = "Functional")
-  public void testCorrectLeafToRootBranchLength()
+  public void testDistantNodeToRootBranchLength()
   {
     assertEquals(tree.getNode("leaf 1c").calculateDistanceToRoot(),
             4.0 + 36.0);
diff --git a/test/jalview/ext/archaeopteryx/TreeViewTest.java b/test/jalview/ext/archaeopteryx/TreeViewTest.java
new file mode 100644 (file)
index 0000000..972263d
--- /dev/null
@@ -0,0 +1,62 @@
+package jalview.ext.archaeopteryx;
+
+import static org.testng.Assert.assertTrue;
+
+import jalview.bin.Jalview;
+import jalview.gui.Desktop;
+
+import javax.swing.JInternalFrame;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public abstract class TreeViewTest
+{
+
+  Jalview jalview;
+
+  JInternalFrame treeView;
+
+  @BeforeClass(alwaysRun = true)
+  public abstract void setUpTree();
+
+  @BeforeClass(alwaysRun = true)
+  public void setUpJalview()
+  {
+    String[] args = new String[0];
+    Jalview.main(args);
+  }
+
+  @Test(groups = "Functional")
+  public void testTreeViewExists()
+  {
+    assertTrue(treeView != null);
+  }
+
+  @Test(groups = "Functional")
+  public void testTreeViewBoundToJalview()
+  {
+    assertTrue(treeView.getTopLevelAncestor() instanceof Desktop);
+  }
+
+  @Test(groups = "Functional")
+  public void testShowingTreeView()
+  {
+    assertTrue(treeView.isShowing());
+  }
+
+  @Test(groups = "Functional")
+  public abstract void testTreeLoaded();
+
+  @Test(groups = "Functional")
+  public abstract void testChildNodesCount();
+
+  @Test(groups = "Functional")
+  public abstract void testChildToParentBranchLength();
+
+  @Test(groups = "Functional")
+  public abstract void testNodeToRootBranchLength();
+
+  @Test(groups = "Functional")
+  public abstract void testDistantNodeToRootBranchLength();
+}