JAL-1369 failing test
authorJim Procter <jprocter@issues.jalview.org>
Mon, 20 Jun 2016 15:26:16 +0000 (16:26 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Mon, 20 Jun 2016 20:35:04 +0000 (21:35 +0100)
test/jalview/io/Jalview2xmlTests.java

index 5e2ceb9..21bf846 100644 (file)
@@ -36,6 +36,8 @@ import jalview.schemes.AnnotationColourGradient;
 import jalview.schemes.ColourSchemeI;
 
 import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.testng.Assert;
 import org.testng.AssertJUnit;
@@ -413,6 +415,72 @@ public class Jalview2xmlTests
             Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
   }
 
+  /**
+   * based on above test store and recovery of expanded views.
+   * 
+   * @throws Exception
+   */
+  @Test(groups = { "Functional" }, enabled = true)
+  public void testStoreAndRecoverReferenceSeqSettings() throws Exception
+  {
+    String afid = "";
+    {
+      AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
+              "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
+      assertTrue("Didn't read in the example file correctly.", af != null);
+      afid = af.getViewport().getSequenceSetId();
+    }
+    Map<String, SequenceI> refs = new HashMap<String, SequenceI>();
+    int n = 1;
+    for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
+    {
+      // mark representative
+      SequenceI rep = ap.getAlignment().getSequenceAt(
+              n++ % ap.getAlignment().getHeight());
+      refs.put(ap.getViewName(), rep);
+      // code from mark/unmark sequence as reference in jalview.gui.PopupMenu
+      // todo refactor the to an alignment view controller
+      ap.getAlignViewport().setDisplayReferenceSeq(true);
+      ap.getAlignViewport().setColourByReferenceSeq(true);
+      ap.getAlignViewport().getAlignment().setSeqrep(rep);
+    }
+    File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
+            ".jvp");
+    try
+    {
+      new Jalview2XML(false).saveState(tfile);
+    } catch (Error e)
+    {
+      Assert.fail("Didn't save the expanded view state", e);
+    } catch (Exception e)
+    {
+      Assert.fail("Didn't save the expanded view state", e);
+    }
+    Desktop.instance.closeAll_actionPerformed(null);
+    if (Desktop.getAlignFrames() != null)
+    {
+      Assert.assertEquals(Desktop.getAlignFrames().length, 0);
+    }
+    {
+      AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
+            tfile.getAbsolutePath(), FormatAdapter.FILE);
+    }
+    for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(Desktop
+            .getAlignFrames()[0].getViewport().getSequenceSetId()))
+    {
+      // check representative
+      SequenceI rep = ap.getAlignment().getSeqrep();
+      Assert.assertNotNull(rep,
+              "Couldn't restore sequence representative from project");
+      Assert.assertEquals(refs.get(ap.getViewName()), rep,
+              "Representative wasn't the same when recovered.");
+      Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
+              "Display reference sequence view setting not set.");
+      Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
+              "Colour By Reference Seq view setting not set.");
+    }
+  }
+
   @Test(groups = { "Functional" })
   public void testIsVersionStringLaterThan()
   {