2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 import static org.junit.Assert.*;
23 import java.io.BufferedReader;
25 import java.io.IOException;
26 import java.io.InputStreamReader;
28 import org.junit.AfterClass;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
32 public class CommandLineOperations
36 public static void setUpBeforeClass() throws Exception
41 public static void tearDownAfterClass() throws Exception
45 * from http://stackoverflow.com/questions/808276/how-to-add-a-timeout-value-when-using-javas-runtime-exec
49 private static class Worker extends Thread {
50 private final Process process;
52 private Worker(Process process) {
53 this.process = process;
57 exit = process.waitFor();
58 } catch (InterruptedException ignore) {
63 private Worker jalviewDesktopRunner(boolean withAwt, String cmd, int timeout) throws InterruptedException, IOException
65 String _cmd = "java "+(withAwt ? "-Djava.awt.headless=true":"")+" -Djava.ext.dirs=./lib -classpath ./classes jalview.bin.Jalview ";
66 System.out.println("###############Jalview CMD: " + _cmd+cmd);
67 Process ls2_proc = Runtime.getRuntime().exec(_cmd+cmd);
68 BufferedReader outputReader = new BufferedReader(new InputStreamReader(
69 ls2_proc.getInputStream()));
71 BufferedReader errorReader = new BufferedReader(new InputStreamReader(
72 ls2_proc.getErrorStream()));
73 Worker worker = new Worker(ls2_proc);
76 System.out.println("Output: ");
78 while ((ln = outputReader.readLine()) != null)
80 System.out.println(ln);
83 System.out.println("Error: ");
84 while ((ln = errorReader.readLine()) != null)
86 System.out.println(ln);
91 public void testHeadlessModeEPS() throws Exception
93 String[] headlessArgs=new String[] { "nodisplay","headless","nogui"};
94 for (String _harg:headlessArgs)
96 boolean _switch=false,withAwt=false;
103 String jalview_input = "examples/uniref50.fa";
104 String jalview_output = "test_uniref50_out.eps";
105 String cmd = ""+_harg+" -open "+ jalview_input + " -eps " + jalview_output;
106 String harg = _harg+(withAwt ? "-Djava.awt.headless=true":" NO AWT.HEADLESS");
107 System.out.println("Testing with Headless argument: '"+harg+"'\n");
108 Worker worker = jalviewDesktopRunner(withAwt, cmd, 9000);
109 assertTrue("Didn't create an output EPS file.["+harg+"]", new File("test_uniref50_out.eps").exists());
110 assertTrue("Didn't create an EPS file with any content["+harg+"]", new File("test_uniref50_out.eps").length()>4096);
111 if (worker.exit == null){
113 Thread.currentThread().interrupt();
114 worker.process.destroy();
115 fail("Jalview did not exit after EPS generation (try running test again to verify - timeout at 9000ms). ["+harg+"]");
121 // public void testJalview2XMLDataset() throws Exception
123 // String jalview_input = "examples/uniref50.fa";
124 // String jalview_output = "test_uniref50_out.eps";
125 // String cmd = ""+" -open "+ jalview_input + " -eps " + jalview_output;
126 // //String harg = _harg+(withAwt ? "-Djava.awt.headless=true":" NO AWT.HEADLESS");
127 // System.out.println("Testing with Headless argument: '"+harg+"'\n");
128 // Worker worker = jalviewDesktopRunner(withAwt, cmd, 9000);
129 // assertTrue("Didn't create an output EPS file.["+harg+"]", new File("test_uniref50_out.eps").exists());
130 // assertTrue("Didn't create an EPS file with any content["+harg+"]", new File("test_uniref50_out.eps").length()>4096);
131 // if (worker.exit == null){
132 // worker.interrupt();
133 // Thread.currentThread().interrupt();
134 // worker.process.destroy();
135 // fail("Jalview did not exit after EPS generation (try running test again to verify - timeout at 9000ms). ["+harg+"]");