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;
52 private BufferedReader outputReader;
54 private BufferedReader errorReader;
58 private Worker(Process process)
60 this.process = process;
67 exit = process.waitFor();
68 } catch (InterruptedException ignore)
74 public BufferedReader getOutputReader()
79 public void setOutputReader(BufferedReader outputReader)
81 this.outputReader = outputReader;
84 public BufferedReader getErrorReader()
89 public void setErrorReader(BufferedReader errorReader)
91 this.errorReader = errorReader;
95 private Worker jalviewDesktopRunner(boolean withAwt, String cmd,
99 + (withAwt ? "-Djava.awt.headless=true" : "")
100 + " -Djava.ext.dirs=./lib -classpath ./classes jalview.bin.Jalview ";
101 System.out.println("CMD [" + cmd + "]");
102 Process ls2_proc = null;
103 Worker worker = null;
106 ls2_proc = Runtime.getRuntime().exec(_cmd + cmd);
107 } catch (IOException e1)
109 e1.printStackTrace();
111 if (ls2_proc != null)
113 BufferedReader outputReader = new BufferedReader(
114 new InputStreamReader(ls2_proc.getInputStream()));
115 BufferedReader errorReader = new BufferedReader(
116 new InputStreamReader(ls2_proc.getErrorStream()));
117 worker = new Worker(ls2_proc);
121 worker.join(timeout);
122 } catch (InterruptedException e)
124 // e.printStackTrace();
126 worker.setOutputReader(outputReader);
127 worker.setErrorReader(errorReader);
132 @BeforeTest(alwaysRun = true)
133 public void initialize()
135 new CommandLineOperations();
138 @BeforeTest(alwaysRun = true)
139 public void setUpForHeadlessCommandLineInputOperations()
142 String cmds = "nodisplay -open examples/uniref50.fa -sortbytree -props FILE -colour zappo "
143 + "-jabaws http://www.compbio.dundee.ac.uk/jabaws -nosortbytree -dasserver nickname=www.test.com "
144 + "-features examples/testdata/plantfdx.features -annotations examples/testdata/plantfdx.annotations -tree examples/testdata/uniref50_test_tree";
145 Worker worker = jalviewDesktopRunner(true, cmds, 9000);
147 while ((ln = worker.getOutputReader().readLine()) != null)
149 System.out.println(ln);
150 successfulCMDs.add(ln);
154 @BeforeTest(alwaysRun = true)
155 public void setUpForCommandLineInputOperations() throws IOException
157 String cmds = "-open examples/uniref50.fa -noquestionnaire -nousagestats";
158 Worker worker = jalviewDesktopRunner(false, cmds, 9000);
161 while ((ln = worker.getErrorReader().readLine()) != null)
163 System.out.println(ln);
164 successfulCMDs.add(ln);
170 if (worker != null && worker.exit == null)
173 Thread.currentThread().interrupt();
174 worker.process.destroy();
178 @Test(groups = { "Functional" }, dataProvider = "allInputOpearationsData")
179 public void testAllInputOperations(String expectedString,
182 Assert.assertTrue(successfulCMDs.contains(expectedString), failureMsg);
186 groups = { "Functional" },
187 dataProvider = "headlessModeOutputOperationsData")
188 public void testHeadlessModeOutputOperations(String harg, String type,
189 String fileName, boolean withAWT, int expectedMinFileSize,
192 String cmd = harg + type + " " + fileName;
193 // System.out.println(">>>>>>>>>>>>>>>> Command : " + cmd);
194 File file = new File(fileName);
195 Worker worker = jalviewDesktopRunner(withAWT, cmd, timeout);
197 FileAssert.assertFile(file, "Didn't create an output" + type
198 + " file.[" + harg + "]");
199 FileAssert.assertMinLength(new File(fileName), expectedMinFileSize);
200 if (worker != null && worker.exit == null)
203 Thread.currentThread().interrupt();
204 worker.process.destroy();
205 Assert.fail("Jalview did not exit after "
207 + " generation (try running test again to verify - timeout at 9000ms). ["
210 new File(fileName).delete();
213 @DataProvider(name = "allInputOpearationsData")
214 public Object[][] getHeadlessModeInputParams()
216 return new Object[][] {
217 // headless mode input operations
218 { "CMD [-color zappo] executed successfully!",
219 "Failed command : -color zappo" },
220 { "CMD [-props FILE] executed successfully!",
221 "Failed command : -props File" },
222 { "CMD [-sortbytree] executed successfully!",
223 "Failed command : -sortbytree" },
225 "CMD [-jabaws http://www.compbio.dundee.ac.uk/jabaws] executed successfully!",
226 "Failed command : -jabaws http://www.compbio.dundee.ac.uk/jabaws" },
227 { "CMD [-open examples/uniref50.fa] executed successfully!",
228 "Failed command : -open examples/uniref50.fa" },
229 { "CMD [-nosortbytree] executed successfully!",
230 "Failed command : -nosortbytree" },
231 { "CMD [-dasserver nickname=www.test.com] executed successfully!",
232 "Failed command : -dasserver nickname=www.test.com" },
234 "CMD [-features examples/testdata/plantfdx.features] executed successfully!",
235 "Failed command : -features examples/testdata/plantfdx.features" },
237 "CMD [-annotations examples/testdata/plantfdx.annotations] executed successfully!",
238 "Failed command : -annotations examples/testdata/plantfdx.annotations" },
240 "CMD [-tree examples/testdata/uniref50_test_tree] executed successfully!",
241 "Failed command : -tree examples/testdata/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" } };
250 @DataProvider(name = "headlessModeOutputOperationsData")
251 public static Object[][] getHeadlessModeOutputParams()
253 return new Object[][] {
254 { "nodisplay -open examples/uniref50.fa", " -eps",
255 "test_uniref50_out.eps", true, 4096, 4000 },
256 { "nodisplay -open examples/uniref50.fa", " -eps",
257 "test_uniref50_out.eps", false, 4096, 4000 },
258 { "nogui -open examples/uniref50.fa", " -eps",
259 "test_uniref50_out.eps", true, 4096, 4000 },
260 { "nogui -open examples/uniref50.fa", " -eps",
261 "test_uniref50_out.eps", false, 4096, 4000 },
262 { "headless -open examples/uniref50.fa", " -eps",
263 "test_uniref50_out.eps", true, 4096, 4000 },
264 { "headless -open examples/uniref50.fa", " -svg",
265 "test_uniref50_out.svg", false, 4096, 3000 },
266 { "headless -open examples/uniref50.fa", " -png",
267 "test_uniref50_out.png", true, 4096, 3000 },
268 { "headless -open examples/uniref50.fa", " -html",
269 "test_uniref50_out.html", true, 4096, 3000 },
270 { "headless -open examples/uniref50.fa", " -fasta",
271 "test_uniref50_out.mfa", true, 2096, 3000 },
272 { "headless -open examples/uniref50.fa", " -clustal",
273 "test_uniref50_out.aln", true, 2096, 3000 },
274 { "headless -open examples/uniref50.fa", " -msf",
275 "test_uniref50_out.msf", true, 2096, 3000 },
276 { "headless -open examples/uniref50.fa", " -pileup",
277 "test_uniref50_out.aln", true, 2096, 3000 },
278 { "headless -open examples/uniref50.fa", " -pir",
279 "test_uniref50_out.pir", true, 2096, 3000 },
280 { "headless -open examples/uniref50.fa", " -pfam",
281 "test_uniref50_out.pfam", true, 2096, 3000 },
282 { "headless -open examples/uniref50.fa", " -blc",
283 "test_uniref50_out.blc", true, 2096, 3000 },
284 { "headless -open examples/uniref50.fa", " -jalview",
285 "test_uniref50_out.jvp", true, 2096, 3000 }, };