3 import static org.junit.Assert.*;
5 import java.io.BufferedReader;
7 import java.io.InputStreamReader;
9 import org.junit.AfterClass;
10 import org.junit.BeforeClass;
11 import org.junit.Test;
13 public class CommandLineOperations
17 public static void setUpBeforeClass() throws Exception
22 public static void tearDownAfterClass() throws Exception
26 * from http://stackoverflow.com/questions/808276/how-to-add-a-timeout-value-when-using-javas-runtime-exec
30 private static class Worker extends Thread {
31 private final Process process;
33 private Worker(Process process) {
34 this.process = process;
38 exit = process.waitFor();
39 } catch (InterruptedException ignore) {
45 public void testHeadlessModeEPS() throws Exception
47 String[] headlessArgs=new String[] { "nodisplay","headless","nogui"};
48 for (String _harg:headlessArgs)
50 boolean _switch=false,withAwt=false;
57 String jalview_input = "examples/uniref50.fa";
58 String jalview_output = "test_uniref50_out.eps";
59 String cmd = "java "+(withAwt ? "-Djava.awt.headless=true":"")+" -Djava.ext.dirs=./lib -classpath ./classes jalview.bin.Jalview -"+_harg+" -open "+ jalview_input + " -eps " + jalview_output;
60 String harg = _harg+(withAwt ? "-Djava.awt.headless=true":" NO AWT.HEADLESS");
61 System.out.println("Testing with Headless argument: '"+harg+"'\n###############Jalview CMD: " + cmd);
62 Process ls2_proc = Runtime.getRuntime().exec(cmd);
63 BufferedReader outputReader = new BufferedReader(new InputStreamReader(ls2_proc.getInputStream()));
65 BufferedReader errorReader = new BufferedReader(new InputStreamReader(ls2_proc.getErrorStream()));
66 Worker worker = new Worker(ls2_proc);
69 System.out.println("Output: ");
71 while ((ln=outputReader.readLine())!=null) {
72 System.out.println(ln);
75 System.out.println("Error: " );
76 while ((ln=errorReader.readLine())!=null) {
77 System.out.println(ln);
79 assertTrue("Didn't create an output EPS file.["+harg+"]", new File("test_uniref50_out.eps").exists());
80 assertTrue("Didn't create an EPS file with any content["+harg+"]", new File("test_uniref50_out.eps").length()>4096);
81 if (worker.exit == null){
83 Thread.currentThread().interrupt();
85 fail("Jalview did not exit after EPS generation (try running test again to verify - timeout at 9000ms). ["+harg+"]");