JAL-3365 expand range of allowed DSSP secondary structure symbols in Stockholm files
[jalview.git] / test / jalview / io / CrossRef2xmlTests.java
index f8157ec..3ca6ed8 100644 (file)
  */
 package jalview.io;
 
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
 import jalview.analysis.CrossRef;
 import jalview.api.AlignmentViewPanel;
 import jalview.datamodel.AlignedCodonFrame;
@@ -29,9 +33,9 @@ import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
 import jalview.gui.CrossRefAction;
 import jalview.gui.Desktop;
-import jalview.gui.Jalview2XML;
 import jalview.gui.JvOptionPane;
 import jalview.gui.SequenceFetcher;
+import jalview.project.Jalview2XML;
 import jalview.util.DBRefUtils;
 
 import java.io.File;
@@ -61,6 +65,51 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
   }
 
+  @Test(groups = { "Functional" }, enabled = true)
+  public void openCrossrefsForEnsemblTwice()
+  {
+    AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
+            "examples/testdata/CantShowEnsemblCrossrefsTwice.jvp",
+            DataSourceType.FILE);
+    assertNotNull(af, "Couldn't load test's project.");
+    AlignmentI origAlig = af.getViewport().getAlignment();
+    List<String> source = new CrossRef(origAlig.getSequencesArray(),
+            origAlig.getDataset()).findXrefSourcesForSequences(true);
+    assertEquals(source.size(), 1, "Expected just one crossref to show.");
+    List<AlignmentViewPanel> views;
+    {
+      // try to show once - in a code block so handler is forgotten about
+      CrossRefAction xref1 = CrossRefAction.getHandlerFor(
+              origAlig.getSequencesArray(), true, source.get(0), af);
+      try
+      {
+        xref1.run();
+        views = (List<AlignmentViewPanel>) PA.getValue(xref1, "xrefViews");
+        assertTrue(views.size() > 0,
+                "Couldn't get cross ref on first attempt (SERIOUS FAIL).");
+      } catch (Exception ex)
+      {
+        Assert.fail("Unexpected Exception for first xref action", ex);
+      }
+    }
+
+    views = null;
+    // now just try it again
+    CrossRefAction xref2 = CrossRefAction.getHandlerFor(
+            origAlig.getSequencesArray(), true, source.get(0), af);
+    try
+    {
+      xref2.run();
+      views = (List<AlignmentViewPanel>) PA.getValue(xref2, "xrefViews");
+      assertTrue(views.size() > 0,
+              "Couldn't get cross ref on second attempt (SERIOUS FAIL).");
+    } catch (Exception ex)
+    {
+      Assert.fail("Unexpected Exception for second xref action", ex);
+    }
+    // TODO : check that both views contain the same data
+  }
+
   @DataProvider(name = "initialAccessions")
   static Object[][] getAccessions()
   {