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;
28 import org.testng.Assert;
29 import org.testng.FileAssert;
30 import org.testng.annotations.AfterClass;
31 import org.testng.annotations.BeforeClass;
32 import org.testng.annotations.BeforeTest;
33 import org.testng.annotations.DataProvider;
34 import org.testng.annotations.Test;
36 public class CommandLineOperations
40 public static void setUpBeforeClass() throws Exception
45 public static void tearDownAfterClass() throws Exception
51 * http://stackoverflow.com/questions/808276/how-to-add-a-timeout-value-when
52 * -using-javas-runtime-exec
57 private static class Worker extends Thread
59 private final Process process;
63 private Worker(Process process)
65 this.process = process;
72 exit = process.waitFor();
73 } catch (InterruptedException ignore)
80 private Worker jalviewDesktopRunner(boolean withAwt, String cmd,
81 int timeout) throws InterruptedException, IOException
84 + (withAwt ? "-Djava.awt.headless=true" : "")
85 + " -Djava.ext.dirs=./lib -classpath ./classes jalview.bin.Jalview ";
86 System.out.println("############ Testing Jalview CMD: " + _cmd + cmd);
87 Process ls2_proc = Runtime.getRuntime().exec(_cmd + cmd);
88 BufferedReader outputReader = new BufferedReader(new InputStreamReader(
89 ls2_proc.getInputStream()));
91 BufferedReader errorReader = new BufferedReader(new InputStreamReader(
92 ls2_proc.getErrorStream()));
93 Worker worker = new Worker(ls2_proc);
96 // System.out.println("Output: ");
98 // while ((ln = outputReader.readLine()) != null)
100 // System.out.println(ln);
103 // System.out.println("Error: ");
104 // while ((ln = errorReader.readLine()) != null)
106 // System.out.println(ln);
112 public void initialize()
114 new CommandLineOperations();
118 { "Functional" }, dataProvider = "headlessModeOutputParams")
119 public void testHeadlessModeOutputs(String harg, String type,
120 String fileName, boolean withAWT, int expectedMinFileSize)
122 String cmd = harg + type + " " + fileName;
123 // System.out.println(">>>>>>>>>>>>>>>> Command : " + cmd);
124 File file = new File(fileName);
125 Worker worker = null;
128 worker = jalviewDesktopRunner(withAWT, cmd, 9000);
129 } catch (InterruptedException e)
132 } catch (IOException e)
137 FileAssert.assertFile(file, "Didn't create an output" + type
138 + " file.[" + harg + "]");
139 FileAssert.assertMinLength(new File(fileName), expectedMinFileSize);
140 if (worker != null && worker.exit == null)
143 Thread.currentThread().interrupt();
144 worker.process.destroy();
145 Assert.fail("Jalview did not exit after "
147 + " generation (try running test again to verify - timeout at 9000ms). ["
150 new File(fileName).delete();
153 @DataProvider(name = "headlessModeOutputParams")
154 public static Object[][] headlessModeOutput()
156 return new Object[][]
158 { "nodisplay -open examples/uniref50.fa", " -eps",
159 "test_uniref50_out.eps", true, 4096 },
160 { "nodisplay -open examples/uniref50.fa", " -eps",
161 "test_uniref50_out.eps", false, 4096 },
162 { "headless -open examples/uniref50.fa", " -eps",
163 "test_uniref50_out.eps", true, 4096 },
164 { "headless -open examples/uniref50.fa", " -eps",
165 "test_uniref50_out.eps", false, 4096 },
166 { "nogui -open examples/uniref50.fa", " -eps",
167 "test_uniref50_out.eps", true, 4096 },
168 { "nogui -open examples/uniref50.fa", " -eps",
169 "test_uniref50_out.eps", false, 4096 },
170 { "headless -open examples/uniref50.fa", " -svg",
171 "test_uniref50_out.svg", true, 4096 },
172 { "headless -open examples/uniref50.fa", " -svg",
173 "test_uniref50_out.svg", false, 4096 },
174 { "headless -open examples/uniref50.fa", " -png",
175 "test_uniref50_out.png", true, 4096 },
176 { "headless -open examples/uniref50.fa", " -png",
177 "test_uniref50_out.png", false, 4096 },
178 { "headless -open examples/uniref50.fa", " -html",
179 "test_uniref50_out.html", true, 4096 },
180 { "headless -open examples/uniref50.fa", " -html",
181 "test_uniref50_out.html", false, 4096 },
182 { "headless -open examples/uniref50.fa", " -fasta",
183 "test_uniref50_out.mfa", true, 2096 },
184 { "headless -open examples/uniref50.fa", " -fasta",
185 "test_uniref50_out.mfa", false, 2096 },
186 { "headless -open examples/uniref50.fa", " -clustal",
187 "test_uniref50_out.aln", true, 2096 },
188 { "headless -open examples/uniref50.fa", " -clustal",
189 "test_uniref50_out.aln", false, 2096 },
190 { "headless -open examples/uniref50.fa", " -msf",
191 "test_uniref50_out.msf", true, 2096 },
192 { "headless -open examples/uniref50.fa", " -msf",
193 "test_uniref50_out.msf", false, 2096 },
194 { "headless -open examples/uniref50.fa", " -pileup",
195 "test_uniref50_out.aln", true, 2096 },
196 { "headless -open examples/uniref50.fa", " -pileup",
197 "test_uniref50_out.aln", false, 2096 },
198 { "headless -open examples/uniref50.fa", " -pir",
199 "test_uniref50_out.pir", true, 2096 },
200 { "headless -open examples/uniref50.fa", " -pir",
201 "test_uniref50_out.pir", false, 2096 },
202 { "headless -open examples/uniref50.fa", " -pfam",
203 "test_uniref50_out.pfam", true, 2096 },
204 { "headless -open examples/uniref50.fa", " -pfam",
205 "test_uniref50_out.pfam", false, 2096 },
206 { "headless -open examples/uniref50.fa", " -blc",
207 "test_uniref50_out.blc", true, 2096 },
208 { "headless -open examples/uniref50.fa", " -blc",
209 "test_uniref50_out.blc", false, 2096 },
210 { "headless -open examples/uniref50.fa", " -jalview",
211 "test_uniref50_out.jvp", true, 2096 },
212 { "headless -open examples/uniref50.fa", " -jalview",
213 "test_uniref50_out.jvp", false, 2096 },