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()));
113 BufferedReader errorReader = new BufferedReader(
114 new InputStreamReader(ls2_proc.getErrorStream()));
115 worker = new Worker(ls2_proc);
119 worker.join(timeout);
120 } catch (InterruptedException e)
122 // e.printStackTrace();
124 worker.setOutputReader(outputReader);
125 worker.setErrorReader(errorReader);
131 public void initialize()
133 new CommandLineOperations();
138 public void setUpForHeadlessCommandLineInputOperations()
141 String cmds = "nodisplay -open examples/uniref50.fa -sortbytree -props FILE -colour zappo "
142 + "-jabaws http://www.compbio.dundee.ac.uk/jabaws -nosortbytree -dasserver nickname=www.test.com "
143 + "-features examples/uniref50_test_features -annotations examples/uniref50_test_annot -tree examples/uniref50_test_tree";
144 Worker worker = jalviewDesktopRunner(true, cmds, 9000);
146 while ((ln = worker.getOutputReader().readLine()) != null)
148 System.out.println(ln);
149 successfulCMDs.add(ln);
154 public void setUpForCommandLineInputOperations() throws IOException
156 String cmds = "-open examples/uniref50.fa -noquestionnaire -nousagestats";
157 Worker worker = jalviewDesktopRunner(false, cmds, 9000);
160 while ((ln = worker.getErrorReader().readLine()) != null)
162 System.out.println(ln);
163 successfulCMDs.add(ln);
169 if (worker != null && worker.exit == null)
172 Thread.currentThread().interrupt();
173 worker.process.destroy();
178 { "Functional" }, dataProvider = "allInputOpearationsData")
179 public void testAllInputOperations(String expectedString,
182 Assert.assertTrue(successfulCMDs.contains(expectedString), failureMsg);
186 { "Functional" }, dataProvider = "headlessModeOutputOperationsData")
187 public void testHeadlessModeOutputOperations(String harg, String type,
188 String fileName, boolean withAWT, int expectedMinFileSize,
191 String cmd = harg + type + " " + fileName;
192 // System.out.println(">>>>>>>>>>>>>>>> Command : " + cmd);
193 File file = new File(fileName);
194 Worker worker = jalviewDesktopRunner(withAWT, cmd, timeout);
196 FileAssert.assertFile(file, "Didn't create an output" + type
197 + " file.[" + harg + "]");
198 FileAssert.assertMinLength(new File(fileName), expectedMinFileSize);
199 if (worker != null && worker.exit == null)
202 Thread.currentThread().interrupt();
203 worker.process.destroy();
204 Assert.fail("Jalview did not exit after "
206 + " generation (try running test again to verify - timeout at 9000ms). ["
209 new File(fileName).delete();
213 @DataProvider(name = "allInputOpearationsData")
214 public Object[][] getHeadlessModeInputParams()
216 return new Object[][]
218 // headless mode input operations
219 { "CMD [-color zappo] executed successfully!",
220 "Failed command : -color zappo" },
221 { "CMD [-props FILE] executed successfully!",
222 "Failed command : -props File" },
223 { "CMD [-sortbytree] executed successfully!",
224 "Failed command : -sortbytree" },
226 "CMD [-jabaws http://www.compbio.dundee.ac.uk/jabaws] executed successfully!",
227 "Failed command : -jabaws http://www.compbio.dundee.ac.uk/jabaws" },
228 { "CMD [-open examples/uniref50.fa] executed successfully!",
229 "Failed command : -open examples/uniref50.fa" },
230 { "CMD [-nosortbytree] executed successfully!",
231 "Failed command : -nosortbytree" },
232 { "CMD [-dasserver nickname=www.test.com] executed successfully!",
233 "Failed command : -dasserver nickname=www.test.com" },
235 "CMD [-features examples/uniref50_test_features] executed successfully!",
236 "Failed command : -features examples/uniref50_test_features" },
238 "CMD [-annotations examples/uniref50_test_annot] executed successfully!",
239 "Failed command : -annotations examples/uniref50_test_annot" },
240 { "CMD [-tree examples/uniref50_test_tree] executed successfully!",
241 "Failed command : -tree examples/uniref50_test_tree" },
242 // non headless mode input operations
243 { "CMD [-nousagestats] executed successfully!",
244 "Failed command : -nousagestats" },
245 { "CMD [-noquestionnaire] executed successfully!",
246 "Failed command : -noquestionnaire nickname=www.test.com" }
251 @DataProvider(name = "headlessModeOutputOperationsData")
252 public static Object[][] getHeadlessModeOutputParams()
254 return new Object[][]
256 { "nodisplay -open examples/uniref50.fa", " -eps",
257 "test_uniref50_out.eps", true, 4096, 4000 },
258 { "nodisplay -open examples/uniref50.fa", " -eps",
259 "test_uniref50_out.eps", false, 4096, 4000 },
260 { "nogui -open examples/uniref50.fa", " -eps",
261 "test_uniref50_out.eps", true, 4096, 4000 },
262 { "nogui -open examples/uniref50.fa", " -eps",
263 "test_uniref50_out.eps", false, 4096, 4000 },
264 { "headless -open examples/uniref50.fa", " -eps",
265 "test_uniref50_out.eps", true, 4096, 4000 },
266 { "headless -open examples/uniref50.fa", " -svg",
267 "test_uniref50_out.svg", false, 4096, 3000 },
268 { "headless -open examples/uniref50.fa", " -png",
269 "test_uniref50_out.png", true, 4096, 3000 },
270 { "headless -open examples/uniref50.fa", " -html",
271 "test_uniref50_out.html", true, 4096, 3000 },
272 { "headless -open examples/uniref50.fa", " -fasta",
273 "test_uniref50_out.mfa", true, 2096, 3000 },
274 { "headless -open examples/uniref50.fa", " -clustal",
275 "test_uniref50_out.aln", true, 2096, 3000 },
276 { "headless -open examples/uniref50.fa", " -msf",
277 "test_uniref50_out.msf", true, 2096, 3000 },
278 { "headless -open examples/uniref50.fa", " -pileup",
279 "test_uniref50_out.aln", true, 2096, 3000 },
280 { "headless -open examples/uniref50.fa", " -pir",
281 "test_uniref50_out.pir", true, 2096, 3000 },
282 { "headless -open examples/uniref50.fa", " -pfam",
283 "test_uniref50_out.pfam", true, 2096, 3000 },
284 { "headless -open examples/uniref50.fa", " -blc",
285 "test_uniref50_out.blc", true, 2096, 3000 },
286 { "headless -open examples/uniref50.fa", " -jalview",
287 "test_uniref50_out.jvp", true, 2096, 3000 },