Merge branch 'merge/JAL-3285_mchmmer_with_211_develop' into alpha/JAL-3362_Jalview_21...
[jalview.git] / test / jalview / gui / AlignFrameTest.java
index bdda48d..442cfb5 100644 (file)
  */
 package jalview.gui;
 
+import static org.junit.Assert.assertNotEquals;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNotSame;
 import static org.testng.Assert.assertSame;
 import static org.testng.Assert.assertTrue;
 
+import jalview.api.AlignViewportI;
 import jalview.api.FeatureColourI;
 import jalview.bin.Cache;
 import jalview.bin.Jalview;
@@ -47,6 +49,7 @@ import jalview.schemes.JalviewColourScheme;
 import jalview.schemes.StrandColourScheme;
 import jalview.schemes.TurnColourScheme;
 import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
 
 import java.awt.Color;
 import java.util.Iterator;
@@ -61,7 +64,53 @@ public class AlignFrameTest
   AlignFrame af;
 
   @BeforeClass(alwaysRun = true)
-  public void setUpJvOptionPane()
+  public static void setUpBeforeClass() throws Exception
+  {
+    setUpJvOptionPane();
+    /*
+     * use read-only test properties file
+     */
+    Cache.loadProperties("test/jalview/io/testProps.jvprops");
+    Jalview.main(new String[] { "-nonews" });
+  }
+
+  @AfterMethod(alwaysRun = true)
+  public void tearDown()
+  {
+    Desktop.instance.closeAll_actionPerformed(null);
+  }
+
+  /**
+   * configure (read-only) properties for test to ensure Consensus is computed for
+   * colour Above PID testing
+   */
+  @BeforeMethod(alwaysRun = true)
+  public void setUp()
+  {
+    Cache.loadProperties("test/jalview/io/testProps.jvprops");
+    Cache.applicationProperties.setProperty("SHOW_IDENTITY",
+            Boolean.TRUE.toString());
+    af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
+            DataSourceType.FILE);
+
+    /*
+     * wait for Consensus thread to complete
+     */
+    synchronized (this)
+    {
+      while (af.getViewport().getConsensusSeq() == null)
+      {
+        try
+        {
+          wait(50);
+        } catch (InterruptedException e)
+        {
+        }
+      }
+    }
+  }
+
+  public static void setUpJvOptionPane()
   {
     JvOptionPane.setInteractiveMode(false);
     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
@@ -118,7 +167,8 @@ public class AlignFrameTest
      * seq1 feature in columns 1-5 is hidden
      * seq2 feature in columns 6-10 is shown
      */
-    FeatureColourI fc = new FeatureColour(Color.red, Color.blue, 0f, 10f);
+    FeatureColourI fc = new FeatureColour(null, Color.red, Color.blue, null,
+            0f, 10f);
     fc.setAboveThreshold(true);
     fc.setThreshold(5f);
     alignFrame.getFeatureRenderer().setColour("Metal", fc);
@@ -149,52 +199,6 @@ public class AlignFrameTest
     assertEquals(next[1], 8);
   }
 
-  @BeforeClass(alwaysRun = true)
-  public static void setUpBeforeClass() throws Exception
-  {
-    /*
-     * use read-only test properties file
-     */
-    Cache.loadProperties("test/jalview/io/testProps.jvprops");
-    Jalview.main(new String[] { "-nonews" });
-  }
-
-  @AfterMethod(alwaysRun = true)
-  public void tearDown()
-  {
-    Desktop.instance.closeAll_actionPerformed(null);
-  }
-
-  /**
-   * configure (read-only) properties for test to ensure Consensus is computed
-   * for colour Above PID testing
-   */
-  @BeforeMethod(alwaysRun = true)
-  public void setUp()
-  {
-    Cache.loadProperties("test/jalview/io/testProps.jvprops");
-    Cache.applicationProperties.setProperty("SHOW_IDENTITY",
-            Boolean.TRUE.toString());
-    af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
-            DataSourceType.FILE);
-
-    /*
-     * wait for Consensus thread to complete
-     */
-    synchronized (this)
-    {
-      while (af.getViewport().getConsensusSeq() == null)
-      {
-        try
-        {
-          wait(50);
-        } catch (InterruptedException e)
-        {
-        }
-      }
-    }
-  }
-
   /**
    * Test that changing background (alignment) colour scheme
    * <ul>
@@ -208,7 +212,7 @@ public class AlignFrameTest
   @Test(groups = "Functional")
   public void testChangeColour_background_groupsAndThresholds()
   {
-    AlignViewport av = af.getViewport();
+    AlignViewportI av = af.getViewport();
     AlignmentI al = av.getAlignment();
 
     /*
@@ -339,7 +343,7 @@ public class AlignFrameTest
   @Test(groups = "Functional")
   public void testColourThresholdActions()
   {
-    AlignViewport av = af.getViewport();
+    AlignViewportI av = af.getViewport();
     AlignmentI al = av.getAlignment();
 
     /*
@@ -508,7 +512,7 @@ public class AlignFrameTest
   @Test(groups = "Functional")
   public void testNewView_colourThresholds()
   {
-    AlignViewport av = af.getViewport();
+    AlignViewportI av = af.getViewport();
     AlignmentI al = av.getAlignment();
 
     /*
@@ -572,7 +576,7 @@ public class AlignFrameTest
      */
     af.newView_actionPerformed(null);
     assertEquals(af.alignPanel.getViewName(), "View 1");
-    AlignViewport av2 = af.getViewport();
+    AlignmentViewport av2 = af.getViewport();
     assertNotSame(av, av2);
     assertSame(av2, af.alignPanel.av);
     rs = av2.getResidueShading();
@@ -599,4 +603,26 @@ public class AlignFrameTest
     sp.valueChanged(22);
     assertEquals(av2.getResidueShading().getConservationInc(), 22);
   }
+
+  /**
+   * Verify that making a New View preserves the dataset reference for the
+   * alignment. Otherwise, see a 'duplicate jar entry' reference when trying to
+   * save alignments with multiple views, and codon mappings will not be shared
+   * across all panels in a split frame.
+   * 
+   * @see Jalview2xmlTests#testStoreAndRecoverColourThresholds()
+   */
+  @Test(groups = "Functional")
+  public void testNewView_dsRefPreserved()
+  {
+    AlignViewport av = af.getViewport();
+    AlignmentI al = av.getAlignment();
+    AlignmentI original_ds = al.getDataset();
+    af.newView_actionPerformed(null);
+    assertNotEquals("New view didn't select the a new panel", av,
+            af.getViewport());
+    org.testng.Assert.assertEquals(original_ds,
+            af.getViewport().getAlignment().getDataset(),
+            "Dataset was not preserved in new view");
+  }
 }