2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import static org.junit.Assert.*;
25 import java.io.BufferedReader;
27 import java.io.IOException;
28 import java.io.InputStreamReader;
30 import org.junit.AfterClass;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
34 public class CommandLineOperations
38 public static void setUpBeforeClass() throws Exception
43 public static void tearDownAfterClass() throws Exception
47 * from http://stackoverflow.com/questions/808276/how-to-add-a-timeout-value-when-using-javas-runtime-exec
51 private static class Worker extends Thread {
52 private final Process process;
54 private Worker(Process process) {
55 this.process = process;
59 exit = process.waitFor();
60 } catch (InterruptedException ignore) {
65 private Worker jalviewDesktopRunner(boolean withAwt, String cmd, int timeout) throws InterruptedException, IOException
67 String _cmd = "java "+(withAwt ? "-Djava.awt.headless=true":"")+" -Djava.ext.dirs=./lib -classpath ./classes jalview.bin.Jalview ";
68 System.out.println("###############Jalview CMD: " + _cmd+cmd);
69 Process ls2_proc = Runtime.getRuntime().exec(_cmd+cmd);
70 BufferedReader outputReader = new BufferedReader(new InputStreamReader(
71 ls2_proc.getInputStream()));
73 BufferedReader errorReader = new BufferedReader(new InputStreamReader(
74 ls2_proc.getErrorStream()));
75 Worker worker = new Worker(ls2_proc);
78 System.out.println("Output: ");
80 while ((ln = outputReader.readLine()) != null)
82 System.out.println(ln);
85 System.out.println("Error: ");
86 while ((ln = errorReader.readLine()) != null)
88 System.out.println(ln);
93 public void testHeadlessModeEPS() throws Exception
95 String[] headlessArgs=new String[] { "nodisplay","headless","nogui"};
96 for (String _harg:headlessArgs)
98 boolean _switch=false,withAwt=false;
105 String jalview_input = "examples/uniref50.fa";
106 String jalview_output = "test_uniref50_out.eps";
107 String cmd = ""+_harg+" -open "+ jalview_input + " -eps " + jalview_output;
108 String harg = _harg+(withAwt ? "-Djava.awt.headless=true":" NO AWT.HEADLESS");
109 System.out.println("Testing with Headless argument: '"+harg+"'\n");
110 Worker worker = jalviewDesktopRunner(withAwt, cmd, 9000);
111 assertTrue("Didn't create an output EPS file.["+harg+"]", new File("test_uniref50_out.eps").exists());
112 assertTrue("Didn't create an EPS file with any content["+harg+"]", new File("test_uniref50_out.eps").length()>4096);
113 if (worker.exit == null){
115 Thread.currentThread().interrupt();
116 worker.process.destroy();
117 fail("Jalview did not exit after EPS generation (try running test again to verify - timeout at 9000ms). ["+harg+"]");
123 // public void testJalview2XMLDataset() throws Exception
125 // String jalview_input = "examples/uniref50.fa";
126 // String jalview_output = "test_uniref50_out.eps";
127 // String cmd = ""+" -open "+ jalview_input + " -eps " + jalview_output;
128 // //String harg = _harg+(withAwt ? "-Djava.awt.headless=true":" NO AWT.HEADLESS");
129 // System.out.println("Testing with Headless argument: '"+harg+"'\n");
130 // Worker worker = jalviewDesktopRunner(withAwt, cmd, 9000);
131 // assertTrue("Didn't create an output EPS file.["+harg+"]", new File("test_uniref50_out.eps").exists());
132 // assertTrue("Didn't create an EPS file with any content["+harg+"]", new File("test_uniref50_out.eps").length()>4096);
133 // if (worker.exit == null){
134 // worker.interrupt();
135 // Thread.currentThread().interrupt();
136 // worker.process.destroy();
137 // fail("Jalview did not exit after EPS generation (try running test again to verify - timeout at 9000ms). ["+harg+"]");