JAL-4353 singleThread all tests
[jalview.git] / test / jalview / bin / CommandsTest.java
index 36522c4..2d54093 100644 (file)
@@ -1,12 +1,35 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 package jalview.bin;
 
 import java.io.File;
 import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
 import java.nio.file.Files;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.swing.SwingUtilities;
+
 import org.testng.Assert;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.AfterMethod;
@@ -48,7 +71,24 @@ public class CommandsTest
   @AfterMethod(alwaysRun = true)
   public void tearDown()
   {
-    Desktop.closeDesktop();
+    try
+    {
+      // occasionally we are blocked by Jmol redraws
+      SwingUtilities.invokeAndWait(new Runnable()
+      {
+
+        @Override
+        public void run()
+        {
+          Desktop.closeDesktop();
+        }
+      });
+    } catch (Exception foo)
+    {
+      System.err.println("Failed during teardown with exception");
+      foo.printStackTrace();
+    }
+
   }
 
   public static void callJalviewMain(String[] args)
@@ -76,7 +116,8 @@ public class CommandsTest
   }
   */
 
-  @Test(groups = "Functional", dataProvider = "cmdLines")
+  @Test(groups = { "Functional", "testTask3" }, dataProvider = "cmdLines", singleThreaded = true)
+
   public void commandsOpenTest(String cmdLine, boolean cmdArgs,
           int numFrames, String[] sequences)
   {
@@ -91,13 +132,13 @@ public class CommandsTest
       Assert.assertEquals(cmds.argsWereParsed(), cmdArgs,
               "Overall command parse and operation is false");
 
-      Assert.assertEquals(Desktop.getAlignFrames().length, numFrames,
+      Assert.assertEquals(Desktop.getDesktopAlignFrames().length, numFrames,
               "Wrong number of AlignFrames");
 
       if (sequences != null)
       {
         Set<String> openedSequenceNames = new HashSet<>();
-        AlignFrame[] afs = Desktop.getAlignFrames();
+        AlignFrame[] afs = Desktop.getDesktopAlignFrames();
         for (AlignFrame af : afs)
         {
           openedSequenceNames.addAll(
@@ -127,8 +168,8 @@ public class CommandsTest
 
   @Test(
     groups =
-    { "Functional", "testTask1" },
-    dataProvider = "structureImageOutputFiles")
+    { "Functional", "testTask3" },
+    dataProvider = "structureImageOutputFiles",    singleThreaded = true)
   public void structureImageOutputTest(String cmdLine, String[] filenames)
           throws IOException
   {
@@ -150,9 +191,13 @@ public class CommandsTest
         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()));
+               if (lastFile != null) {
+                       Assert.assertTrue(Files.size(file.toPath()) > Files.size(lastFile.toPath()));
+                       System.out.println("this file: " + file + " +" + Files.size(file.toPath()) + " greater than "
+                                       + Files.size(lastFile.toPath()));
+               }
+               // remember it for next file
+               lastFile = file;
       }
     } catch (Exception x)
     {
@@ -165,7 +210,7 @@ public class CommandsTest
     }
   }
 
-  @Test(groups = "Functional", dataProvider = "argfileOutputFiles")
+  @Test(groups = "Functional", dataProvider = "argfileOutputFiles", singleThreaded = true)
   public void argFilesGlobAndSubstitutionsTest(String cmdLine,
           String[] filenames) throws IOException
   {
@@ -187,9 +232,13 @@ public class CommandsTest
         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)
