1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.bin; |
22 |
|
|
23 |
|
import jalview.gui.JvOptionPane; |
24 |
|
|
25 |
|
import java.io.BufferedReader; |
26 |
|
import java.io.File; |
27 |
|
import java.io.IOException; |
28 |
|
import java.io.InputStreamReader; |
29 |
|
import java.util.ArrayList; |
30 |
|
|
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; |
37 |
|
|
|
|
| 84.2% |
Uncovered Elements: 12 (76) |
Complexity: 20 |
Complexity Density: 0.38 |
|
38 |
|
public class CommandLineOperations |
39 |
|
{ |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
41 |
1 |
@BeforeClass(alwaysRun = true)... |
42 |
|
public void setUpJvOptionPane() |
43 |
|
{ |
44 |
1 |
JvOptionPane.setInteractiveMode(false); |
45 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
46 |
|
} |
47 |
|
|
48 |
|
private static final int TEST_TIMEOUT = 4500; |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
private static final int SETUP_TIMEOUT = 9000; |
53 |
|
|
54 |
|
private static final int MINFILESIZE_SMALL = 2096; |
55 |
|
|
56 |
|
private static final int MINFILESIZE_BIG = 4096; |
57 |
|
|
58 |
|
private ArrayList<String> successfulCMDs = new ArrayList<String>(); |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
@author |
66 |
|
|
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 7 |
Complexity Density: 0.88 |
|
68 |
|
private static class Worker extends Thread |
69 |
|
{ |
70 |
|
private final Process process; |
71 |
|
|
72 |
|
private BufferedReader outputReader; |
73 |
|
|
74 |
|
private BufferedReader errorReader; |
75 |
|
|
76 |
|
private Integer exit; |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
18 |
private Worker(Process process)... |
79 |
|
{ |
80 |
18 |
this.process = process; |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
83 |
18 |
@Override... |
84 |
|
public void run() |
85 |
|
{ |
86 |
18 |
try |
87 |
|
{ |
88 |
18 |
exit = process.waitFor(); |
89 |
|
} catch (InterruptedException ignore) |
90 |
|
{ |
91 |
1 |
return; |
92 |
|
} |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
18 |
public BufferedReader getOutputReader()... |
96 |
|
{ |
97 |
18 |
return outputReader; |
98 |
|
} |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
100 |
18 |
public void setOutputReader(BufferedReader outputReader)... |
101 |
|
{ |
102 |
18 |
this.outputReader = outputReader; |
103 |
|
} |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
6 |
public BufferedReader getErrorReader()... |
106 |
|
{ |
107 |
6 |
return errorReader; |
108 |
|
} |
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
110 |
18 |
public void setErrorReader(BufferedReader errorReader)... |
111 |
|
{ |
112 |
18 |
this.errorReader = errorReader; |
113 |
|
} |
114 |
|
} |
115 |
|
|
|
|
| 90.5% |
Uncovered Elements: 2 (21) |
Complexity: 5 |
Complexity Density: 0.29 |
|
116 |
18 |
private Worker jalviewDesktopRunner(boolean withAwt, String cmd,... |
117 |
|
int timeout) |
118 |
|
{ |
119 |
18 |
String _cmd = "java " |
120 |
18 |
+ (withAwt ? "-Djava.awt.headless=true" : "") |
121 |
|
+ " -Djava.ext.dirs=./lib -classpath ./classes jalview.bin.Jalview "; |
122 |
18 |
System.out.println("CMD [" + cmd + "]"); |
123 |
18 |
Process ls2_proc = null; |
124 |
18 |
Worker worker = null; |
125 |
18 |
try |
126 |
|
{ |
127 |
18 |
ls2_proc = Runtime.getRuntime().exec(_cmd + cmd); |
128 |
|
} catch (IOException e1) |
129 |
|
{ |
130 |
0 |
e1.printStackTrace(); |
131 |
|
} |
132 |
18 |
if (ls2_proc != null) |
133 |
|
{ |
134 |
18 |
BufferedReader outputReader = new BufferedReader( |
135 |
|
new InputStreamReader(ls2_proc.getInputStream())); |
136 |
18 |
BufferedReader errorReader = new BufferedReader( |
137 |
|
new InputStreamReader(ls2_proc.getErrorStream())); |
138 |
18 |
worker = new Worker(ls2_proc); |
139 |
18 |
worker.start(); |
140 |
18 |
try |
141 |
|
{ |
142 |
18 |
worker.join(timeout); |
143 |
|
} catch (InterruptedException e) |
144 |
|
{ |
145 |
|
|
146 |
|
} |
147 |
18 |
worker.setOutputReader(outputReader); |
148 |
18 |
worker.setErrorReader(errorReader); |
149 |
|
} |
150 |
18 |
return worker; |
151 |
|
} |
152 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
153 |
1 |
@BeforeTest(alwaysRun = true)... |
154 |
|
public void initialize() |
155 |
|
{ |
156 |
1 |
new CommandLineOperations(); |
157 |
|
} |
158 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
159 |
1 |
@BeforeTest(alwaysRun = true)... |
160 |
|
public void setUpForHeadlessCommandLineInputOperations() |
161 |
|
throws IOException |
162 |
|
{ |
163 |
1 |
String cmds = "nodisplay -open examples/uniref50.fa -sortbytree -props FILE -colour zappo " |
164 |
|
+ "-jabaws http://www.compbio.dundee.ac.uk/jabaws -nosortbytree -dasserver nickname=www.test.com " |
165 |
|
+ "-features examples/testdata/plantfdx.features -annotations examples/testdata/plantfdx.annotations -tree examples/testdata/uniref50_test_tree"; |
166 |
1 |
Worker worker = jalviewDesktopRunner(true, cmds, SETUP_TIMEOUT); |
167 |
1 |
String ln = null; |
168 |
? |
while ((ln = worker.getOutputReader().readLine()) != null) |
169 |
|
{ |
170 |
17 |
System.out.println(ln); |
171 |
17 |
successfulCMDs.add(ln); |
172 |
|
} |
173 |
|
} |
174 |
|
|
|
|
| 84.2% |
Uncovered Elements: 3 (19) |
Complexity: 5 |
Complexity Density: 0.38 |
|
175 |
1 |
@BeforeTest(alwaysRun = true)... |
176 |
|
public void setUpForCommandLineInputOperations() throws IOException |
177 |
|
{ |
178 |
1 |
String cmds = "-open examples/uniref50.fa -noquestionnaire -nousagestats"; |
179 |
1 |
Worker worker = jalviewDesktopRunner(false, cmds, SETUP_TIMEOUT); |
180 |
1 |
String ln = null; |
181 |
1 |
int count = 0; |
182 |
? |
while ((ln = worker.getErrorReader().readLine()) != null) |
183 |
|
{ |
184 |
6 |
System.out.println(ln); |
185 |
6 |
successfulCMDs.add(ln); |
186 |
6 |
if (++count > 5) |
187 |
|
{ |
188 |
1 |
break; |
189 |
|
} |
190 |
|
} |
191 |
1 |
if (worker != null && worker.exit == null) |
192 |
|
{ |
193 |
1 |
worker.interrupt(); |
194 |
1 |
Thread.currentThread().interrupt(); |
195 |
1 |
worker.process.destroy(); |
196 |
|
} |
197 |
|
} |
198 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
199 |
12 |
@Test(groups = { "Functional" }, dataProvider = "allInputOpearationsData")... |
200 |
|
public void testAllInputOperations(String expectedString, |
201 |
|
String failureMsg) |
202 |
|
{ |
203 |
12 |
Assert.assertTrue(successfulCMDs.contains(expectedString), failureMsg); |
204 |
|
} |
205 |
|
|
|
|
| 61.5% |
Uncovered Elements: 5 (13) |
Complexity: 3 |
Complexity Density: 0.27 |
|
206 |
16 |
@Test(... |
207 |
|
groups = { "Functional" }, |
208 |
|
dataProvider = "headlessModeOutputOperationsData") |
209 |
|
public void testHeadlessModeOutputOperations(String harg, String type, |
210 |
|
String fileName, boolean withAWT, int expectedMinFileSize, |
211 |
|
int timeout) |
212 |
|
{ |
213 |
16 |
String cmd = harg + type + " " + fileName; |
214 |
|
|
215 |
16 |
File file = new File(fileName); |
216 |
16 |
Worker worker = jalviewDesktopRunner(withAWT, cmd, timeout); |
217 |
|
|
218 |
16 |
FileAssert.assertFile(file, "Didn't create an output" + type |
219 |
|
+ " file.[" + harg + "]"); |
220 |
16 |
FileAssert.assertMinLength(new File(fileName), expectedMinFileSize); |
221 |
16 |
if (worker != null && worker.exit == null) |
222 |
|
{ |
223 |
0 |
worker.interrupt(); |
224 |
0 |
Thread.currentThread().interrupt(); |
225 |
0 |
worker.process.destroy(); |
226 |
0 |
Assert.fail("Jalview did not exit after " |
227 |
|
+ type |
228 |
|
+ " generation (try running test again to verify - timeout at " |
229 |
|
+ SETUP_TIMEOUT + "ms). [" |
230 |
|
+ harg + "]"); |
231 |
|
} |
232 |
16 |
new File(fileName).delete(); |
233 |
|
} |
234 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
235 |
1 |
@DataProvider(name = "allInputOpearationsData")... |
236 |
|
public Object[][] getHeadlessModeInputParams() |
237 |
|
{ |
238 |
1 |
return new Object[][] { |
239 |
|
|
240 |
|
{ "CMD [-color zappo] executed successfully!", |
241 |
|
"Failed command : -color zappo" }, |
242 |
|
{ "CMD [-props FILE] executed successfully!", |
243 |
|
"Failed command : -props File" }, |
244 |
|
{ "CMD [-sortbytree] executed successfully!", |
245 |
|
"Failed command : -sortbytree" }, |
246 |
|
{ |
247 |
|
"CMD [-jabaws http://www.compbio.dundee.ac.uk/jabaws] executed successfully!", |
248 |
|
"Failed command : -jabaws http://www.compbio.dundee.ac.uk/jabaws" }, |
249 |
|
{ "CMD [-open examples/uniref50.fa] executed successfully!", |
250 |
|
"Failed command : -open examples/uniref50.fa" }, |
251 |
|
{ "CMD [-nosortbytree] executed successfully!", |
252 |
|
"Failed command : -nosortbytree" }, |
253 |
|
{ "CMD [-dasserver nickname=www.test.com] executed successfully!", |
254 |
|
"Failed command : -dasserver nickname=www.test.com" }, |
255 |
|
{ |
256 |
|
"CMD [-features examples/testdata/plantfdx.features] executed successfully!", |
257 |
|
"Failed command : -features examples/testdata/plantfdx.features" }, |
258 |
|
{ |
259 |
|
"CMD [-annotations examples/testdata/plantfdx.annotations] executed successfully!", |
260 |
|
"Failed command : -annotations examples/testdata/plantfdx.annotations" }, |
261 |
|
{ |
262 |
|
"CMD [-tree examples/testdata/uniref50_test_tree] executed successfully!", |
263 |
|
"Failed command : -tree examples/testdata/uniref50_test_tree" }, |
264 |
|
|
265 |
|
{ "CMD [-nousagestats] executed successfully!", |
266 |
|
"Failed command : -nousagestats" }, |
267 |
|
{ "CMD [-noquestionnaire] executed successfully!", |
268 |
|
"Failed command : -noquestionnaire nickname=www.test.com" } }; |
269 |
|
|
270 |
|
} |
271 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
272 |
1 |
@DataProvider(name = "headlessModeOutputOperationsData")... |
273 |
|
public static Object[][] getHeadlessModeOutputParams() |
274 |
|
{ |
275 |
1 |
return new Object[][] { |
276 |
|
{ "nodisplay -open examples/uniref50.fa", " -eps", |
277 |
|
"test_uniref50_out.eps", true, MINFILESIZE_BIG, TEST_TIMEOUT }, |
278 |
|
{ "nodisplay -open examples/uniref50.fa", " -eps", |
279 |
|
"test_uniref50_out.eps", false, MINFILESIZE_BIG, TEST_TIMEOUT }, |
280 |
|
{ "nogui -open examples/uniref50.fa", " -eps", |
281 |
|
"test_uniref50_out.eps", true, MINFILESIZE_BIG, TEST_TIMEOUT }, |
282 |
|
{ "nogui -open examples/uniref50.fa", " -eps", |
283 |
|
"test_uniref50_out.eps", false, MINFILESIZE_BIG, TEST_TIMEOUT }, |
284 |
|
{ "headless -open examples/uniref50.fa", " -eps", |
285 |
|
"test_uniref50_out.eps", true, MINFILESIZE_BIG, TEST_TIMEOUT }, |
286 |
|
{ "headless -open examples/uniref50.fa", " -svg", |
287 |
|
"test_uniref50_out.svg", false, MINFILESIZE_BIG, TEST_TIMEOUT }, |
288 |
|
{ "headless -open examples/uniref50.fa", " -png", |
289 |
|
"test_uniref50_out.png", true, MINFILESIZE_BIG, TEST_TIMEOUT }, |
290 |
|
{ "headless -open examples/uniref50.fa", " -html", |
291 |
|
"test_uniref50_out.html", true, MINFILESIZE_BIG, TEST_TIMEOUT }, |
292 |
|
{ "headless -open examples/uniref50.fa", " -fasta", |
293 |
|
"test_uniref50_out.mfa", true, MINFILESIZE_SMALL, TEST_TIMEOUT }, |
294 |
|
{ "headless -open examples/uniref50.fa", " -clustal", |
295 |
|
"test_uniref50_out.aln", true, MINFILESIZE_SMALL, TEST_TIMEOUT }, |
296 |
|
{ "headless -open examples/uniref50.fa", " -msf", |
297 |
|
"test_uniref50_out.msf", true, MINFILESIZE_SMALL, TEST_TIMEOUT }, |
298 |
|
{ "headless -open examples/uniref50.fa", " -pileup", |
299 |
|
"test_uniref50_out.aln", true, MINFILESIZE_SMALL, TEST_TIMEOUT }, |
300 |
|
{ "headless -open examples/uniref50.fa", " -pir", |
301 |
|
"test_uniref50_out.pir", true, MINFILESIZE_SMALL, TEST_TIMEOUT }, |
302 |
|
{ "headless -open examples/uniref50.fa", " -pfam", |
303 |
|
"test_uniref50_out.pfam", true, MINFILESIZE_SMALL, TEST_TIMEOUT }, |
304 |
|
{ "headless -open examples/uniref50.fa", " -blc", |
305 |
|
"test_uniref50_out.blc", true, MINFILESIZE_SMALL, TEST_TIMEOUT }, |
306 |
|
{ "headless -open examples/uniref50.fa", " -jalview", |
307 |
|
"test_uniref50_out.jvp", true, MINFILESIZE_SMALL, TEST_TIMEOUT }, }; |
308 |
|
} |
309 |
|
} |