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 jalview_input = "examples/uniref50.fa";
48 String jalview_output = "test_uniref50_out.eps";
49 String cmd = "java -Djava.awt.headless=true -Djava.ext.dirs=./lib -classpath ./classes jalview.bin.Jalview -nodisplay -open "+ jalview_input + " -eps " + jalview_output;
51 System.out.println("###############Jalview CMD: " + cmd);
52 Process ls2_proc = Runtime.getRuntime().exec(cmd);
53 BufferedReader outputReader = new BufferedReader(new InputStreamReader(ls2_proc.getInputStream()));
55 BufferedReader errorReader = new BufferedReader(new InputStreamReader(ls2_proc.getErrorStream()));
56 Worker worker = new Worker(ls2_proc);
59 System.out.println("Output: ");
61 while ((ln=outputReader.readLine())!=null) {
62 System.out.println(ln);
65 System.out.println("Error: " );
66 while ((ln=errorReader.readLine())!=null) {
67 System.out.println(ln);
69 assertTrue("Didn't create an output EPS file.", new File("test_uniref50_out.eps").exists());
70 assertTrue("Didn't create an EPS file with any content", new File("test_uniref50_out.eps").length()>4096);
71 if (worker.exit == null){
73 Thread.currentThread().interrupt();
75 fail("Jalview did not exit after EPS generation (try running test again to verify - timeout at 9000ms).");