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();
117 @Test(dataProvider = "headlessModeOutputParams")
118 public void testHeadlessModeOutputs(String harg, String type,
119 String fileName, boolean withAWT, int expectedMinFileSize)
121 String cmd = harg + type + " " + fileName;
122 // System.out.println(">>>>>>>>>>>>>>>> Command : " + cmd);
123 File file = new File(fileName);
124 Worker worker = null;
127 worker = jalviewDesktopRunner(withAWT, cmd, 9000);
128 } catch (InterruptedException e)
131 } catch (IOException e)
136 FileAssert.assertFile(file, "Didn't create an output" + type
137 + " file.[" + harg + "]");
138 FileAssert.assertMinLength(new File(fileName), expectedMinFileSize);
139 if (worker != null && worker.exit == null)
142 Thread.currentThread().interrupt();
143 worker.process.destroy();
144 Assert.fail("Jalview did not exit after "
146 + " generation (try running test again to verify - timeout at 9000ms). ["
149 new File(fileName).delete();
152 @DataProvider(name = "headlessModeOutputParams")
153 public static Object[][] headlessModeOutput()
155 return new Object[][]
157 { "nodisplay -open examples/uniref50.fa", " -eps",
158 "test_uniref50_out.eps", true, 4096 },
159 { "nodisplay -open examples/uniref50.fa", " -eps",
160 "test_uniref50_out.eps", false, 4096 },
161 { "headless -open examples/uniref50.fa", " -eps",
162 "test_uniref50_out.eps", true, 4096 },
163 { "headless -open examples/uniref50.fa", " -eps",
164 "test_uniref50_out.eps", false, 4096 },
165 { "nogui -open examples/uniref50.fa", " -eps",
166 "test_uniref50_out.eps", true, 4096 },
167 { "nogui -open examples/uniref50.fa", " -eps",
168 "test_uniref50_out.eps", false, 4096 },
169 { "headless -open examples/uniref50.fa", " -svg",
170 "test_uniref50_out.svg", true, 4096 },
171 { "headless -open examples/uniref50.fa", " -svg",
172 "test_uniref50_out.svg", false, 4096 },
173 { "headless -open examples/uniref50.fa", " -png",
174 "test_uniref50_out.png", true, 4096 },
175 { "headless -open examples/uniref50.fa", " -png",
176 "test_uniref50_out.png", false, 4096 },
177 { "headless -open examples/uniref50.fa", " -html",
178 "test_uniref50_out.html", true, 4096 },
179 { "headless -open examples/uniref50.fa", " -html",
180 "test_uniref50_out.html", false, 4096 },
181 { "headless -open examples/uniref50.fa", " -fasta",
182 "test_uniref50_out.mfa", true, 2096 },
183 { "headless -open examples/uniref50.fa", " -fasta",
184 "test_uniref50_out.mfa", false, 2096 },
185 { "headless -open examples/uniref50.fa", " -clustal",
186 "test_uniref50_out.aln", true, 2096 },
187 { "headless -open examples/uniref50.fa", " -clustal",
188 "test_uniref50_out.aln", false, 2096 },
189 { "headless -open examples/uniref50.fa", " -msf",
190 "test_uniref50_out.msf", true, 2096 },
191 { "headless -open examples/uniref50.fa", " -msf",
192 "test_uniref50_out.msf", false, 2096 },
193 { "headless -open examples/uniref50.fa", " -pileup",
194 "test_uniref50_out.aln", true, 2096 },
195 { "headless -open examples/uniref50.fa", " -pileup",
196 "test_uniref50_out.aln", false, 2096 },
197 { "headless -open examples/uniref50.fa", " -pir",
198 "test_uniref50_out.pir", true, 2096 },
199 { "headless -open examples/uniref50.fa", " -pir",
200 "test_uniref50_out.pir", false, 2096 },
201 { "headless -open examples/uniref50.fa", " -pfam",
202 "test_uniref50_out.pfam", true, 2096 },
203 { "headless -open examples/uniref50.fa", " -pfam",
204 "test_uniref50_out.pfam", false, 2096 },
205 { "headless -open examples/uniref50.fa", " -blc",
206 "test_uniref50_out.blc", true, 2096 },
207 { "headless -open examples/uniref50.fa", " -blc",
208 "test_uniref50_out.blc", false, 2096 },
209 { "headless -open examples/uniref50.fa", " -jalview",
210 "test_uniref50_out.jvp", true, 2096 },
211 { "headless -open examples/uniref50.fa", " -jalview",
212 "test_uniref50_out.jvp", false, 2096 },