X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fbin%2FCommandsTest.java;h=36522c43836e5ab4ec5677f66e3eaec8ae199a48;hb=871535152992c147f2175c3006b6bec4615fead4;hp=20ccd110cd1e0155cb8f085a5a84c3203121f007;hpb=fc07ec3706c45b21d90eadddd00f23d6318a7008;p=jalview.git diff --git a/test/jalview/bin/CommandsTest.java b/test/jalview/bin/CommandsTest.java index 20ccd11..36522c4 100644 --- a/test/jalview/bin/CommandsTest.java +++ b/test/jalview/bin/CommandsTest.java @@ -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,19 @@ 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,39 +80,89 @@ public class CommandsTest public void commandsOpenTest(String cmdLine, boolean cmdArgs, int numFrames, String[] sequences) { - String[] args = cmdLine.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 openedSequenceNames = new HashSet<>(); - AlignFrame[] afs = Desktop.getAlignFrames(); - for (AlignFrame af : afs) + if (sequences != null) { - openedSequenceNames - .addAll(af.getViewport().getAlignment().getSequenceNames()); + Set 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)); + } } - for (String sequence : sequences) + + Assert.assertFalse( + lookForSequenceName("THIS_SEQUENCE_ID_DOESN'T_EXIST")); + } catch (Exception x) + { + Assert.fail("Unexpected exception during commandsOpenTest", x); + } finally + { + tearDown(); + + } + } + + @Test( + groups = + { "Functional", "testTask1" }, + dataProvider = "structureImageOutputFiles") + public void structureImageOutputTest(String cmdLine, String[] filenames) + throws IOException + { + cleanupFiles(filenames); + String[] args = (cmdLine + " --gui").split("\\s+"); + try + { + callJalviewMain(args); + Commands cmds = Jalview.getInstance().getCommands(); + Assert.assertNotNull(cmds); + File lastFile = null; + for (String filename : filenames) { - Assert.assertTrue(openedSequenceNames.contains(sequence), - "Sequence '" + sequence - + "' was not found in opened alignment files: " - + cmdLine + ".\nOpened sequence names are:\n" - + String.join("\n", openedSequenceNames)); + 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(); } - - Assert.assertFalse( - lookForSequenceName("THIS_SEQUENCE_ID_DOESN'T_EXIST")); } @Test(groups = "Functional", dataProvider = "argfileOutputFiles") @@ -110,27 +170,79 @@ public class CommandsTest String[] filenames) throws IOException { cleanupFiles(filenames); - String[] args = cmdLine.split("\\s+"); - Jalview.main(args); - Commands cmds = Jalview.getInstance().getCommands(); - Assert.assertNotNull(cmds); - File lastFile = null; - for (String filename : filenames) + String[] args = (cmdLine + " --gui").split("\\s+"); + 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 argFilesGlobAndSubstitutions", + x); + } finally + { + cleanupFiles(filenames); + tearDown(); } - cleanupFiles(filenames); - tearDown(); + } + + @DataProvider(name = "structureImageOutputFiles") + public Object[][] structureImageOutputFiles() + { + return new Object[][] { + // + { "--gui --nonews --nosplash --open=./examples/test_fab41.result/sample.a2m " + + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb " + + "--structureimage=" + testfiles + "/structureimage1.png " + + "--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" + + "--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", + new String[] + { testfiles + "/structureimage1.png", + testfiles + "/structureimage2.png", + testfiles + "/structureimage3.png" } }, + { "--headless --noquit --open=./examples/test_fab41.result/sample.a2m " + + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb " + + "--structureimage=" + testfiles + "/structureimage1.png " + + "--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" + + "--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", + new String[] + { testfiles + "/structureimage1.png", + testfiles + "/structureimage2.png", + testfiles + "/structureimage3.png" } }, + /* + */ + // + }; + } @DataProvider(name = "argfileOutputFiles") @@ -138,18 +250,18 @@ public class CommandsTest { return new Object[][] { // - { "--argfile=" + testfiles + "/**/*.txt", new String[] + { "--gui --argfile=" + testfiles + "/**/*.txt", new String[] { testfiles + "/dir1/test1.png", testfiles + "/dir2/test1.png", testfiles + "/dir3/subdir/test0.png" } }, - { "--argfile=" + testfiles + "/**/argfile.txt", new String[] + { "--gui --argfile=" + testfiles + "/**/argfile.txt", new String[] { testfiles + "/dir1/test1.png", testfiles + "/dir2/test1.png" } }, - { "--argfile=" + testfiles + "/dir*/argfile.txt", new String[] + { "--gui --argfile=" + testfiles + "/dir*/argfile.txt", new String[] { testfiles + "/dir1/test1.png", testfiles + "/dir2/test1.png" } }, - { "--initsubstitutions --append examples/uniref50.fa --image " + { "--gui --initsubstitutions --append examples/uniref50.fa --image " + testfiles + "/{basename}.png", new String[] { testfiles + "/uniref50.png" } }, - { "--append examples/uniref50.fa --nosubstitutions --image " + { "--gui --append examples/uniref50.fa --nosubstitutions --image " + testfiles + "/{basename}.png", new String[] { testfiles + "/{basename}.png" } } @@ -182,11 +294,11 @@ public class CommandsTest { "examples/uniref50.fa " + testfiles + "/test1.fa", true, 2, ArrayUtils.concatArrays(someUniref50Seqs, t1) }, { "examples/uniref50.fa " + testfiles + "/test1.fa", true, 2, t1 }, - { "--argfile=" + testfiles + "/argfile0.txt", true, 1, + { "--gui --argfile=" + testfiles + "/argfile0.txt", true, 1, ArrayUtils.concatArrays(t1, t3) }, - { "--argfile=" + testfiles + "/argfile*.txt", true, 5, + { "--gui --argfile=" + testfiles + "/argfile*.txt", true, 5, ArrayUtils.concatArrays(t1, t2, t3) }, - { "--argfile=" + testfiles + "/argfile.autocounter", true, 3, + { "--gui --argfile=" + testfiles + "/argfile.autocounter", true, 3, ArrayUtils.concatArrays(t1, t2) } }; } @@ -226,8 +338,8 @@ public class CommandsTest public void allLinkedIdsTest(String cmdLine, String[] filenames, String[] nonfilenames) { - String[] args = cmdLine.split("\\s+"); - Jalview.main(args); + String[] args = (cmdLine + " --gui").split("\\s+"); + callJalviewMain(args); Commands cmds = Jalview.getInstance().getCommands(); Assert.assertNotNull(cmds); for (String filename : filenames) @@ -252,21 +364,19 @@ public class CommandsTest { return new Object[][] { // - /* - */ - { "--open=test/jalview/bin/argparser/testfiles/*.fa --substitutions --all --output={dirname}/{basename}.stk --close", + { "--gui --open=test/jalview/bin/argparser/testfiles/*.fa --substitutions --all --output={dirname}/{basename}.stk --close", new String[] { "test/jalview/bin/argparser/testfiles/test1.stk", "test/jalview/bin/argparser/testfiles/test2.stk", "test/jalview/bin/argparser/testfiles/test3.stk", }, null }, - { "--open=test/jalview/bin/argparser/testfiles/*.fa --substitutions --all --image={dirname}/{basename}.png --close", + { "--gui --open=test/jalview/bin/argparser/testfiles/*.fa --substitutions --all --image={dirname}/{basename}.png --close", new String[] { "test/jalview/bin/argparser/testfiles/test1.png", "test/jalview/bin/argparser/testfiles/test2.png", "test/jalview/bin/argparser/testfiles/test3.png", }, null }, - { "--open=test/jalview/bin/argparser/testfiles/*.fa --all --output={dirname}/{basename}.stk --close", + { "--gui --open=test/jalview/bin/argparser/testfiles/*.fa --all --output={dirname}/{basename}.stk --close", new String[] { "test/jalview/bin/argparser/testfiles/test1.stk", "test/jalview/bin/argparser/testfiles/test2.stk", @@ -281,7 +391,7 @@ public class CommandsTest "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", }, }, - { "--open=test/jalview/bin/argparser/**/*.fa --all --output={dirname}/{basename}.stk --close", + { "--gui --open=test/jalview/bin/argparser/**/*.fa --all --output={dirname}/{basename}.stk --close", new String[] { "test/jalview/bin/argparser/testfiles/test1.stk", "test/jalview/bin/argparser/testfiles/test2.stk", @@ -296,7 +406,7 @@ public class CommandsTest "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk", "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk", }, null }, - { "--open=test/jalview/bin/argparser/**/*.fa --output=*.stk --close", + { "--gui --open=test/jalview/bin/argparser/**/*.fa --output=*/*.stk --close", new String[] { "test/jalview/bin/argparser/testfiles/test1.stk", "test/jalview/bin/argparser/testfiles/test2.stk", @@ -311,7 +421,7 @@ public class CommandsTest "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk", "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk", }, null }, - { "--open=test/jalview/bin/argparser/testfiles/dir1/*.fa --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --output=*.stk --close", + { "--gui --open=test/jalview/bin/argparser/testfiles/dir1/*.fa --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --all --output=*/*.stk --close", new String[] { "test/jalview/bin/argparser/testfiles/dir1/test1.stk", "test/jalview/bin/argparser/testfiles/dir1/test2.stk", @@ -326,7 +436,20 @@ public class CommandsTest "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", }, }, - { "--open=test/jalview/bin/argparser/testfiles/dir1/*.fa --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --output=open*.stk --close", + { "--gui --open=test/jalview/bin/argparser/testfiles/dir1/*.fa --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --output=*/*.stk --close", + new String[] + { "test/jalview/bin/argparser/testfiles/dir2/test1.stk", + "test/jalview/bin/argparser/testfiles/dir2/test2.stk", + "test/jalview/bin/argparser/testfiles/dir2/test3.stk", }, + 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/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", }, }, + { "--gui --open=test/jalview/bin/argparser/testfiles/dir1/*.fa --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --output={dirname}/{basename}.stk --close", new String[] { "test/jalview/bin/argparser/testfiles/dir2/test1.stk", "test/jalview/bin/argparser/testfiles/dir2/test2.stk", @@ -341,7 +464,7 @@ public class CommandsTest "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", }, }, - { "--open=test/jalview/bin/argparser/testfiles/dir1/*.fa --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --opened --output={dirname}/{basename}.stk --close", + { "--gui --open=test/jalview/bin/argparser/testfiles/dir1/*.fa --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --output={dirname}/{basename}.stk --close", new String[] { "test/jalview/bin/argparser/testfiles/dir2/test1.stk", "test/jalview/bin/argparser/testfiles/dir2/test2.stk", @@ -356,7 +479,7 @@ public class CommandsTest "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", }, }, - { "--open=test/jalview/bin/argparser/testfiles/dir1/*.fa --output open*.stk --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --output=open*.aln --close", + { "--gui --open=test/jalview/bin/argparser/testfiles/dir1/*.fa --output {dirname}/{basename}.stk --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --output={dirname}/{basename}.aln --close", new String[] { "test/jalview/bin/argparser/testfiles/dir1/test1.stk", "test/jalview/bin/argparser/testfiles/dir1/test2.stk",