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
37 private static final int TEST_TIMEOUT = 4500; // Note longer timeout needed on
38 // full test run than on
41 private static final int SETUP_TIMEOUT = 9000;
43 private static final int MINFILESIZE_SMALL = 2096;
45 private static final int MINFILESIZE_BIG = 4096;
47 private ArrayList<String> successfulCMDs = new ArrayList<String>();
51 * http://stackoverflow.com/questions/808276/how-to-add-a-timeout-value-when
52 * -using-javas-runtime-exec
57 private static class Worker extends Thread
59 private final Process process;
61 private BufferedReader outputReader;
63 private BufferedReader errorReader;
67 private Worker(Process process)
69 this.process = process;
77 exit = process.waitFor();
78 } catch (InterruptedException ignore)
84 public BufferedReader getOutputReader()
89 public void setOutputReader(BufferedReader outputReader)
91 this.outputReader = outputReader;
94 public BufferedReader getErrorReader()
99 public void setErrorReader(BufferedReader errorReader)
101 this.errorReader = errorReader;
105 private Worker jalviewDesktopRunner(boolean withAwt, String cmd,
108 String _cmd = "java "
109 + (withAwt ? "-Djava.awt.headless=true" : "")
110 + " -Djava.ext.dirs=./lib -classpath ./classes jalview.bin.Jalview ";
111 System.out.println("CMD [" + cmd + "]");
112 Process ls2_proc = null;
113 Worker worker = null;
116 ls2_proc = Runtime.getRuntime().exec(_cmd + cmd);
117 } catch (IOException e1)
119 e1.printStackTrace();
121 if (ls2_proc != null)
123 BufferedReader outputReader = new BufferedReader(
124 new InputStreamReader(ls2_proc.getInputStream()));
125 BufferedReader errorReader = new BufferedReader(
126 new InputStreamReader(ls2_proc.getErrorStream()));
127 worker = new Worker(ls2_proc);
131 worker.join(timeout);
132 } catch (InterruptedException e)
134 // e.printStackTrace();
136 worker.setOutputReader(outputReader);
137 worker.setErrorReader(errorReader);
142 @BeforeTest(alwaysRun = true)
143 public void initialize()
145 new CommandLineOperations();
148 @BeforeTest(alwaysRun = true)
149 public void setUpForHeadlessCommandLineInputOperations()
152 String cmds = "nodisplay -open examples/uniref50.fa -sortbytree -props FILE -colour zappo "
153 + "-jabaws http://www.compbio.dundee.ac.uk/jabaws -nosortbytree -dasserver nickname=www.test.com "
154 + "-features examples/testdata/plantfdx.features -annotations examples/testdata/plantfdx.annotations -tree examples/testdata/uniref50_test_tree";
155 Worker worker = jalviewDesktopRunner(true, cmds, SETUP_TIMEOUT);
157 while ((ln = worker.getOutputReader().readLine()) != null)
159 System.out.println(ln);
160 successfulCMDs.add(ln);
164 @BeforeTest(alwaysRun = true)
165 public void setUpForCommandLineInputOperations() throws IOException
167 String cmds = "-open examples/uniref50.fa -noquestionnaire -nousagestats";
168 Worker worker = jalviewDesktopRunner(false, cmds, SETUP_TIMEOUT);
171 while ((ln = worker.getErrorReader().readLine()) != null)
173 System.out.println(ln);
174 successfulCMDs.add(ln);
180 if (worker != null && worker.exit == null)
183 Thread.currentThread().interrupt();
184 worker.process.destroy();
188 @Test(groups = { "Functional" }, dataProvider = "allInputOpearationsData")
189 public void testAllInputOperations(String expectedString,
192 Assert.assertTrue(successfulCMDs.contains(expectedString), failureMsg);
196 groups = { "Functional" },
197 dataProvider = "headlessModeOutputOperationsData")
198 public void testHeadlessModeOutputOperations(String harg, String type,
199 String fileName, boolean withAWT, int expectedMinFileSize,
202 String cmd = harg + type + " " + fileName;
203 // System.out.println(">>>>>>>>>>>>>>>> Command : " + cmd);
204 File file = new File(fileName);
205 Worker worker = jalviewDesktopRunner(withAWT, cmd, timeout);
207 FileAssert.assertFile(file, "Didn't create an output" + type
208 + " file.[" + harg + "]");
209 FileAssert.assertMinLength(new File(fileName), expectedMinFileSize);
210 if (worker != null && worker.exit == null)
213 Thread.currentThread().interrupt();
214 worker.process.destroy();
215 Assert.fail("Jalview did not exit after "
217 + " generation (try running test again to verify - timeout at "
218 + SETUP_TIMEOUT + "ms). ["
221 new File(fileName).delete();
224 @DataProvider(name = "allInputOpearationsData")
225 public Object[][] getHeadlessModeInputParams()
227 return new Object[][] {
228 // headless mode input operations
229 { "CMD [-color zappo] executed successfully!",
230 "Failed command : -color zappo" },
231 { "CMD [-props FILE] executed successfully!",
232 "Failed command : -props File" },
233 { "CMD [-sortbytree] executed successfully!",
234 "Failed command : -sortbytree" },
236 "CMD [-jabaws http://www.compbio.dundee.ac.uk/jabaws] executed successfully!",
237 "Failed command : -jabaws http://www.compbio.dundee.ac.uk/jabaws" },
238 { "CMD [-open examples/uniref50.fa] executed successfully!",
239 "Failed command : -open examples/uniref50.fa" },
240 { "CMD [-nosortbytree] executed successfully!",
241 "Failed command : -nosortbytree" },
242 { "CMD [-dasserver nickname=www.test.com] executed successfully!",
243 "Failed command : -dasserver nickname=www.test.com" },
245 "CMD [-features examples/testdata/plantfdx.features] executed successfully!",
246 "Failed command : -features examples/testdata/plantfdx.features" },
248 "CMD [-annotations examples/testdata/plantfdx.annotations] executed successfully!",
249 "Failed command : -annotations examples/testdata/plantfdx.annotations" },
251 "CMD [-tree examples/testdata/uniref50_test_tree] executed successfully!",
252 "Failed command : -tree examples/testdata/uniref50_test_tree" },
253 // non headless mode input operations
254 { "CMD [-nousagestats] executed successfully!",
255 "Failed command : -nousagestats" },
256 { "CMD [-noquestionnaire] executed successfully!",
257 "Failed command : -noquestionnaire nickname=www.test.com" } };
261 @DataProvider(name = "headlessModeOutputOperationsData")
262 public static Object[][] getHeadlessModeOutputParams()
264 return new Object[][] {
265 { "nodisplay -open examples/uniref50.fa", " -eps",
266 "test_uniref50_out.eps", true, MINFILESIZE_BIG, TEST_TIMEOUT },
267 { "nodisplay -open examples/uniref50.fa", " -eps",
268 "test_uniref50_out.eps", false, MINFILESIZE_BIG, TEST_TIMEOUT },
269 { "nogui -open examples/uniref50.fa", " -eps",
270 "test_uniref50_out.eps", true, MINFILESIZE_BIG, TEST_TIMEOUT },
271 { "nogui -open examples/uniref50.fa", " -eps",
272 "test_uniref50_out.eps", false, MINFILESIZE_BIG, TEST_TIMEOUT },
273 { "headless -open examples/uniref50.fa", " -eps",
274 "test_uniref50_out.eps", true, MINFILESIZE_BIG, TEST_TIMEOUT },
275 { "headless -open examples/uniref50.fa", " -svg",
276 "test_uniref50_out.svg", false, MINFILESIZE_BIG, TEST_TIMEOUT },
277 { "headless -open examples/uniref50.fa", " -png",
278 "test_uniref50_out.png", true, MINFILESIZE_BIG, TEST_TIMEOUT },
279 { "headless -open examples/uniref50.fa", " -html",
280 "test_uniref50_out.html", true, MINFILESIZE_BIG, TEST_TIMEOUT },
281 { "headless -open examples/uniref50.fa", " -fasta",
282 "test_uniref50_out.mfa", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
283 { "headless -open examples/uniref50.fa", " -clustal",
284 "test_uniref50_out.aln", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
285 { "headless -open examples/uniref50.fa", " -msf",
286 "test_uniref50_out.msf", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
287 { "headless -open examples/uniref50.fa", " -pileup",
288 "test_uniref50_out.aln", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
289 { "headless -open examples/uniref50.fa", " -pir",
290 "test_uniref50_out.pir", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
291 { "headless -open examples/uniref50.fa", " -pfam",
292 "test_uniref50_out.pfam", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
293 { "headless -open examples/uniref50.fa", " -blc",
294 "test_uniref50_out.blc", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
295 { "headless -open examples/uniref50.fa", " -jalview",
296 "test_uniref50_out.jvp", true, MINFILESIZE_SMALL, TEST_TIMEOUT }, };