JAL-1805 modified test setup's so the are ran for groups which requires them
[jalview.git] / test / jalview / ext / rbvi / chimera / JalviewChimeraView.java
index 1736af5..0c5d7fa 100644 (file)
@@ -1,21 +1,17 @@
 package jalview.ext.rbvi.chimera;
 
-import static org.junit.Assert.*;
-import jalview.datamodel.PDBEntry;
+import static org.testng.AssertJUnit.assertTrue;
+
+import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
 import jalview.gui.StructureViewer;
-import jalview.gui.StructureViewer.Viewer;
+import jalview.gui.StructureViewer.ViewerType;
 import jalview.io.FormatAdapter;
 
-import java.awt.Desktop;
-import java.io.File;
-
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
 
 public class JalviewChimeraView
 {
@@ -23,7 +19,7 @@ public class JalviewChimeraView
   /**
    * @throws java.lang.Exception
    */
-  @BeforeClass
+  @BeforeClass(alwaysRun = true)
   public static void setUpBeforeClass() throws Exception
   {
     jalview.bin.Jalview.main(new String[]
@@ -36,47 +32,100 @@ public class JalviewChimeraView
   @AfterClass
   public static void tearDownAfterClass() throws Exception
   {
+    try
+    {
     jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
+    } catch (Exception e)
+    {
+      // ignore NullPointerException thrown by JMol
+    }
 
   }
 
-
-  @Test
-  public void testSingleSeqView()
+  @Test(groups ={ "Functional" })
+  public void testSingleSeqViewJMol()
   {
     String inFile = "examples/1gaq.txt";
     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
             inFile, FormatAdapter.FILE);
     assertTrue("Didn't read input file " + inFile, af != null);
-    for (SequenceI sq:af.getViewport().getAlignment().getSequences())
+    for (SequenceI sq : af.getViewport().getAlignment().getSequences())
     {
-      SequenceI dsq=sq.getDatasetSequence();
-      while (dsq.getDatasetSequence()!=null)
+      SequenceI dsq = sq.getDatasetSequence();
+      while (dsq.getDatasetSequence() != null)
       {
-        dsq=dsq.getDatasetSequence();
+        dsq = dsq.getDatasetSequence();
       }
-      if (dsq.getPDBId()!=null && dsq.getPDBId().size()>0) {
-        for (int q=0;q<dsq.getPDBId().size();q++) 
+      if (dsq.getPDBId() != null && dsq.getPDBId().size() > 0)
+      {
+        for (int q = 0; q < dsq.getPDBId().size(); q++)
         {
-          new StructureViewer(af.getViewport().getStructureSelectionManager()).viewStructures(Viewer.JMOL,
-                  af.getCurrentView().getAlignPanel(),
-                  new PDBEntry[] { (PDBEntry)dsq.getPDBId().elementAt(q) },
-                  new SequenceI[][] { new SequenceI[] { sq } });
+          final StructureViewer structureViewer = new StructureViewer(af
+                  .getViewport().getStructureSelectionManager());
+          structureViewer.setViewerType(ViewerType.JMOL);
+          JalviewStructureDisplayI jmolViewer = structureViewer
+                  .viewStructures(dsq.getPDBId().elementAt(q),
+                          new SequenceI[]
+                  { sq }, af.getCurrentView().getAlignPanel());
+          /*
+           * Wait for viewer thread to start
+           */
+          try
+          {
+            Thread.sleep(1000);
+          } catch (InterruptedException e)
+          {
+          }
 
-          new StructureViewer(af.getViewport().getStructureSelectionManager()).viewStructures(Viewer.CHIMERA,
-                  af.getCurrentView().getAlignPanel(),
-                  new PDBEntry[] { (PDBEntry)dsq.getPDBId().elementAt(q) },
-                  new SequenceI[][] { new SequenceI[] { sq } });
+          jmolViewer.closeViewer(true);
+          // todo: break here means only once through this loop?
           break;
         }
         break;
       }
-   }
-    try {
-      Thread.sleep(200000);
-    } catch (InterruptedException q)
+    }
+  }
+
+  @Test(groups ={ "Functional" })
+  public void testSingleSeqViewChimera()
+  {
+    String inFile = "examples/1gaq.txt";
+    AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
+            inFile, FormatAdapter.FILE);
+    assertTrue("Didn't read input file " + inFile, af != null);
+    for (SequenceI sq : af.getViewport().getAlignment().getSequences())
     {
-      
+      SequenceI dsq = sq.getDatasetSequence();
+      while (dsq.getDatasetSequence() != null)
+      {
+        dsq = dsq.getDatasetSequence();
+      }
+      if (dsq.getPDBId() != null && dsq.getPDBId().size() > 0)
+      {
+        for (int q = 0; q < dsq.getPDBId().size(); q++)
+        {
+          final StructureViewer structureViewer = new StructureViewer(af
+                  .getViewport().getStructureSelectionManager());
+          structureViewer.setViewerType(ViewerType.CHIMERA);
+          JalviewStructureDisplayI chimeraViewer = structureViewer
+                  .viewStructures(dsq.getPDBId().elementAt(q),
+                          new SequenceI[]
+                          { sq }, af.getCurrentView().getAlignPanel());
+          /*
+           * Wait for viewer thread to start
+           */
+          try
+          {
+            Thread.sleep(1000);
+          } catch (InterruptedException e)
+          {
+          }
+          chimeraViewer.closeViewer(true);
+          // todo: break here means only once through this loop?
+          break;
+        }
+        break;
+      }
     }
   }
 }