+        if (lastFile != null) {
           Assert.assertTrue(Files.size(file.toPath()) > Files
                   .size(lastFile.toPath()));
+          System.out.println("this file: "+file+" +"+Files.size(file.toPath()) + " greater than " +Files.size(lastFile.toPath()));
+        }
+        // remember it for next file
+        lastFile = file;
       }
     } catch (Exception x)
     {
@@ -214,11 +263,11 @@ public class CommandsTest
                 + "--open=./examples/test_fab41.result/sample.a2m "
                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
                 + "--structureimage=" + testfiles
-                + "/structureimage2.png --structureimagescale=1.5"
+                + "/structureimage2.png --scale=1.5 "
                 + "--open=./examples/test_fab41.result/sample.a2m "
                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
                 + "--structureimage=" + testfiles
-                + "/structureimage3.png --structureimagescale=2.0",
+                + "/structureimage3.png --scale=2.0 ",
             new String[]
             { testfiles + "/structureimage1.png",
                 testfiles + "/structureimage2.png",
@@ -229,15 +278,28 @@ public class CommandsTest
                 + "--open=./examples/test_fab41.result/sample.a2m "
                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
                 + "--structureimage=" + testfiles
-                + "/structureimage2.png --structureimagescale=1.5"
+                + "/structureimage2.png --scale=1.5 "
                 + "--open=./examples/test_fab41.result/sample.a2m "
                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
                 + "--structureimage=" + testfiles
-                + "/structureimage3.png --structureimagescale=2.0",
+                + "/structureimage3.png --scale=2.0 ",
             new String[]
             { testfiles + "/structureimage1.png",
                 testfiles + "/structureimage2.png",
                 testfiles + "/structureimage3.png" } },
+        { "--gui --nonews --nosplash --open examples/1gaq.txt --append ./examples/3W5V.pdb "+"--structure examples/1gaq.txt --seqid \"1GAQ|A\" "+"--structureimage "+testfiles+"/1gaq.png --structure examples/3W5V.pdb "+"--seqid \"3W5V|A\" --structureimage "+testfiles+"/3w5v.png --overwrite",
+                       
+                new String[] {
+                               testfiles+"/1gaq.png",testfiles+"/3w5v.png"
+                }
+        },
+        { "--headless --noquit --open ./examples/1gaq.txt --append ./examples/3W5V.pdb "+"--structure examples/1gaq.txt --seqid \"1GAQ|A\" "+"--structureimage "+testfiles+"/1gaq.png --structure examples/3W5V.pdb "+"--seqid \"3W5V|A\" --structureimage "+testfiles+"/3w5v.png --overwrite",
+               
+            new String[] {
+                       testfiles+"/1gaq.png",testfiles+"/3w5v.png"
+            }
+    }
+
         /*
                 */
         //
@@ -305,7 +367,7 @@ public class CommandsTest
 
   public static boolean lookForSequenceName(String sequenceName)
   {
-    AlignFrame[] afs = Desktop.getAlignFrames();
+    AlignFrame[] afs = Desktop.getDesktopAlignFrames();
     for (AlignFrame af : afs)
     {
       for (String name : af.getViewport().getAlignment().getSequenceNames())
@@ -331,6 +393,8 @@ public class CommandsTest
     }
   }
 
+  private final String deleteDir = "test/deleteAfter";
+
   @Test(
     groups = "Functional",
     dataProvider = "allLinkedIdsData",
@@ -357,6 +421,12 @@ public class CommandsTest
                 "File " + nonfilename + " exists when it shouldn't!");
       }
     }
+
+    File deleteDirF = new File(deleteDir);
+    if (deleteDirF.exists())
+    {
+      deleteDirF.delete();
+    }
   }
 
   @DataProvider(name = "allLinkedIdsData")
@@ -506,6 +576,81 @@ public class CommandsTest
                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.aln",
                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.aln",
                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.aln", }, },
+        // --mkdirs
+        { "--headless --open=test/jalview/bin/argparser/testfiles/dir1/*.fa --output "
+                + deleteDir
+                + "/{dirname}/{basename}.stk --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --output="
+                + deleteDir
+                + "/{dirname}/{basename}.aln --close --all --mkdirs",
+            new String[]
+            { deleteDir
+                    + "/test/jalview/bin/argparser/testfiles/dir1/test1.stk",
+                deleteDir
+                        + "/test/jalview/bin/argparser/testfiles/dir1/test2.stk",
+                deleteDir
+                        + "/test/jalview/bin/argparser/testfiles/dir2/test1.aln",
+                deleteDir
+                        + "/test/jalview/bin/argparser/testfiles/dir2/test2.aln",
+                deleteDir
+                        + "/test/jalview/bin/argparser/testfiles/dir2/test3.aln", },
+            new String[]
+            { "test/jalview/bin/argparser/testfiles/test1.stk",
+                "test/jalview/bin/argparser/testfiles/test2.stk",
+                "test/jalview/bin/argparser/testfiles/test3.stk",
+                "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
+                "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
+                "test/jalview/bin/argparser/testfiles/dir2/test3.stk",
+                "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
+                "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
+                "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
+                "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk",
+                "test/jalview/bin/argparser/testfiles/test1.aln",
+                "test/jalview/bin/argparser/testfiles/test2.aln",
+                "test/jalview/bin/argparser/testfiles/test3.aln",
+                "test/jalview/bin/argparser/testfiles/dir1/test1.aln",
+                "test/jalview/bin/argparser/testfiles/dir1/test2.aln",
+                "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.aln",
+                "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.aln",
+                "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.aln",
+                "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.aln",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/test1.stk",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/test2.stk",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/test3.stk",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/dir2/test3.stk",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/test1.aln",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/test2.aln",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/test3.aln",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/dir1/test1.aln",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/dir1/test2.aln",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.aln",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.aln",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.aln",
+                deleteDir
+                        + "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.aln", }, },
         //
     };
   }