X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fbin%2FCommandsTest.java;h=65162f3f51f9ba404f71ad2bc60fc106ced7ec51;hb=a5928e2c1b9e2cea8d9c43f3d03f9cce2604f3b2;hp=e4fea7b18c2803c24106f64735d3e8f371ac3e8a;hpb=5afaa80bd2cddc6651867f86a04affffa0896f89;p=jalview.git diff --git a/test/jalview/bin/CommandsTest.java b/test/jalview/bin/CommandsTest.java index e4fea7b..65162f3 100644 --- a/test/jalview/bin/CommandsTest.java +++ b/test/jalview/bin/CommandsTest.java @@ -1,103 +1,86 @@ 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.AfterMethod; +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; + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } - public synchronized static String getClassPath() + @AfterMethod(alwaysRun = true) + public void tearDown() { - java_exe = System.getProperty("java.home") + File.separator + "bin" - + File.separator + "java"; - classpath = ManagementFactory.getRuntimeMXBean().getClassPath(); - return classpath; + Desktop.instance.closeAll_actionPerformed(null); } - 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 + String[] args = cmdLine.split("\\s+"); + Jalview.main(args); + Commands cmds = Jalview.getInstance().getCommands(); + Assert.assertNotNull(cmds); + Assert.assertTrue(cmds.commandArgsProvided(), + "Commands were not provided in the args"); + Assert.assertTrue(cmds.argsWereParsed(), + "Overall command parse and operation is false"); + + if (sequence != null) { - ls2_proc = Runtime.getRuntime().exec(_cmd + cmd); - } catch (Throwable e1) - { - e1.printStackTrace(); + Assert.assertTrue(lookForSequenceName(sequence), + "Sequence '" + sequence + + "' was not found in opened alignment files: " + + cmdLine); } - if (ls2_proc != null) + + System.out.println("##### GOT TO END"); + } + + public static boolean lookForSequenceName(String sequenceName) + { + AlignFrame[] afs = Desktop.getAlignFrames(); + for (AlignFrame af : afs) { - worker = new Worker(ls2_proc); - worker.start(); - try - { - worker.join(timeout); - } catch (InterruptedException e) + for (String name : af.getViewport().getAlignment().getSequenceNames()) { - System.err.println("Thread interrupted"); + if (sequenceName.equals(name)) + { + return true; + } } } - return worker; - } - - @BeforeTest(alwaysRun = true) - public void initialize() - { - new CommandsTest(); + return false; } - @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 } }; } }