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 } };
}
}