Merge branch 'develop' into features/r2_11_2_alphafold/JAL-629
[jalview.git] / test / jalview / bin / CommandsTest.java
index b4c927b..73a0241 100644 (file)
@@ -19,7 +19,6 @@ import jalview.gui.Desktop;
 import jalview.gui.JvOptionPane;
 import jalview.util.ArrayUtils;
 
-@Test
 public class CommandsTest
 {
   private static final String testfiles = "test/jalview/bin/argparser/testfiles";
@@ -49,8 +48,15 @@ public class CommandsTest
   @AfterMethod(alwaysRun = true)
   public void tearDown()
   {
-    if (Desktop.instance != null)
-      Desktop.instance.closeAll_actionPerformed(null);
+    Desktop.closeDesktop();
+  }
+  
+  public static void callJalviewMain(String[] args) {
+    if (Jalview.getInstance()!=null) {
+      Jalview.getInstance().doMain(args);
+    } else {
+      Jalview.main(args);
+    }
   }
 
   /* --setprops is currently disabled so this test won't work
@@ -70,67 +76,86 @@ public class CommandsTest
   public void commandsOpenTest(String cmdLine, boolean cmdArgs,
           int numFrames, String[] sequences)
   {
-    String[] args = (cmdLine + " --gui").split("\\s+");
-    Jalview.main(args);
-    Commands cmds = Jalview.getInstance().getCommands();
-    Assert.assertNotNull(cmds);
-    Assert.assertEquals(cmds.commandArgsProvided(), cmdArgs,
-            "Commands were not provided in the args");
-    Assert.assertEquals(cmds.argsWereParsed(), cmdArgs,
-            "Overall command parse and operation is false");
+    try
+    {
+      String[] args = (cmdLine + " --gui").split("\\s+");
+      callJalviewMain(args);
+      Commands cmds = Jalview.getInstance().getCommands();
+      Assert.assertNotNull(cmds);
+      Assert.assertEquals(cmds.commandArgsProvided(), cmdArgs,
+              "Commands were not provided in the args");
+      Assert.assertEquals(cmds.argsWereParsed(), cmdArgs,
+              "Overall command parse and operation is false");
 
-    Assert.assertEquals(Desktop.getAlignFrames().length, numFrames,
-            "Wrong number of AlignFrames");
+      Assert.assertEquals(Desktop.getAlignFrames().length, numFrames,
+              "Wrong number of AlignFrames");
 
-    if (sequences != null)
-    {
-      Set<String> openedSequenceNames = new HashSet<>();
-      AlignFrame[] afs = Desktop.getAlignFrames();
-      for (AlignFrame af : afs)
-      {
-        openedSequenceNames
-                .addAll(af.getViewport().getAlignment().getSequenceNames());
-      }
-      for (String sequence : sequences)
+      if (sequences != null)
       {
-        Assert.assertTrue(openedSequenceNames.contains(sequence),
-                "Sequence '" + sequence
-                        + "' was not found in opened alignment files: "
-                        + cmdLine + ".\nOpened sequence names are:\n"
-                        + String.join("\n", openedSequenceNames));
+        Set<String> openedSequenceNames = new HashSet<>();
+        AlignFrame[] afs = Desktop.getAlignFrames();
+        for (AlignFrame af : afs)
+        {
+          openedSequenceNames.addAll(
+                  af.getViewport().getAlignment().getSequenceNames());
+        }
+        for (String sequence : sequences)
+        {
+          Assert.assertTrue(openedSequenceNames.contains(sequence),
+                  "Sequence '" + sequence
+                          + "' was not found in opened alignment files: "
+                          + cmdLine + ".\nOpened sequence names are:\n"
+                          + String.join("\n", openedSequenceNames));
+        }
       }
-    }
 
-    Assert.assertFalse(
-            lookForSequenceName("THIS_SEQUENCE_ID_DOESN'T_EXIST"));
+      Assert.assertFalse(
+              lookForSequenceName("THIS_SEQUENCE_ID_DOESN'T_EXIST"));
+    } catch (Exception x)
+    {
+      Assert.fail("Unexpected exception during commandsOpenTest", x);
+    } finally
+    {
+      tearDown();
+
+    }
   }
 
-  @Test(groups = "Functional", dataProvider = "structureImageOutputFiles")
+  @Test(groups = {"Functional","testTask1"}, dataProvider = "structureImageOutputFiles")
   public void structureImageOutputTest(String cmdLine, String[] filenames)
           throws IOException
   {
     cleanupFiles(filenames);
     String[] args = (cmdLine + " --gui").split("\\s+");
-    Jalview.main(args);
-    Commands cmds = Jalview.getInstance().getCommands();
-    Assert.assertNotNull(cmds);
-    File lastFile = null;
-    for (String filename : filenames)
+    try
     {
-      File file = new File(filename);
-      Assert.assertTrue(file.exists(), "File '" + filename
-              + "' was not created by '" + cmdLine + "'");
-      Assert.assertTrue(file.isFile(), "File '" + filename
-              + "' is not a file from '" + cmdLine + "'");
-      Assert.assertTrue(Files.size(file.toPath()) > 0, "File '" + filename
-              + "' has no content from '" + cmdLine + "'");
-      // make sure the successive output files get bigger!
-      if (lastFile != null)
-        Assert.assertTrue(
-                Files.size(file.toPath()) > Files.size(lastFile.toPath()));
+      callJalviewMain(args);
+      Commands cmds = Jalview.getInstance().getCommands();
+      Assert.assertNotNull(cmds);
+      File lastFile = null;
+      for (String filename : filenames)
+      {
+        File file = new File(filename);
+        Assert.assertTrue(file.exists(), "File '" + filename
+                + "' was not created by '" + cmdLine + "'");
+        Assert.assertTrue(file.isFile(), "File '" + filename
+                + "' is not a file from '" + cmdLine + "'");
+        Assert.assertTrue(Files.size(file.toPath()) > 0, "File '" + filename
+                + "' has no content from '" + cmdLine + "'");
+        // make sure the successive output files get bigger!
+        if (lastFile != null)
+          Assert.assertTrue(Files.size(file.toPath()) > Files
+                  .size(lastFile.toPath()));
+      }
+    } catch (Exception x)
+    {
+      Assert.fail("Unexpected exception during structureImageOutputTest",
+              x);
+    } finally
+    {
+      cleanupFiles(filenames);
+      tearDown();
     }
-    cleanupFiles(filenames);
-    tearDown();
   }
 
   @Test(groups = "Functional", dataProvider = "argfileOutputFiles")
@@ -139,7 +164,8 @@ public class CommandsTest
   {
     cleanupFiles(filenames);
     String[] args = (cmdLine + " --gui").split("\\s+");
-    Jalview.main(args);
+    try {
+    callJalviewMain(args);
     Commands cmds = Jalview.getInstance().getCommands();
     Assert.assertNotNull(cmds);
     File lastFile = null;
@@ -157,8 +183,15 @@ public class CommandsTest
         Assert.assertTrue(
                 Files.size(file.toPath()) > Files.size(lastFile.toPath()));
     }
-    cleanupFiles(filenames);
-    tearDown();
+    } catch (Exception x)
+    {
+      Assert.fail("Unexpected exception during argFilesGlobAndSubstitutions",
+              x);
+    } finally
+    {
+      cleanupFiles(filenames);
+      tearDown();
+    }
   }
 
   @DataProvider(name = "structureImageOutputFiles")
@@ -297,7 +330,7 @@ public class CommandsTest
           String[] nonfilenames)
   {
     String[] args = (cmdLine + " --gui").split("\\s+");
-    Jalview.main(args);
+    callJalviewMain(args);
     Commands cmds = Jalview.getInstance().getCommands();
     Assert.assertNotNull(cmds);
     for (String filename : filenames)