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 static org.testng.Assert.assertNotNull; |
24 |
|
import static org.testng.Assert.assertTrue; |
25 |
|
|
26 |
|
import jalview.gui.JvOptionPane; |
27 |
|
|
28 |
|
import java.io.BufferedReader; |
29 |
|
import java.io.File; |
30 |
|
import java.io.IOException; |
31 |
|
import java.io.InputStreamReader; |
32 |
|
import java.nio.file.Path; |
33 |
|
import java.nio.file.Paths; |
34 |
|
import java.util.ArrayList; |
35 |
|
|
36 |
|
import org.testng.Assert; |
37 |
|
import org.testng.FileAssert; |
38 |
|
import org.testng.annotations.BeforeClass; |
39 |
|
import org.testng.annotations.BeforeTest; |
40 |
|
import org.testng.annotations.DataProvider; |
41 |
|
import org.testng.annotations.Test; |
42 |
|
|
43 |
|
import io.github.classgraph.ClassGraph; |
44 |
|
import io.github.classgraph.ModuleRef; |
45 |
|
import io.github.classgraph.ScanResult; |
46 |
|
|
|
|
| 82% |
Uncovered Elements: 20 (111) |
Complexity: 28 |
Complexity Density: 0.36 |
|
47 |
|
public class CommandLineOperations |
48 |
|
{ |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
50 |
1 |
@BeforeClass(alwaysRun = true)... |
51 |
|
public void setUpJvOptionPane() |
52 |
|
{ |
53 |
1 |
JvOptionPane.setInteractiveMode(false); |
54 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
55 |
|
} |
56 |
|
|
57 |
|
private static final int TEST_TIMEOUT = 9000; |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
private static final int SETUP_TIMEOUT = 9000; |
63 |
|
|
64 |
|
private static final int MINFILESIZE_SMALL = 2096; |
65 |
|
|
66 |
|
private static final int MINFILESIZE_BIG = 4096; |
67 |
|
|
68 |
|
private ArrayList<String> successfulCMDs = new ArrayList<>(); |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
@author |
76 |
|
|
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 7 |
Complexity Density: 0.88 |
|
78 |
|
private static class Worker extends Thread |
79 |
|
{ |
80 |
|
private final Process process; |
81 |
|
|
82 |
|
private BufferedReader outputReader; |
83 |
|
|
84 |
|
private BufferedReader errorReader; |
85 |
|
|
86 |
|
private Integer exit; |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
18 |
private Worker(Process process)... |
89 |
|
{ |
90 |
18 |
this.process = process; |
91 |
|
} |
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
93 |
18 |
@Override... |
94 |
|
public void run() |
95 |
|
{ |
96 |
18 |
try |
97 |
|
{ |
98 |
18 |
exit = process.waitFor(); |
99 |
|
} catch (InterruptedException ignore) |
100 |
|
{ |
101 |
1 |
return; |
102 |
|
} |
103 |
|
} |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
16 |
public BufferedReader getOutputReader()... |
106 |
|
{ |
107 |
16 |
return outputReader; |
108 |
|
} |
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
110 |
18 |
public void setOutputReader(BufferedReader outputReader)... |
111 |
|
{ |
112 |
18 |
this.outputReader = outputReader; |
113 |
|
} |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
115 |
37 |
public BufferedReader getErrorReader()... |
116 |
|
{ |
117 |
37 |
return errorReader; |
118 |
|
} |
119 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
120 |
18 |
public void setErrorReader(BufferedReader errorReader)... |
121 |
|
{ |
122 |
18 |
this.errorReader = errorReader; |
123 |
|
} |
124 |
|
} |
125 |
|
|
126 |
|
private static ClassGraph scanner = null; |
127 |
|
|
128 |
|
private static String classpath = null; |
129 |
|
|
130 |
|
private static String modules = null; |
131 |
|
|
132 |
|
private static String java_exe = null; |
133 |
|
|
|
|
| 75% |
Uncovered Elements: 4 (16) |
Complexity: 4 |
Complexity Density: 0.33 |
|
134 |
18 |
public synchronized static String getClassPath()... |
135 |
|
{ |
136 |
18 |
if (scanner == null) |
137 |
|
{ |
138 |
1 |
scanner = new ClassGraph(); |
139 |
1 |
ScanResult scan = scanner.scan(); |
140 |
1 |
classpath = scan.getClasspath(); |
141 |
1 |
modules = ""; |
142 |
1 |
for (ModuleRef mr : scan.getModules()) |
143 |
|
{ |
144 |
0 |
modules.concat(mr.getName()); |
145 |
|
} |
146 |
1 |
java_exe = System.getProperty("java.home") + File.separator + "bin" |
147 |
|
+ File.separator + "java"; |
148 |
|
|
149 |
|
} |
150 |
18 |
while (classpath == null) |
151 |
|
{ |
152 |
0 |
try |
153 |
|
{ |
154 |
0 |
Thread.sleep(10); |
155 |
|
} catch (InterruptedException x) |
156 |
|
{ |
157 |
|
|
158 |
|
} |
159 |
|
} |
160 |
18 |
return classpath; |
161 |
|
} |
162 |
|
|
|
|
| 87.5% |
Uncovered Elements: 3 (24) |
Complexity: 6 |
Complexity Density: 0.33 |
|
163 |
18 |
private Worker getJalviewDesktopRunner(boolean withAwt, String cmd,... |
164 |
|
int timeout) |
165 |
|
{ |
166 |
|
|
167 |
|
|
168 |
18 |
String classpath = getClassPath(); |
169 |
18 |
String _cmd = java_exe + " " |
170 |
18 |
+ (withAwt ? "-Djava.awt.headless=true" : "") |
171 |
|
+ " -classpath " + classpath |
172 |
18 |
+ (modules.length() > 2 ? "--add-modules=\"" + modules + "\"" |
173 |
|
: "") |
174 |
|
+ " jalview.bin.Jalview "; |
175 |
18 |
Process ls2_proc = null; |
176 |
18 |
Worker worker = null; |
177 |
18 |
try |
178 |
|
{ |
179 |
18 |
ls2_proc = Runtime.getRuntime().exec(_cmd + cmd); |
180 |
|
} catch (Throwable e1) |
181 |
|
{ |
182 |
0 |
e1.printStackTrace(); |
183 |
|
} |
184 |
18 |
if (ls2_proc != null) |
185 |
|
{ |
186 |
18 |
BufferedReader outputReader = new BufferedReader( |
187 |
|
new InputStreamReader(ls2_proc.getInputStream())); |
188 |
18 |
BufferedReader errorReader = new BufferedReader( |
189 |
|
new InputStreamReader(ls2_proc.getErrorStream())); |
190 |
18 |
worker = new Worker(ls2_proc); |
191 |
18 |
worker.start(); |
192 |
18 |
try |
193 |
|
{ |
194 |
18 |
worker.join(timeout); |
195 |
|
} catch (InterruptedException e) |
196 |
|
{ |
197 |
1 |
System.err.println("Thread interrupted"); |
198 |
|
} |
199 |
18 |
worker.setOutputReader(outputReader); |
200 |
18 |
worker.setErrorReader(errorReader); |
201 |
|
} |
202 |
18 |
return worker; |
203 |
|
} |
204 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
205 |
1 |
@Test(groups = { "Functional" })... |
206 |
|
public void reportCurrentWorkingDirectory() |
207 |
|
{ |
208 |
1 |
try |
209 |
|
{ |
210 |
1 |
Path currentRelativePath = Paths.get(""); |
211 |
1 |
String s = currentRelativePath.toAbsolutePath().toString(); |
212 |
1 |
System.out.println("Test CWD is " + s); |
213 |
|
} catch (Exception q) |
214 |
|
{ |
215 |
0 |
q.printStackTrace(); |
216 |
|
} |
217 |
|
} |
218 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
219 |
1 |
@BeforeTest(alwaysRun = true)... |
220 |
|
public void initialize() |
221 |
|
{ |
222 |
1 |
new CommandLineOperations(); |
223 |
|
} |
224 |
|
|
|
|
| 66.7% |
Uncovered Elements: 4 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
225 |
1 |
@BeforeTest(alwaysRun = true)... |
226 |
|
public void setUpForHeadlessCommandLineInputOperations() |
227 |
|
throws IOException |
228 |
|
{ |
229 |
1 |
String cmds = "nodisplay -open examples/uniref50.fa -sortbytree -props test/jalview/io/testProps.jvprops -colour zappo " |
230 |
|
+ "-jabaws http://www.compbio.dundee.ac.uk/jabaws -nosortbytree " |
231 |
|
+ "-features examples/testdata/plantfdx.features -annotations examples/testdata/plantfdx.annotations -tree examples/testdata/uniref50_test_tree"; |
232 |
1 |
Worker worker = getJalviewDesktopRunner(true, cmds, SETUP_TIMEOUT); |
233 |
1 |
String ln = null; |
234 |
? |
while ((ln = worker.getOutputReader().readLine()) != null) |
235 |
|
{ |
236 |
15 |
System.out.println(ln); |
237 |
15 |
successfulCMDs.add(ln); |
238 |
|
} |
239 |
? |
while ((ln = worker.getErrorReader().readLine()) != null) |
240 |
|
{ |
241 |
10 |
System.err.println(ln); |
242 |
|
} |
243 |
|
} |
244 |
|
|
|
|
| 84.2% |
Uncovered Elements: 3 (19) |
Complexity: 5 |
Complexity Density: 0.38 |
|
245 |
1 |
@BeforeTest(alwaysRun = true)... |
246 |
|
public void setUpForCommandLineInputOperations() throws IOException |
247 |
|
{ |
248 |
1 |
String cmds = "-open examples/uniref50.fa -noquestionnaire -nousagestats"; |
249 |
1 |
Worker worker = getJalviewDesktopRunner(false, cmds, SETUP_TIMEOUT); |
250 |
1 |
String ln = null; |
251 |
1 |
int count = 0; |
252 |
? |
while ((ln = worker.getErrorReader().readLine()) != null) |
253 |
|
{ |
254 |
26 |
System.out.println(ln); |
255 |
26 |
successfulCMDs.add(ln); |
256 |
26 |
if (++count > 25) |
257 |
|
{ |
258 |
1 |
break; |
259 |
|
} |
260 |
|
} |
261 |
1 |
if (worker != null && worker.exit == null) |
262 |
|
{ |
263 |
1 |
worker.interrupt(); |
264 |
1 |
Thread.currentThread().interrupt(); |
265 |
1 |
worker.process.destroy(); |
266 |
|
} |
267 |
|
} |
268 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
269 |
11 |
@Test(groups = { "Functional" }, dataProvider = "allInputOperationsData")... |
270 |
|
public void testAllInputOperations(String expectedString, |
271 |
|
String failureMsg) |
272 |
|
{ |
273 |
11 |
Assert.assertTrue(successfulCMDs.contains(expectedString), failureMsg); |
274 |
|
} |
275 |
|
|
|
|
| 70.6% |
Uncovered Elements: 5 (17) |
Complexity: 3 |
Complexity Density: 0.2 |
|
276 |
16 |
@Test(... |
277 |
|
groups = |
278 |
|
{ "Functional", "testben" }, |
279 |
|
dataProvider = "headlessModeOutputOperationsData") |
280 |
|
public void testHeadlessModeOutputOperations(String harg, String type, |
281 |
|
String fileName, boolean withAWT, int expectedMinFileSize, |
282 |
|
int timeout) |
283 |
|
{ |
284 |
16 |
String cmd = harg + type + " " + fileName; |
285 |
|
|
286 |
16 |
File file = new File(fileName); |
287 |
16 |
file.deleteOnExit(); |
288 |
16 |
Worker worker = getJalviewDesktopRunner(withAWT, cmd, timeout); |
289 |
16 |
assertNotNull(worker, "worker is null"); |
290 |
16 |
String msg = "Didn't create an output" + type + " file.[" + harg + "]"; |
291 |
16 |
assertTrue(file.exists(), msg); |
292 |
16 |
FileAssert.assertFile(file, msg); |
293 |
16 |
FileAssert.assertMinLength(file, expectedMinFileSize); |
294 |
16 |
if (worker != null && worker.exit == null) |
295 |
|
{ |
296 |
0 |
worker.interrupt(); |
297 |
0 |
Thread.currentThread().interrupt(); |
298 |
0 |
worker.process.destroy(); |
299 |
0 |
Assert.fail("Jalview did not exit after " + type |
300 |
|
+ " generation (try running test again to verify - timeout at " |
301 |
|
+ timeout + "ms). [" + harg + "]"); |
302 |
|
} |
303 |
16 |
file.delete(); |
304 |
|
} |
305 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
306 |
1 |
@DataProvider(name = "allInputOperationsData")... |
307 |
|
public Object[][] getHeadlessModeInputParams() |
308 |
|
{ |
309 |
1 |
return new Object[][] { |
310 |
|
|
311 |
|
{ "CMD [-color zappo] executed successfully!", |
312 |
|
"Failed command : -color zappo" }, |
313 |
|
{ "CMD [-props test/jalview/io/testProps.jvprops] executed successfully!", |
314 |
|
"Failed command : -props File" }, |
315 |
|
{ "CMD [-sortbytree] executed successfully!", |
316 |
|
"Failed command : -sortbytree" }, |
317 |
|
{ "CMD [-jabaws http://www.compbio.dundee.ac.uk/jabaws] executed successfully!", |
318 |
|
"Failed command : -jabaws http://www.compbio.dundee.ac.uk/jabaws" }, |
319 |
|
{ "CMD [-open examples/uniref50.fa] executed successfully!", |
320 |
|
"Failed command : -open examples/uniref50.fa" }, |
321 |
|
{ "CMD [-nosortbytree] executed successfully!", |
322 |
|
"Failed command : -nosortbytree" }, |
323 |
|
{ "CMD [-features examples/testdata/plantfdx.features] executed successfully!", |
324 |
|
"Failed command : -features examples/testdata/plantfdx.features" }, |
325 |
|
{ "CMD [-annotations examples/testdata/plantfdx.annotations] executed successfully!", |
326 |
|
"Failed command : -annotations examples/testdata/plantfdx.annotations" }, |
327 |
|
{ "CMD [-tree examples/testdata/uniref50_test_tree] executed successfully!", |
328 |
|
"Failed command : -tree examples/testdata/uniref50_test_tree" }, |
329 |
|
|
330 |
|
{ "CMD [-nousagestats] executed successfully!", |
331 |
|
"Failed command : -nousagestats" }, |
332 |
|
{ "CMD [-noquestionnaire] executed successfully!", |
333 |
|
"Failed command : -noquestionnaire" } }; |
334 |
|
} |
335 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
336 |
1 |
@DataProvider(name = "headlessModeOutputOperationsData")... |
337 |
|
public static Object[][] getHeadlessModeOutputParams() |
338 |
|
{ |
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
1 |
String workingDir = "test/jalview/bin/"; |
344 |
1 |
return new Object[][] { { "nodisplay -open examples/uniref50.fa", |
345 |
|
" -eps", workingDir + "test_uniref50_out.eps", true, |
346 |
|
MINFILESIZE_BIG, TEST_TIMEOUT }, |
347 |
|
{ "nodisplay -open examples/uniref50.fa", " -eps", |
348 |
|
workingDir + "test_uniref50_out.eps", false, |
349 |
|
MINFILESIZE_BIG, TEST_TIMEOUT }, |
350 |
|
{ "nogui -open examples/uniref50.fa", " -eps", |
351 |
|
workingDir + "test_uniref50_out.eps", true, MINFILESIZE_BIG, |
352 |
|
TEST_TIMEOUT }, |
353 |
|
{ "nogui -open examples/uniref50.fa", " -eps", |
354 |
|
workingDir + "test_uniref50_out.eps", false, |
355 |
|
MINFILESIZE_BIG, TEST_TIMEOUT }, |
356 |
|
{ "headless -open examples/uniref50.fa", " -eps", |
357 |
|
workingDir + "test_uniref50_out.eps", true, MINFILESIZE_BIG, |
358 |
|
TEST_TIMEOUT }, |
359 |
|
{ "headless -open examples/uniref50.fa", " -svg", |
360 |
|
workingDir + "test_uniref50_out.svg", false, |
361 |
|
MINFILESIZE_BIG, TEST_TIMEOUT }, |
362 |
|
{ "headless -open examples/uniref50.fa", " -png", |
363 |
|
workingDir + "test_uniref50_out.png", true, MINFILESIZE_BIG, |
364 |
|
TEST_TIMEOUT }, |
365 |
|
{ "headless -open examples/uniref50.fa", " -html", |
366 |
|
workingDir + "test_uniref50_out.html", true, |
367 |
|
MINFILESIZE_BIG, TEST_TIMEOUT }, |
368 |
|
{ "headless -open examples/uniref50.fa", " -fasta", |
369 |
|
workingDir + "test_uniref50_out.mfa", true, MINFILESIZE_SMALL, |
370 |
|
TEST_TIMEOUT }, |
371 |
|
{ "headless -open examples/uniref50.fa", " -clustal", |
372 |
|
workingDir + "test_uniref50_out.aln", true, MINFILESIZE_SMALL, |
373 |
|
TEST_TIMEOUT }, |
374 |
|
{ "headless -open examples/uniref50.fa", " -msf", |
375 |
|
workingDir + "test_uniref50_out.msf", true, MINFILESIZE_SMALL, |
376 |
|
TEST_TIMEOUT }, |
377 |
|
{ "headless -open examples/uniref50.fa", " -pileup", |
378 |
|
workingDir + "test_uniref50_out.aln", true, MINFILESIZE_SMALL, |
379 |
|
TEST_TIMEOUT }, |
380 |
|
{ "headless -open examples/uniref50.fa", " -pir", |
381 |
|
workingDir + "test_uniref50_out.pir", true, MINFILESIZE_SMALL, |
382 |
|
TEST_TIMEOUT }, |
383 |
|
{ "headless -open examples/uniref50.fa", " -pfam", |
384 |
|
workingDir + "test_uniref50_out.pfam", true, MINFILESIZE_SMALL, |
385 |
|
TEST_TIMEOUT }, |
386 |
|
{ "headless -open examples/uniref50.fa", " -blc", |
387 |
|
workingDir + "test_uniref50_out.blc", true, MINFILESIZE_SMALL, |
388 |
|
TEST_TIMEOUT }, |
389 |
|
{ "headless -open examples/uniref50.fa", " -jalview", |
390 |
|
workingDir + "test_uniref50_out.jvp", true, MINFILESIZE_SMALL, |
391 |
|
TEST_TIMEOUT }, }; |
392 |
|
} |
393 |
|
} |