Package org.zeroturnaround.exec

Examples of org.zeroturnaround.exec.ProcessExecutor


    protected long getProcessTimeout() {
        return processTimeout;
    }

    protected ProcessExecutor makePresetProcessExecutor() {
        return new ProcessExecutor()
                .redirectOutput(Slf4jStream.of(logger).asInfo())
                .redirectError(Slf4jStream.of(logger).asInfo())
                .readOutput(true)
                .directory(getBaseFolder())
                .timeout(getProcessTimeout(), TimeUnit.MILLISECONDS)
View Full Code Here


  private ProcessExecutor printArguments(String... args) {
    List<String> command = new ArrayList<String>();
    command.addAll(Arrays.asList("java", "-cp", "target/test-classes", PrintArguments.class.getName()));
    command.addAll(Arrays.asList(args));
    return new ProcessExecutor(command).readOutput(true);
  }
View Full Code Here

    String output = argumentsAsList("arg1 arg2  arg3").readOutput(true).execute().outputUTF8();
    Assert.assertEquals("[arg1, arg2, arg3]", output);
  }

  private ProcessExecutor argumentsAsList(String args) {
    return new ProcessExecutor().commandSplit("java -cp target/test-classes " + ArgumentsAsList.class.getName() + " " + args);
  }
View Full Code Here

    String str = "Tere Minu Uus vihik";
    ByteArrayInputStream bais = new ByteArrayInputStream(str.getBytes());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PumpStreamHandler handler = new PumpStreamHandler(baos, System.err, bais);

    ProcessExecutor exec = new ProcessExecutor("java", "-cp", "target/test-classes",
        PrintInputToOutput.class.getName()).readOutput(true);
    exec.streams(handler);

    String result = exec.execute().outputUTF8();
    Assert.assertEquals(str, result);
  }
View Full Code Here

  public void testPumpFromInputToOutputWithInput() throws Exception {
    String str = "Tere Minu Uus vihik";
    ByteArrayInputStream bais = new ByteArrayInputStream(str.getBytes());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    ProcessExecutor exec = new ProcessExecutor("java", "-cp", "target/test-classes",
        PrintInputToOutput.class.getName()).readOutput(true).redirectInput(bais);

    String result = exec.execute().outputUTF8();
    Assert.assertEquals(str, result);
  }
View Full Code Here

    Assert.assertEquals("world!", new String(out.toByteArray()));
    Assert.assertFalse(close.isClosed());
  }

  private ProcessExecutor helloWorld() {
    return new ProcessExecutor("java", "-cp", "target/test-classes", HelloWorld.class.getName());
  }
View Full Code Here

  @Test
  public void testExecuteTimeout() throws Exception {
    try {
      // Use timeout in case we get stuck
      List<String> args = getWriterLoopCommand();
      new ProcessExecutor().command(args).timeout(1, TimeUnit.SECONDS).execute();
      Assert.fail("TimeoutException expected.");
    }
    catch (TimeoutException e) {
      Assert.assertThat(e.getMessage(), CoreMatchers.containsString("1 second"));
      Assert.assertThat(e.getMessage(), CoreMatchers.containsString(Loop.class.getName()));
View Full Code Here

  @Test
  public void testStartTimeout() throws Exception {
    try {
      // Use timeout in case we get stuck
      List<String> args = getWriterLoopCommand();
      new ProcessExecutor().command(args).start().getFuture().get(1, TimeUnit.SECONDS);
      Assert.fail("TimeoutException expected.");
    }
    catch (TimeoutException e) {
      Assert.assertNull(e.getMessage());
    }
View Full Code Here

    String fullName = getClass().getName();
    testSlf4jLoggerName(fullName, Slf4jStream.ofCaller());
  }

  private void testSlf4jLoggerName(String fullName, Slf4jStream stream) {
    ProcessExecutor executor = new ProcessExecutor();
    executor.redirectOutput(stream.asInfo());
    PumpStreamHandler pumps = executor.pumps();
    OutputStream out = pumps.getOut();
    Assert.assertTrue("Slf4jInfoOutputStream expected", out instanceof Slf4jInfoOutputStream);
    Assert.assertEquals(fullName, ((Slf4jInfoOutputStream) out).getLogger().getName());
  }
View Full Code Here

    Assert.assertEquals("Hello ", new String(out.toByteArray()));
    Assert.assertEquals("world!", new String(err.toByteArray()));
  }

  private ProcessExecutor helloWorld() {
    return new ProcessExecutor("java", "-cp", "target/test-classes", HelloWorld.class.getName());
  }
View Full Code Here

TOP

Related Classes of org.zeroturnaround.exec.ProcessExecutor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.