2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 import static org.junit.Assert.*;
23 import java.io.BufferedReader;
25 import java.io.InputStreamReader;
27 import org.junit.AfterClass;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
31 public class CommandLineOperations
35 public static void setUpBeforeClass() throws Exception
40 public static void tearDownAfterClass() throws Exception
44 * from http://stackoverflow.com/questions/808276/how-to-add-a-timeout-value-when-using-javas-runtime-exec
48 private static class Worker extends Thread {
49 private final Process process;
51 private Worker(Process process) {
52 this.process = process;
56 exit = process.waitFor();
57 } catch (InterruptedException ignore) {
63 public void testHeadlessModeEPS() throws Exception
65 String[] headlessArgs=new String[] { "nodisplay","headless","nogui"};
66 for (String _harg:headlessArgs)
68 boolean _switch=false,withAwt=false;
75 String jalview_input = "examples/uniref50.fa";
76 String jalview_output = "test_uniref50_out.eps";
77 String cmd = "java "+(withAwt ? "-Djava.awt.headless=true":"")+" -Djava.ext.dirs=./lib -classpath ./classes jalview.bin.Jalview -"+_harg+" -open "+ jalview_input + " -eps " + jalview_output;
78 String harg = _harg+(withAwt ? "-Djava.awt.headless=true":" NO AWT.HEADLESS");
79 System.out.println("Testing with Headless argument: '"+harg+"'\n###############Jalview CMD: " + cmd);
80 Process ls2_proc = Runtime.getRuntime().exec(cmd);
81 BufferedReader outputReader = new BufferedReader(new InputStreamReader(ls2_proc.getInputStream()));
83 BufferedReader errorReader = new BufferedReader(new InputStreamReader(ls2_proc.getErrorStream()));
84 Worker worker = new Worker(ls2_proc);
87 System.out.println("Output: ");
89 while ((ln=outputReader.readLine())!=null) {
90 System.out.println(ln);
93 System.out.println("Error: " );
94 while ((ln=errorReader.readLine())!=null) {
95 System.out.println(ln);
97 assertTrue("Didn't create an output EPS file.["+harg+"]", new File("test_uniref50_out.eps").exists());
98 assertTrue("Didn't create an EPS file with any content["+harg+"]", new File("test_uniref50_out.eps").length()>4096);
99 if (worker.exit == null){
101 Thread.currentThread().interrupt();
103 fail("Jalview did not exit after EPS generation (try running test again to verify - timeout at 9000ms). ["+harg+"]");