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;
27 import java.util.ArrayList;
29 import org.testng.Assert;
30 import org.testng.FileAssert;
31 import org.testng.annotations.BeforeTest;
32 import org.testng.annotations.DataProvider;
33 import org.testng.annotations.Test;
35 public class CommandLineOperations
38 private ArrayList<String> successfulCMDs = new ArrayList<String>();
42 * http://stackoverflow.com/questions/808276/how-to-add-a-timeout-value-when
43 * -using-javas-runtime-exec
48 private static class Worker extends Thread
50 private final Process process;
51 private BufferedReader outputReader;
52 private BufferedReader errorReader;
55 private Worker(Process process)
57 this.process = process;
64 exit = process.waitFor();
65 } catch (InterruptedException ignore)
71 public BufferedReader getOutputReader()
76 public void setOutputReader(BufferedReader outputReader)
78 this.outputReader = outputReader;
81 public BufferedReader getErrorReader()
86 public void setErrorReader(BufferedReader errorReader)
88 this.errorReader = errorReader;
92 private Worker jalviewDesktopRunner(boolean withAwt, String cmd,
96 + (withAwt ? "-Djava.awt.headless=true" : "")
97 + " -Djava.ext.dirs=./lib -classpath ./classes jalview.bin.Jalview ";
98 System.out.println("CMD [" + cmd + "]");
99 Process ls2_proc = null;
100 Worker worker = null;
103 ls2_proc = Runtime.getRuntime().exec(_cmd + cmd);
104 } catch (IOException e1)
106 e1.printStackTrace();
108 if (ls2_proc != null)
110 BufferedReader outputReader = new BufferedReader(
111 new InputStreamReader(ls2_proc.getInputStream()));
112 BufferedReader errorReader = new BufferedReader(
113 new InputStreamReader(ls2_proc.getErrorStream()));
114 worker = new Worker(ls2_proc);
118 worker.join(timeout);
119 } catch (InterruptedException e)
121 // e.printStackTrace();
123 worker.setOutputReader(outputReader);
124 worker.setErrorReader(errorReader);
129 @BeforeTest(alwaysRun = true)
130 public void initialize()
132 new CommandLineOperations();
135 @BeforeTest(alwaysRun = true)
136 public void setUpForHeadlessCommandLineInputOperations()
139 String cmds = "nodisplay -open examples/uniref50.fa -sortbytree -props FILE -colour zappo "
140 + "-jabaws http://www.compbio.dundee.ac.uk/jabaws -nosortbytree -dasserver nickname=www.test.com "
141 + "-features examples/testdata/plantfdx.features -annotations examples/testdata/plantfdx.annotations -tree examples/testdata/uniref50_test_tree";
142 Worker worker = jalviewDesktopRunner(true, cmds, 9000);
144 while ((ln = worker.getOutputReader().readLine()) != null)
146 System.out.println(ln);
147 successfulCMDs.add(ln);
151 @BeforeTest(alwaysRun = true)
152 public void setUpForCommandLineInputOperations() throws IOException
154 String cmds = "-open examples/uniref50.fa -noquestionnaire -nousagestats";
155 Worker worker = jalviewDesktopRunner(false, cmds, 9000);
158 while ((ln = worker.getErrorReader().readLine()) != null)
160 System.out.println(ln);
161 successfulCMDs.add(ln);
167 if (worker != null && worker.exit == null)
170 Thread.currentThread().interrupt();
171 worker.process.destroy();
176 { "Functional" }, dataProvider = "allInputOpearationsData")
177 public void testAllInputOperations(String expectedString,
180 Assert.assertTrue(successfulCMDs.contains(expectedString), failureMsg);
184 { "Functional" }, dataProvider = "headlessModeOutputOperationsData")
185 public void testHeadlessModeOutputOperations(String harg, String type,
186 String fileName, boolean withAWT, int expectedMinFileSize,
189 String cmd = harg + type + " " + fileName;
190 // System.out.println(">>>>>>>>>>>>>>>> Command : " + cmd);
191 File file = new File(fileName);
192 Worker worker = jalviewDesktopRunner(withAWT, cmd, timeout);
194 FileAssert.assertFile(file, "Didn't create an output" + type
195 + " file.[" + harg + "]");
196 FileAssert.assertMinLength(new File(fileName), expectedMinFileSize);
197 if (worker != null && worker.exit == null)
200 Thread.currentThread().interrupt();
201 worker.process.destroy();
202 Assert.fail("Jalview did not exit after "
204 + " generation (try running test again to verify - timeout at 9000ms). ["
207 new File(fileName).delete();
211 @DataProvider(name = "allInputOpearationsData")
212 public Object[][] getHeadlessModeInputParams()
214 return new Object[][]
216 // headless mode input operations
217 { "CMD [-color zappo] executed successfully!",
218 "Failed command : -color zappo" },
219 { "CMD [-props FILE] executed successfully!",
220 "Failed command : -props File" },
221 { "CMD [-sortbytree] executed successfully!",
222 "Failed command : -sortbytree" },
224 "CMD [-jabaws http://www.compbio.dundee.ac.uk/jabaws] executed successfully!",
225 "Failed command : -jabaws http://www.compbio.dundee.ac.uk/jabaws" },
226 { "CMD [-open examples/uniref50.fa] executed successfully!",
227 "Failed command : -open examples/uniref50.fa" },
228 { "CMD [-nosortbytree] executed successfully!",
229 "Failed command : -nosortbytree" },
230 { "CMD [-dasserver nickname=www.test.com] executed successfully!",
231 "Failed command : -dasserver nickname=www.test.com" },
233 "CMD [-features examples/testdata/plantfdx.features] executed successfully!",
234 "Failed command : -features examples/testdata/plantfdx.features" },
236 "CMD [-annotations examples/testdata/plantfdx.annotations] executed successfully!",
237 "Failed command : -annotations examples/testdata/plantfdx.annotations" },
239 "CMD [-tree examples/testdata/uniref50_test_tree] executed successfully!",
240 "Failed command : -tree examples/testdata/uniref50_test_tree" },
241 // non headless mode input operations
242 { "CMD [-nousagestats] executed successfully!",
243 "Failed command : -nousagestats" },
244 { "CMD [-noquestionnaire] executed successfully!",
245 "Failed command : -noquestionnaire nickname=www.test.com" }
250 @DataProvider(name = "headlessModeOutputOperationsData")
251 public static Object[][] getHeadlessModeOutputParams()
253 return new Object[][]
255 { "nodisplay -open examples/uniref50.fa", " -eps",
256 "test_uniref50_out.eps", true, 4096, 4000 },
257 { "nodisplay -open examples/uniref50.fa", " -eps",
258 "test_uniref50_out.eps", false, 4096, 4000 },
259 { "nogui -open examples/uniref50.fa", " -eps",
260 "test_uniref50_out.eps", true, 4096, 4000 },
261 { "nogui -open examples/uniref50.fa", " -eps",
262 "test_uniref50_out.eps", false, 4096, 4000 },
263 { "headless -open examples/uniref50.fa", " -eps",
264 "test_uniref50_out.eps", true, 4096, 4000 },
265 { "headless -open examples/uniref50.fa", " -svg",
266 "test_uniref50_out.svg", false, 4096, 3000 },
267 { "headless -open examples/uniref50.fa", " -png",
268 "test_uniref50_out.png", true, 4096, 3000 },
269 { "headless -open examples/uniref50.fa", " -html",
270 "test_uniref50_out.html", true, 4096, 3000 },
271 { "headless -open examples/uniref50.fa", " -fasta",
272 "test_uniref50_out.mfa", true, 2096, 3000 },
273 { "headless -open examples/uniref50.fa", " -clustal",
274 "test_uniref50_out.aln", true, 2096, 3000 },
275 { "headless -open examples/uniref50.fa", " -msf",
276 "test_uniref50_out.msf", true, 2096, 3000 },
277 { "headless -open examples/uniref50.fa", " -pileup",
278 "test_uniref50_out.aln", true, 2096, 3000 },
279 { "headless -open examples/uniref50.fa", " -pir",
280 "test_uniref50_out.pir", true, 2096, 3000 },
281 { "headless -open examples/uniref50.fa", " -pfam",
282 "test_uniref50_out.pfam", true, 2096, 3000 },
283 { "headless -open examples/uniref50.fa", " -blc",
284 "test_uniref50_out.blc", true, 2096, 3000 },
285 { "headless -open examples/uniref50.fa", " -jalview",
286 "test_uniref50_out.jvp", true, 2096, 3000 },