Source:
public void testLaunchCliApp() throws Throwable { ProcessBuilder pb = new ProcessBuilder(); pb.environment().remove("BROOKLYN_HOME"); pb.environment().put("BROOKLYN_CLASSPATH", BROOKLYN_CLASSPATH); pb.command(BROOKLYN_BIN_PATH, "--verbose", "launch", "--stopOnKeyPress", "--app", "brooklyn.cli.CliTest$ExampleApp", "--location", "localhost", "--noConsole"); final Process brooklyn = pb.start(); Callable<Void> cli = new Callable<Void>() { @Override public Void call() throws Exception { String consoleOutput = convertStreamToString(brooklyn.getInputStream()); String consoleError = convertStreamToString(brooklyn.getErrorStream()); assertTrue(consoleOutput.contains("Launching Brooklyn web console management"), "Launch message not output"); assertFalse(consoleOutput.contains("Initiating Jersey application"), "Web console started"); assertTrue(consoleOutput.contains("Started application ExampleApp"), "ExampleApp not started"); assertTrue(consoleOutput.contains("Server started. Press return to stop."), "Server started message not output"); assertTrue(consoleError.isEmpty()); return null; } }; try { Future<Void> future = executor.submit(cli); Thread.sleep(15000L); OutputStream out = brooklyn.getOutputStream(); out.write('\n'); out.flush(); future.get(10, TimeUnit.SECONDS); assertEquals(brooklyn.exitValue(), 0, "Command terminated with error status"); } catch (TimeoutException te) { fail("Timed out waiting for process to complete"); } catch (ExecutionException ee) { throw ee.getCause(); } finally { brooklyn.destroy(); } }

Target:
public void testLaunchCliApp() throws Throwable { ProcessBuilder pb = new ProcessBuilder(); pb.environment().remove("BROOKLYN_HOME"); pb.environment().put("BROOKLYN_CLASSPATH", BROOKLYN_CLASSPATH); pb.command(BROOKLYN_BIN_PATH, "--verbose", "launch", "--stopOnKeyPress", "--app", "brooklyn.cli.CliTest$ExampleApp", "--location", "localhost", "--noConsole"); final Process brooklyn = pb.start(); Callable<Void> cli = new Callable<Void>() { @Override public Void call() throws Exception { String consoleOutput = convertStreamToString(brooklyn.getInputStream()); String consoleError = convertStreamToString(brooklyn.getErrorStream()); assertTrue(consoleOutput.contains("Launching Brooklyn web console management"), "Launch message not output; output=" + consoleOutput); assertFalse(consoleOutput.contains("Initiating Jersey application"), "Web console started; output=" + consoleOutput); assertTrue(consoleOutput.contains("Started application ExampleApp"), "ExampleApp not started; output=" + consoleOutput); assertTrue(consoleOutput.contains("Server started. Press return to stop."), "Server started message not output; output=" + consoleOutput); assertTrue(consoleError.isEmpty(), "Output present; error=" + consoleError); return null; } }; try { Future<Void> future = executor.submit(cli); Thread.sleep(15000L); OutputStream out = brooklyn.getOutputStream(); out.write('\n'); out.flush(); future.get(10, TimeUnit.SECONDS); assertEquals(brooklyn.exitValue(), 0, "Command terminated with error status"); } catch (TimeoutException te) { fail("Timed out waiting for process to complete"); } catch (ExecutionException ee) { throw ee.getCause(); } finally { brooklyn.destroy(); } }