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 jalview.gui.JvOptionPane;
25 import java.io.BufferedReader;
27 import java.io.IOException;
28 import java.io.InputStreamReader;
29 import java.util.ArrayList;
31 import org.testng.Assert;
32 import org.testng.FileAssert;
33 import org.testng.annotations.BeforeClass;
34 import org.testng.annotations.BeforeTest;
35 import org.testng.annotations.DataProvider;
36 import org.testng.annotations.Test;
38 public class CommandLineOperations
41 @BeforeClass(alwaysRun = true)
42 public void setUpJvOptionPane()
44 JvOptionPane.setInteractiveMode(false);
45 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
48 private static final int TEST_TIMEOUT = 4500; // Note longer timeout needed on
49 // full test run than on
52 private static final int SETUP_TIMEOUT = 9000;
54 private static final int MINFILESIZE_SMALL = 2096;
56 private static final int MINFILESIZE_BIG = 4096;
58 private ArrayList<String> successfulCMDs = new ArrayList<>();
62 * http://stackoverflow.com/questions/808276/how-to-add-a-timeout-value-when
63 * -using-javas-runtime-exec
68 private static class Worker extends Thread
70 private final Process process;
72 private BufferedReader outputReader;
74 private BufferedReader errorReader;
78 private Worker(Process process)
80 this.process = process;
88 exit = process.waitFor();
89 } catch (InterruptedException ignore)
95 public BufferedReader getOutputReader()
100 public void setOutputReader(BufferedReader outputReader)
102 this.outputReader = outputReader;
105 public BufferedReader getErrorReader()
110 public void setErrorReader(BufferedReader errorReader)
112 this.errorReader = errorReader;
116 private Worker jalviewDesktopRunner(boolean withAwt, String cmd,
120 if (System.getProperty("os.name").indexOf("Windows") >= 0)
124 String _cmd = "java "
125 + (withAwt ? "-Djava.awt.headless=true" : "")
126 + " -classpath \"./lib/*" + cp_sep
127 + "./classes\" jalview.bin.Jalview ";
128 System.out.println("CMD [" + cmd + "]");
129 Process ls2_proc = null;
130 Worker worker = null;
133 ls2_proc = Runtime.getRuntime().exec(_cmd + cmd);
134 } catch (IOException e1)
136 e1.printStackTrace();
138 if (ls2_proc != null)
140 BufferedReader outputReader = new BufferedReader(
141 new InputStreamReader(ls2_proc.getInputStream()));
142 BufferedReader errorReader = new BufferedReader(
143 new InputStreamReader(ls2_proc.getErrorStream()));
144 worker = new Worker(ls2_proc);
148 worker.join(timeout);
149 } catch (InterruptedException e)
151 // e.printStackTrace();
153 worker.setOutputReader(outputReader);
154 worker.setErrorReader(errorReader);
159 @BeforeTest(alwaysRun = true)
160 public void initialize()
162 new CommandLineOperations();
165 @BeforeTest(alwaysRun = true)
166 public void setUpForHeadlessCommandLineInputOperations()
169 String cmds = "nodisplay -open examples/uniref50.fa -sortbytree -props FILE -colour zappo "
170 + "-jabaws http://www.compbio.dundee.ac.uk/jabaws -nosortbytree -dasserver nickname=www.test.com "
171 + "-features examples/testdata/plantfdx.features -annotations examples/testdata/plantfdx.annotations -tree examples/testdata/uniref50_test_tree";
172 Worker worker = jalviewDesktopRunner(true, cmds, SETUP_TIMEOUT);
174 while ((ln = worker.getOutputReader().readLine()) != null)
176 System.out.println(ln);
177 successfulCMDs.add(ln);
181 @BeforeTest(alwaysRun = true)
182 public void setUpForCommandLineInputOperations() throws IOException
184 String cmds = "-open examples/uniref50.fa -noquestionnaire -nousagestats";
185 Worker worker = jalviewDesktopRunner(false, cmds, SETUP_TIMEOUT);
188 while ((ln = worker.getErrorReader().readLine()) != null)
190 System.out.println(ln);
191 successfulCMDs.add(ln);
197 if (worker != null && worker.exit == null)
200 Thread.currentThread().interrupt();
201 worker.process.destroy();
205 @Test(groups = { "Functional" }, dataProvider = "allInputOpearationsData")
206 public void testAllInputOperations(String expectedString,
209 Assert.assertTrue(successfulCMDs.contains(expectedString), failureMsg);
213 groups = { "Functional" },
214 dataProvider = "headlessModeOutputOperationsData")
215 public void testHeadlessModeOutputOperations(String harg, String type,
216 String fileName, boolean withAWT, int expectedMinFileSize,
219 String cmd = harg + type + " " + fileName;
220 // System.out.println(">>>>>>>>>>>>>>>> Command : " + cmd);
221 File file = new File(fileName);
222 Worker worker = jalviewDesktopRunner(withAWT, cmd, timeout);
224 FileAssert.assertFile(file, "Didn't create an output" + type
225 + " file.[" + harg + "]");
226 FileAssert.assertMinLength(new File(fileName), expectedMinFileSize);
227 if (worker != null && worker.exit == null)
230 Thread.currentThread().interrupt();
231 worker.process.destroy();
232 Assert.fail("Jalview did not exit after "
234 + " generation (try running test again to verify - timeout at "
235 + SETUP_TIMEOUT + "ms). ["
238 new File(fileName).delete();
241 @DataProvider(name = "allInputOpearationsData")
242 public Object[][] getHeadlessModeInputParams()
244 return new Object[][] {
245 // headless mode input operations
246 { "CMD [-color zappo] executed successfully!",
247 "Failed command : -color zappo" },
248 { "CMD [-props FILE] executed successfully!",
249 "Failed command : -props File" },
250 { "CMD [-sortbytree] executed successfully!",
251 "Failed command : -sortbytree" },
253 "CMD [-jabaws http://www.compbio.dundee.ac.uk/jabaws] executed successfully!",
254 "Failed command : -jabaws http://www.compbio.dundee.ac.uk/jabaws" },
255 { "CMD [-open examples/uniref50.fa] executed successfully!",
256 "Failed command : -open examples/uniref50.fa" },
257 { "CMD [-nosortbytree] executed successfully!",
258 "Failed command : -nosortbytree" },
259 { "CMD [-dasserver nickname=www.test.com] executed successfully!",
260 "Failed command : -dasserver nickname=www.test.com" },
262 "CMD [-features examples/testdata/plantfdx.features] executed successfully!",
263 "Failed command : -features examples/testdata/plantfdx.features" },
265 "CMD [-annotations examples/testdata/plantfdx.annotations] executed successfully!",
266 "Failed command : -annotations examples/testdata/plantfdx.annotations" },
268 "CMD [-tree examples/testdata/uniref50_test_tree] executed successfully!",
269 "Failed command : -tree examples/testdata/uniref50_test_tree" },
270 // non headless mode input operations
271 { "CMD [-nousagestats] executed successfully!",
272 "Failed command : -nousagestats" },
273 { "CMD [-noquestionnaire] executed successfully!",
274 "Failed command : -noquestionnaire nickname=www.test.com" } };
278 @DataProvider(name = "headlessModeOutputOperationsData")
279 public static Object[][] getHeadlessModeOutputParams()
281 return new Object[][] {
282 { "nodisplay -open examples/uniref50.fa", " -eps",
283 "test_uniref50_out.eps", true, MINFILESIZE_BIG, TEST_TIMEOUT },
284 { "nodisplay -open examples/uniref50.fa", " -eps",
285 "test_uniref50_out.eps", false, MINFILESIZE_BIG, TEST_TIMEOUT },
286 { "nogui -open examples/uniref50.fa", " -eps",
287 "test_uniref50_out.eps", true, MINFILESIZE_BIG, TEST_TIMEOUT },
288 { "nogui -open examples/uniref50.fa", " -eps",
289 "test_uniref50_out.eps", false, MINFILESIZE_BIG, TEST_TIMEOUT },
290 { "headless -open examples/uniref50.fa", " -eps",
291 "test_uniref50_out.eps", true, MINFILESIZE_BIG, TEST_TIMEOUT },
292 { "headless -open examples/uniref50.fa", " -svg",
293 "test_uniref50_out.svg", false, MINFILESIZE_BIG, TEST_TIMEOUT },
294 { "headless -open examples/uniref50.fa", " -png",
295 "test_uniref50_out.png", true, MINFILESIZE_BIG, TEST_TIMEOUT },
296 { "headless -open examples/uniref50.fa", " -html",
297 "test_uniref50_out.html", true, MINFILESIZE_BIG, TEST_TIMEOUT },
298 { "headless -open examples/uniref50.fa", " -fasta",
299 "test_uniref50_out.mfa", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
300 { "headless -open examples/uniref50.fa", " -clustal",
301 "test_uniref50_out.aln", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
302 { "headless -open examples/uniref50.fa", " -msf",
303 "test_uniref50_out.msf", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
304 { "headless -open examples/uniref50.fa", " -pileup",
305 "test_uniref50_out.aln", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
306 { "headless -open examples/uniref50.fa", " -pir",
307 "test_uniref50_out.pir", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
308 { "headless -open examples/uniref50.fa", " -pfam",
309 "test_uniref50_out.pfam", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
310 { "headless -open examples/uniref50.fa", " -blc",
311 "test_uniref50_out.blc", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
312 { "headless -open examples/uniref50.fa", " -jalview",
313 "test_uniref50_out.jvp", true, MINFILESIZE_SMALL, TEST_TIMEOUT }, };