2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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 java.io.BufferedReader;
25 import java.io.IOException;
26 import java.io.InputStreamReader;
28 import org.testng.Assert;
29 import org.testng.AssertJUnit;
30 import org.testng.annotations.AfterClass;
31 import org.testng.annotations.BeforeClass;
32 import org.testng.annotations.Test;
34 public class CommandLineOperations
38 public static void setUpBeforeClass() throws Exception
43 public static void tearDownAfterClass() throws Exception
49 * http://stackoverflow.com/questions/808276/how-to-add-a-timeout-value-when
50 * -using-javas-runtime-exec
55 private static class Worker extends Thread
57 private final Process process;
61 private Worker(Process process)
63 this.process = process;
70 exit = process.waitFor();
71 } catch (InterruptedException ignore)
78 private Worker jalviewDesktopRunner(boolean withAwt, String cmd,
79 int timeout) throws InterruptedException, IOException
82 + (withAwt ? "-Djava.awt.headless=true" : "")
83 + " -Djava.ext.dirs=./lib -classpath ./classes jalview.bin.Jalview ";
84 System.out.println("###############Jalview CMD: " + _cmd + cmd);
85 Process ls2_proc = Runtime.getRuntime().exec(_cmd + cmd);
86 BufferedReader outputReader = new BufferedReader(new InputStreamReader(
87 ls2_proc.getInputStream()));
89 BufferedReader errorReader = new BufferedReader(new InputStreamReader(
90 ls2_proc.getErrorStream()));
91 Worker worker = new Worker(ls2_proc);
94 System.out.println("Output: ");
96 while ((ln = outputReader.readLine()) != null)
98 System.out.println(ln);
101 System.out.println("Error: ");
102 while ((ln = errorReader.readLine()) != null)
104 System.out.println(ln);
110 public void testHeadlessModeEPS() throws Exception
112 String[] headlessArgs = new String[]
113 { "nodisplay", "headless", "nogui" };
114 for (String _harg : headlessArgs)
116 boolean _switch = false, withAwt = false;
124 String jalview_input = "examples/uniref50.fa";
125 String jalview_output = "test_uniref50_out.eps";
126 String cmd = "" + _harg + " -open " + jalview_input + " -eps "
129 + (withAwt ? "-Djava.awt.headless=true"
130 : " NO AWT.HEADLESS");
131 System.out.println("Testing with Headless argument: '" + harg
133 Worker worker = jalviewDesktopRunner(withAwt, cmd, 9000);
134 AssertJUnit.assertTrue("Didn't create an output EPS file.[" + harg
135 + "]", new File("test_uniref50_out.eps").exists());
136 AssertJUnit.assertTrue(
137 "Didn't create an EPS file with any content[" + harg + "]",
138 new File("test_uniref50_out.eps").length() > 4096);
139 if (worker.exit == null)
142 Thread.currentThread().interrupt();
143 worker.process.destroy();
144 Assert.fail("Jalview did not exit after EPS generation (try running test again to verify - timeout at 9000ms). ["
151 // public void testJalview2XMLDataset() throws Exception
153 // String jalview_input = "examples/uniref50.fa";
154 // String jalview_output = "test_uniref50_out.eps";
155 // String cmd = ""+" -open "+ jalview_input + " -eps " + jalview_output;
156 // //String harg = _harg+(withAwt ?
157 // "-Djava.awt.headless=true":" NO AWT.HEADLESS");
158 // System.out.println("Testing with Headless argument: '"+harg+"'\n");
159 // Worker worker = jalviewDesktopRunner(withAwt, cmd, 9000);
160 // assertTrue("Didn't create an output EPS file.["+harg+"]", new
161 // File("test_uniref50_out.eps").exists());
162 // assertTrue("Didn't create an EPS file with any content["+harg+"]", new
163 // File("test_uniref50_out.eps").length()>4096);
164 // if (worker.exit == null){
165 // worker.interrupt();
166 // Thread.currentThread().interrupt();
167 // worker.process.destroy();
168 // fail("Jalview did not exit after EPS generation (try running test again to verify - timeout at 9000ms). ["+harg+"]");