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;
24 import jalview.ws.utils.Worker;
26 import java.io.BufferedReader;
28 import java.io.IOException;
29 import java.io.InputStreamReader;
30 import java.util.ArrayList;
32 import org.testng.Assert;
33 import org.testng.FileAssert;
34 import org.testng.annotations.BeforeClass;
35 import org.testng.annotations.BeforeTest;
36 import org.testng.annotations.DataProvider;
37 import org.testng.annotations.Test;
39 import io.github.classgraph.ClassGraph;
40 import io.github.classgraph.ScanResult;
42 public class CommandLineOperations
45 @BeforeClass(alwaysRun = true)
46 public void setUpJvOptionPane()
48 JvOptionPane.setInteractiveMode(false);
49 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
52 private static final int TEST_TIMEOUT = 9000; // Note longer timeout needed on
53 // full test run than on
56 private static final int SETUP_TIMEOUT = 9000;
58 private static final int MINFILESIZE_SMALL = 2096;
60 private static final int MINFILESIZE_BIG = 4096;
62 private ArrayList<String> successfulCMDs = new ArrayList<>();
65 private static ClassGraph scanner = null;
67 private static String classpath = null;
69 public synchronized static String getClassPath()
73 scanner = new ClassGraph();
74 ScanResult scan = scanner.scan();
75 classpath = scan.getClasspath();
77 while (classpath == null)
82 } catch (InterruptedException x)
89 private Worker jalviewDesktopRunner(boolean withAwt, String cmd,
92 // Note: JAL-3065 - don't include quotes for lib/* because the arguments are
93 // not expanded by the shell
94 String classpath = getClassPath();
96 + (withAwt ? "-Djava.awt.headless=true" : "")
97 + " -classpath " + classpath + " jalview.bin.Jalview ";
98 Process ls2_proc = null;
102 ls2_proc = Runtime.getRuntime().exec(_cmd + cmd);
103 } catch (IOException e1)
105 e1.printStackTrace();
107 if (ls2_proc != null)
109 BufferedReader outputReader = new BufferedReader(
110 new InputStreamReader(ls2_proc.getInputStream()));
111 BufferedReader errorReader = new BufferedReader(
112 new InputStreamReader(ls2_proc.getErrorStream()));
113 worker = new Worker(ls2_proc);
117 worker.join(timeout);
118 } catch (InterruptedException e)
120 // e.printStackTrace();
122 worker.setOutputReader(outputReader);
123 worker.setErrorReader(errorReader);
128 @BeforeTest(alwaysRun = true)
129 public void initialize()
131 new CommandLineOperations();
134 @BeforeTest(alwaysRun = true)
135 public void setUpForHeadlessCommandLineInputOperations()
138 String cmds = "nodisplay -open examples/uniref50.fa -sortbytree -props FILE -colour zappo "
139 + "-jabaws http://www.compbio.dundee.ac.uk/jabaws -nosortbytree -dasserver nickname=www.test.com "
140 + "-features examples/testdata/plantfdx.features -annotations examples/testdata/plantfdx.annotations -tree examples/testdata/uniref50_test_tree";
141 Worker worker = jalviewDesktopRunner(true, cmds, SETUP_TIMEOUT);
143 while ((ln = worker.getOutputReader().readLine()) != null)
145 System.out.println(ln);
146 successfulCMDs.add(ln);
150 @BeforeTest(alwaysRun = true)
151 public void setUpForCommandLineInputOperations() throws IOException
153 String cmds = "-open examples/uniref50.fa -noquestionnaire -nousagestats";
154 Worker worker = jalviewDesktopRunner(false, cmds, SETUP_TIMEOUT);
157 while ((ln = worker.getErrorReader().readLine()) != null)
159 System.out.println(ln);
160 successfulCMDs.add(ln);
166 if (worker != null && worker.getExitValue() == null)
168 worker.destroyProcess();
173 @Test(groups = { "Functional" }, dataProvider = "allInputOpearationsData")
174 public void testAllInputOperations(String expectedString,
177 Assert.assertTrue(successfulCMDs.contains(expectedString), failureMsg);
181 groups = { "Functional" },
182 dataProvider = "headlessModeOutputOperationsData")
183 public void testHeadlessModeOutputOperations(String harg, String type,
184 String fileName, boolean withAWT, int expectedMinFileSize,
187 String cmd = harg + type + " " + fileName;
188 // System.out.println(">>>>>>>>>>>>>>>> Command : " + cmd);
189 File file = new File(fileName);
190 Worker worker = jalviewDesktopRunner(withAWT, cmd, timeout);
192 FileAssert.assertFile(file, "Didn't create an output" + type
193 + " file.[" + harg + "]");
194 FileAssert.assertMinLength(new File(fileName), expectedMinFileSize);
195 if (worker != null && worker.getExitValue() == null)
197 worker.destroyProcess();
198 Assert.fail("Jalview did not exit after "
200 + " generation (try running test again to verify - timeout at "
201 + SETUP_TIMEOUT + "ms). ["
204 new File(fileName).delete();
207 @DataProvider(name = "allInputOpearationsData")
208 public Object[][] getHeadlessModeInputParams()
210 return new Object[][] {
211 // headless mode input operations
212 { "CMD [-color zappo] executed successfully!",
213 "Failed command : -color zappo" },
214 { "CMD [-props FILE] executed successfully!",
215 "Failed command : -props File" },
216 { "CMD [-sortbytree] executed successfully!",
217 "Failed command : -sortbytree" },
219 "CMD [-jabaws http://www.compbio.dundee.ac.uk/jabaws] executed successfully!",
220 "Failed command : -jabaws http://www.compbio.dundee.ac.uk/jabaws" },
221 { "CMD [-open examples/uniref50.fa] executed successfully!",
222 "Failed command : -open examples/uniref50.fa" },
223 { "CMD [-nosortbytree] executed successfully!",
224 "Failed command : -nosortbytree" },
225 { "CMD [-dasserver nickname=www.test.com] executed successfully!",
226 "Failed command : -dasserver nickname=www.test.com" },
228 "CMD [-features examples/testdata/plantfdx.features] executed successfully!",
229 "Failed command : -features examples/testdata/plantfdx.features" },
231 "CMD [-annotations examples/testdata/plantfdx.annotations] executed successfully!",
232 "Failed command : -annotations examples/testdata/plantfdx.annotations" },
234 "CMD [-tree examples/testdata/uniref50_test_tree] executed successfully!",
235 "Failed command : -tree examples/testdata/uniref50_test_tree" },
236 // non headless mode input operations
237 { "CMD [-nousagestats] executed successfully!",
238 "Failed command : -nousagestats" },
239 { "CMD [-noquestionnaire] executed successfully!",
240 "Failed command : -noquestionnaire nickname=www.test.com" } };
244 @DataProvider(name = "headlessModeOutputOperationsData")
245 public static Object[][] getHeadlessModeOutputParams()
247 return new Object[][] {
248 { "nodisplay -open examples/uniref50.fa", " -eps",
249 "test_uniref50_out.eps", true, MINFILESIZE_BIG, TEST_TIMEOUT },
250 { "nodisplay -open examples/uniref50.fa", " -eps",
251 "test_uniref50_out.eps", false, MINFILESIZE_BIG, TEST_TIMEOUT },
252 { "nogui -open examples/uniref50.fa", " -eps",
253 "test_uniref50_out.eps", true, MINFILESIZE_BIG, TEST_TIMEOUT },
254 { "nogui -open examples/uniref50.fa", " -eps",
255 "test_uniref50_out.eps", false, MINFILESIZE_BIG, TEST_TIMEOUT },
256 { "headless -open examples/uniref50.fa", " -eps",
257 "test_uniref50_out.eps", true, MINFILESIZE_BIG, TEST_TIMEOUT },
258 { "headless -open examples/uniref50.fa", " -svg",
259 "test_uniref50_out.svg", false, MINFILESIZE_BIG, TEST_TIMEOUT },
260 { "headless -open examples/uniref50.fa", " -png",
261 "test_uniref50_out.png", true, MINFILESIZE_BIG, TEST_TIMEOUT },
262 { "headless -open examples/uniref50.fa", " -html",
263 "test_uniref50_out.html", true, MINFILESIZE_BIG, TEST_TIMEOUT },
264 { "headless -open examples/uniref50.fa", " -fasta",
265 "test_uniref50_out.mfa", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
266 { "headless -open examples/uniref50.fa", " -clustal",
267 "test_uniref50_out.aln", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
268 { "headless -open examples/uniref50.fa", " -msf",
269 "test_uniref50_out.msf", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
270 { "headless -open examples/uniref50.fa", " -pileup",
271 "test_uniref50_out.aln", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
272 { "headless -open examples/uniref50.fa", " -pir",
273 "test_uniref50_out.pir", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
274 { "headless -open examples/uniref50.fa", " -pfam",
275 "test_uniref50_out.pfam", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
276 { "headless -open examples/uniref50.fa", " -blc",
277 "test_uniref50_out.blc", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
278 { "headless -open examples/uniref50.fa", " -jalview",
279 "test_uniref50_out.jvp", true, MINFILESIZE_SMALL, TEST_TIMEOUT }, };