X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fbin%2FCommandLineOperations.java;h=ec0b160094cdc65a0c35d1bdfa9791245fa87d25;hb=c75ae0da287834282173560815959c4b4e7e6b2d;hp=40263c3e81ec1564a33752a4cfb1ad8c9af4ad12;hpb=47168f025aefdaa044802bd5f8f510ffe43a4808;p=jalview.git diff --git a/test/jalview/bin/CommandLineOperations.java b/test/jalview/bin/CommandLineOperations.java index 40263c3..ec0b160 100644 --- a/test/jalview/bin/CommandLineOperations.java +++ b/test/jalview/bin/CommandLineOperations.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -43,30 +43,46 @@ public class CommandLineOperations public static void tearDownAfterClass() throws Exception { } -/*** - * from http://stackoverflow.com/questions/808276/how-to-add-a-timeout-value-when-using-javas-runtime-exec - * @author jimp - * - */ -private static class Worker extends Thread { - private final Process process; - private Integer exit; - private Worker(Process process) { - this.process = process; - } - public void run() { - try { - exit = process.waitFor(); - } catch (InterruptedException ignore) { - return; + + /*** + * from + * http://stackoverflow.com/questions/808276/how-to-add-a-timeout-value-when + * -using-javas-runtime-exec + * + * @author jimp + * + */ + private static class Worker extends Thread + { + private final Process process; + + private Integer exit; + + private Worker(Process process) + { + this.process = process; + } + + public void run() + { + try + { + exit = process.waitFor(); + } catch (InterruptedException ignore) + { + return; + } } } -} -private Worker jalviewDesktopRunner(boolean withAwt, String cmd, int timeout) throws InterruptedException, IOException + + private Worker jalviewDesktopRunner(boolean withAwt, String cmd, + int timeout) throws InterruptedException, IOException { - String _cmd = "java "+(withAwt ? "-Djava.awt.headless=true":"")+" -Djava.ext.dirs=./lib -classpath ./classes jalview.bin.Jalview "; - System.out.println("###############Jalview CMD: " + _cmd+cmd); - Process ls2_proc = Runtime.getRuntime().exec(_cmd+cmd); + String _cmd = "java " + + (withAwt ? "-Djava.awt.headless=true" : "") + + " -Djava.ext.dirs=./lib -classpath ./classes jalview.bin.Jalview "; + System.out.println("###############Jalview CMD: " + _cmd + cmd); + Process ls2_proc = Runtime.getRuntime().exec(_cmd + cmd); BufferedReader outputReader = new BufferedReader(new InputStreamReader( ls2_proc.getInputStream())); @@ -89,52 +105,66 @@ private Worker jalviewDesktopRunner(boolean withAwt, String cmd, int timeout) th } return worker; } + @Test public void testHeadlessModeEPS() throws Exception { - String[] headlessArgs=new String[] { "nodisplay","headless","nogui"}; - for (String _harg:headlessArgs) + String[] headlessArgs = new String[] + { "nodisplay", "headless", "nogui" }; + for (String _harg : headlessArgs) { - boolean _switch=false,withAwt=false; - do { + boolean _switch = false, withAwt = false; + do + { if (_switch) { - withAwt=true; + withAwt = true; + } + _switch = true; + String jalview_input = "examples/uniref50.fa"; + String jalview_output = "test_uniref50_out.eps"; + String cmd = "" + _harg + " -open " + jalview_input + " -eps " + + jalview_output; + String harg = _harg + + (withAwt ? "-Djava.awt.headless=true" + : " NO AWT.HEADLESS"); + System.out.println("Testing with Headless argument: '" + harg + + "'\n"); + Worker worker = jalviewDesktopRunner(withAwt, cmd, 9000); + assertTrue("Didn't create an output EPS file.[" + harg + "]", + new File("test_uniref50_out.eps").exists()); + assertTrue("Didn't create an EPS file with any content[" + harg + + "]", new File("test_uniref50_out.eps").length() > 4096); + if (worker.exit == null) + { + worker.interrupt(); + Thread.currentThread().interrupt(); + worker.process.destroy(); + fail("Jalview did not exit after EPS generation (try running test again to verify - timeout at 9000ms). [" + + harg + "]"); } - _switch=true; - String jalview_input = "examples/uniref50.fa"; - String jalview_output = "test_uniref50_out.eps"; - String cmd = ""+_harg+" -open "+ jalview_input + " -eps " + jalview_output; - String harg = _harg+(withAwt ? "-Djava.awt.headless=true":" NO AWT.HEADLESS"); - System.out.println("Testing with Headless argument: '"+harg+"'\n"); - Worker worker = jalviewDesktopRunner(withAwt, cmd, 9000); - assertTrue("Didn't create an output EPS file.["+harg+"]", new File("test_uniref50_out.eps").exists()); - assertTrue("Didn't create an EPS file with any content["+harg+"]", new File("test_uniref50_out.eps").length()>4096); - if (worker.exit == null){ - worker.interrupt(); - Thread.currentThread().interrupt(); - worker.process.destroy(); - fail("Jalview did not exit after EPS generation (try running test again to verify - timeout at 9000ms). ["+harg+"]"); + } while (!withAwt); } - } while (!withAwt); - } } -// @Test -// public void testJalview2XMLDataset() throws Exception -// { -// String jalview_input = "examples/uniref50.fa"; -// String jalview_output = "test_uniref50_out.eps"; -// String cmd = ""+" -open "+ jalview_input + " -eps " + jalview_output; -// //String harg = _harg+(withAwt ? "-Djava.awt.headless=true":" NO AWT.HEADLESS"); -// System.out.println("Testing with Headless argument: '"+harg+"'\n"); -// Worker worker = jalviewDesktopRunner(withAwt, cmd, 9000); -// assertTrue("Didn't create an output EPS file.["+harg+"]", new File("test_uniref50_out.eps").exists()); -// assertTrue("Didn't create an EPS file with any content["+harg+"]", new File("test_uniref50_out.eps").length()>4096); -// if (worker.exit == null){ -// worker.interrupt(); -// Thread.currentThread().interrupt(); -// worker.process.destroy(); -// fail("Jalview did not exit after EPS generation (try running test again to verify - timeout at 9000ms). ["+harg+"]"); -// } -// } + // @Test + // public void testJalview2XMLDataset() throws Exception + // { + // String jalview_input = "examples/uniref50.fa"; + // String jalview_output = "test_uniref50_out.eps"; + // String cmd = ""+" -open "+ jalview_input + " -eps " + jalview_output; + // //String harg = _harg+(withAwt ? + // "-Djava.awt.headless=true":" NO AWT.HEADLESS"); + // System.out.println("Testing with Headless argument: '"+harg+"'\n"); + // Worker worker = jalviewDesktopRunner(withAwt, cmd, 9000); + // assertTrue("Didn't create an output EPS file.["+harg+"]", new + // File("test_uniref50_out.eps").exists()); + // assertTrue("Didn't create an EPS file with any content["+harg+"]", new + // File("test_uniref50_out.eps").length()>4096); + // if (worker.exit == null){ + // worker.interrupt(); + // Thread.currentThread().interrupt(); + // worker.process.destroy(); + // fail("Jalview did not exit after EPS generation (try running test again to verify - timeout at 9000ms). ["+harg+"]"); + // } + // } }