From 01ef8b680f9a74d03b1d2b0228185a26f5fb584c Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Sat, 11 Mar 2023 00:12:45 +0000 Subject: [PATCH] JAL-629 start of CommandsTest. More ArgParserTests. --- test/jalview/bin/ArgParserTest.java | 16 ++++- test/jalview/bin/CommandsTest.java | 123 +++++++++++++---------------------- 2 files changed, 59 insertions(+), 80 deletions(-) diff --git a/test/jalview/bin/ArgParserTest.java b/test/jalview/bin/ArgParserTest.java index 9d4a8be..b72fcb9 100644 --- a/test/jalview/bin/ArgParserTest.java +++ b/test/jalview/bin/ArgParserTest.java @@ -12,6 +12,7 @@ import org.testng.annotations.Test; import jalview.bin.ArgParser.Arg; import jalview.bin.ArgParser.BootstrapArgs; +@Test(singleThreaded = true) public class ArgParserTest { @@ -77,11 +78,12 @@ public class ArgParserTest } } - @DataProvider(name = "argLinesTest") + @DataProvider(name = "argLinesNotworking") public Object[][] argLinesTest() { return new Object[][] { - // can't use this one yet as it doesn't get shell expanded + // can't use this one yet as it doesn't get shell glob expanded by the + // test { "--argfile test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE, "test/jalview/bin/argparser/argfile0.txt" }, }; } @@ -96,12 +98,22 @@ public class ArgParserTest Arg.HEADLESS, null }, { "--open=test/jalview/bin/argparser/test1.fa --props=test/jalview/bin/argparser/testProps.jvprops", Arg.PROPS, "true" }, + { "--argfile test/jalview/bin/argparser/argfile0.txt", Arg.ARGFILE, + "test/jalview/bin/argparser/argfile0.txt" }, + // these next three are what a shell glob expansion would look like + { "--argfile test/jalview/bin/argparser/argfile0.txt test/jalview/bin/argparser/argfile1.txt test/jalview/bin/argparser/argfile2.txt", + Arg.ARGFILE, "test/jalview/bin/argparser/argfile0.txt" }, + { "--argfile test/jalview/bin/argparser/argfile0.txt test/jalview/bin/argparser/argfile1.txt test/jalview/bin/argparser/argfile2.txt", + Arg.ARGFILE, "test/jalview/bin/argparser/argfile1.txt" }, + { "--argfile test/jalview/bin/argparser/argfile0.txt test/jalview/bin/argparser/argfile1.txt test/jalview/bin/argparser/argfile2.txt", + Arg.ARGFILE, "test/jalview/bin/argparser/argfile2.txt" }, { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE, "test/jalview/bin/argparser/argfile0.txt" }, { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE, "test/jalview/bin/argparser/argfile1.txt" }, { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE, "test/jalview/bin/argparser/argfile2.txt" } }; + } @DataProvider(name = "argFiles") diff --git a/test/jalview/bin/CommandsTest.java b/test/jalview/bin/CommandsTest.java index e4fea7b..9c763e1 100644 --- a/test/jalview/bin/CommandsTest.java +++ b/test/jalview/bin/CommandsTest.java @@ -1,103 +1,70 @@ package jalview.bin; -import java.io.File; -import java.io.IOException; -import java.lang.management.ManagementFactory; +import java.util.Date; -import org.testng.annotations.BeforeTest; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import io.github.classgraph.ClassGraph; +import jalview.gui.AlignFrame; +import jalview.gui.Desktop; +import jalview.gui.JvOptionPane; +@Test(singleThreaded = true) public class CommandsTest { - - private static final int SETUP_TIMEOUT = 30000; - - private static class Worker extends Thread + @BeforeClass(alwaysRun = true) + public static void setUpBeforeClass() throws Exception { - private final Process process; - - private Integer exit; - - private Worker(Process process) - { - this.process = process; - } - - @Override - public void run() - { - try - { - exit = process.waitFor(); - } catch (InterruptedException ignore) - { - return; - } - } + Cache.loadProperties("test/jalview/gui/quitProps.jvprops"); + Date oneHourFromNow = new Date( + System.currentTimeMillis() + 3600 * 1000); + Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED", oneHourFromNow); } - private static ClassGraph scanner = null; - - private static String classpath = null; - - private static String modules = null; - - private static String java_exe = null; - - public synchronized static String getClassPath() + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() { - java_exe = System.getProperty("java.home") + File.separator + "bin" - + File.separator + "java"; - classpath = ManagementFactory.getRuntimeMXBean().getClassPath(); - return classpath; + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); } - private Worker getJalviewDesktopRunner(boolean withAwt, String cmd, - int timeout) + @Test(groups = "Functional", dataProvider = "cmdLines") + public void commandsOpenTest(String cmdLine, String sequence) { - // Note: JAL-3065 - don't include quotes for lib/* because the arguments are - // not expanded by the shell - String classpath = getClassPath(); - String _cmd = java_exe + " " - + (withAwt ? "-Djava.awt.headless=true" : "") + " -classpath " - + classpath + " jalview.bin.Jalview "; - Process ls2_proc = null; - Worker worker = null; - try - { - ls2_proc = Runtime.getRuntime().exec(_cmd + cmd); - } catch (Throwable e1) - { - e1.printStackTrace(); - } - if (ls2_proc != null) + String[] args = cmdLine.split("\\s+"); + Jalview.main(args); + ArgParser argparser = new ArgParser(args); + boolean commandsSuccess = Commands.processArgs(argparser, false); + Assert.assertTrue(commandsSuccess, "Overall commandsSuccess is false"); + + if (sequence != null) { - worker = new Worker(ls2_proc); - worker.start(); - try - { - worker.join(timeout); - } catch (InterruptedException e) + AlignFrame[] afs = Desktop.getAlignFrames(); + boolean found = false; + ALIGNFRAME: for (AlignFrame af : afs) { - System.err.println("Thread interrupted"); + for (String name : af.getViewport().getAlignment() + .getSequenceNames()) + { + if (sequence.equals(name)) + { + found = true; + break ALIGNFRAME; + } + } } + Assert.assertTrue(found, "Sequence '" + sequence + + "' was not found in opened alignment files: " + cmdLine); } - return worker; - } - - @BeforeTest(alwaysRun = true) - public void initialize() - { - new CommandsTest(); } - @Test(groups = "Functional") - public void setUpForHeadlessCommandsTest() throws IOException + @DataProvider(name = "cmdLines") + public Object[][] cmdLines() { - String cmds = "--open=./examples/uniref50.fa"; - Worker worker = getJalviewDesktopRunner(true, cmds, SETUP_TIMEOUT); + return new Object[][] { { "--open=examples/uniref50.fa", "FER1_SPIOL" }, + { "--argfile=test/jalview/bin/argparser/argfile0.txt", null } }; } } -- 1.7.10.2