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 public class CommandLineOperations
42 @BeforeClass(alwaysRun = true)
43 public void setUpJvOptionPane()
45 JvOptionPane.setInteractiveMode(false);
46 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
49 private static final int TEST_TIMEOUT = 4500; // Note longer timeout needed on
50 // full test run than on
53 private static final int SETUP_TIMEOUT = 9000;
55 private static final int MINFILESIZE_SMALL = 2096;
57 private static final int MINFILESIZE_BIG = 4096;
59 private ArrayList<String> successfulCMDs = new ArrayList<>();
61 private Worker jalviewDesktopRunner(boolean withAwt, String cmd,
65 if (System.getProperty("os.name").indexOf("Windows") >= 0)
69 // Note: JAL-3065 - don't include quotes for lib/* because the arguments are
70 // not expanded by the shell
72 + (withAwt ? "-Djava.awt.headless=true" : "")
73 + " -classpath ./classes" + cp_sep
74 + "./lib/* jalview.bin.Jalview ";
75 System.out.println("CMD [" + cmd + "]");
76 Process ls2_proc = null;
80 ls2_proc = Runtime.getRuntime().exec(_cmd + cmd);
81 } catch (IOException e1)
87 BufferedReader outputReader = new BufferedReader(
88 new InputStreamReader(ls2_proc.getInputStream()));
89 BufferedReader errorReader = new BufferedReader(
90 new InputStreamReader(ls2_proc.getErrorStream()));
91 worker = new Worker(ls2_proc);
96 } catch (InterruptedException e)
98 // e.printStackTrace();
100 worker.setOutputReader(outputReader);
101 worker.setErrorReader(errorReader);
106 @BeforeTest(alwaysRun = true)
107 public void initialize()
109 new CommandLineOperations();
112 @BeforeTest(alwaysRun = true)
113 public void setUpForHeadlessCommandLineInputOperations()
116 String cmds = "nodisplay -open examples/uniref50.fa -sortbytree -props FILE -colour zappo "
117 + "-jabaws http://www.compbio.dundee.ac.uk/jabaws -nosortbytree -dasserver nickname=www.test.com "
118 + "-features examples/testdata/plantfdx.features -annotations examples/testdata/plantfdx.annotations -tree examples/testdata/uniref50_test_tree";
119 Worker worker = jalviewDesktopRunner(true, cmds, SETUP_TIMEOUT);
121 while ((ln = worker.getOutputReader().readLine()) != null)
123 System.out.println(ln);
124 successfulCMDs.add(ln);
128 @BeforeTest(alwaysRun = true)
129 public void setUpForCommandLineInputOperations() throws IOException
131 String cmds = "-open examples/uniref50.fa -noquestionnaire -nousagestats";
132 Worker worker = jalviewDesktopRunner(false, cmds, SETUP_TIMEOUT);
135 while ((ln = worker.getErrorReader().readLine()) != null)
137 System.out.println(ln);
138 successfulCMDs.add(ln);
144 if (worker != null && worker.getExitValue() == null)
146 worker.destroyProcess();
151 @Test(groups = { "Functional" }, dataProvider = "allInputOpearationsData")
152 public void testAllInputOperations(String expectedString,
155 Assert.assertTrue(successfulCMDs.contains(expectedString), failureMsg);
159 groups = { "Functional" },
160 dataProvider = "headlessModeOutputOperationsData")
161 public void testHeadlessModeOutputOperations(String harg, String type,
162 String fileName, boolean withAWT, int expectedMinFileSize,
165 String cmd = harg + type + " " + fileName;
166 // System.out.println(">>>>>>>>>>>>>>>> Command : " + cmd);
167 File file = new File(fileName);
168 Worker worker = jalviewDesktopRunner(withAWT, cmd, timeout);
170 FileAssert.assertFile(file, "Didn't create an output" + type
171 + " file.[" + harg + "]");
172 FileAssert.assertMinLength(new File(fileName), expectedMinFileSize);
173 if (worker != null && worker.getExitValue() == null)
175 worker.destroyProcess();
176 Assert.fail("Jalview did not exit after "
178 + " generation (try running test again to verify - timeout at "
179 + SETUP_TIMEOUT + "ms). ["
182 new File(fileName).delete();
185 @DataProvider(name = "allInputOpearationsData")
186 public Object[][] getHeadlessModeInputParams()
188 return new Object[][] {
189 // headless mode input operations
190 { "CMD [-color zappo] executed successfully!",
191 "Failed command : -color zappo" },
192 { "CMD [-props FILE] executed successfully!",
193 "Failed command : -props File" },
194 { "CMD [-sortbytree] executed successfully!",
195 "Failed command : -sortbytree" },
197 "CMD [-jabaws http://www.compbio.dundee.ac.uk/jabaws] executed successfully!",
198 "Failed command : -jabaws http://www.compbio.dundee.ac.uk/jabaws" },
199 { "CMD [-open examples/uniref50.fa] executed successfully!",
200 "Failed command : -open examples/uniref50.fa" },
201 { "CMD [-nosortbytree] executed successfully!",
202 "Failed command : -nosortbytree" },
203 { "CMD [-dasserver nickname=www.test.com] executed successfully!",
204 "Failed command : -dasserver nickname=www.test.com" },
206 "CMD [-features examples/testdata/plantfdx.features] executed successfully!",
207 "Failed command : -features examples/testdata/plantfdx.features" },
209 "CMD [-annotations examples/testdata/plantfdx.annotations] executed successfully!",
210 "Failed command : -annotations examples/testdata/plantfdx.annotations" },
212 "CMD [-tree examples/testdata/uniref50_test_tree] executed successfully!",
213 "Failed command : -tree examples/testdata/uniref50_test_tree" },
214 // non headless mode input operations
215 { "CMD [-nousagestats] executed successfully!",
216 "Failed command : -nousagestats" },
217 { "CMD [-noquestionnaire] executed successfully!",
218 "Failed command : -noquestionnaire nickname=www.test.com" } };
222 @DataProvider(name = "headlessModeOutputOperationsData")
223 public static Object[][] getHeadlessModeOutputParams()
225 return new Object[][] {
226 { "nodisplay -open examples/uniref50.fa", " -eps",
227 "test_uniref50_out.eps", true, MINFILESIZE_BIG, TEST_TIMEOUT },
228 { "nodisplay -open examples/uniref50.fa", " -eps",
229 "test_uniref50_out.eps", false, MINFILESIZE_BIG, TEST_TIMEOUT },
230 { "nogui -open examples/uniref50.fa", " -eps",
231 "test_uniref50_out.eps", true, MINFILESIZE_BIG, TEST_TIMEOUT },
232 { "nogui -open examples/uniref50.fa", " -eps",
233 "test_uniref50_out.eps", false, MINFILESIZE_BIG, TEST_TIMEOUT },
234 { "headless -open examples/uniref50.fa", " -eps",
235 "test_uniref50_out.eps", true, MINFILESIZE_BIG, TEST_TIMEOUT },
236 { "headless -open examples/uniref50.fa", " -svg",
237 "test_uniref50_out.svg", false, MINFILESIZE_BIG, TEST_TIMEOUT },
238 { "headless -open examples/uniref50.fa", " -png",
239 "test_uniref50_out.png", true, MINFILESIZE_BIG, TEST_TIMEOUT },
240 { "headless -open examples/uniref50.fa", " -html",
241 "test_uniref50_out.html", true, MINFILESIZE_BIG, TEST_TIMEOUT },
242 { "headless -open examples/uniref50.fa", " -fasta",
243 "test_uniref50_out.mfa", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
244 { "headless -open examples/uniref50.fa", " -clustal",
245 "test_uniref50_out.aln", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
246 { "headless -open examples/uniref50.fa", " -msf",
247 "test_uniref50_out.msf", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
248 { "headless -open examples/uniref50.fa", " -pileup",
249 "test_uniref50_out.aln", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
250 { "headless -open examples/uniref50.fa", " -pir",
251 "test_uniref50_out.pir", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
252 { "headless -open examples/uniref50.fa", " -pfam",
253 "test_uniref50_out.pfam", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
254 { "headless -open examples/uniref50.fa", " -blc",
255 "test_uniref50_out.blc", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
256 { "headless -open examples/uniref50.fa", " -jalview",
257 "test_uniref50_out.jvp", true, MINFILESIZE_SMALL, TEST_TIMEOUT }, };