Package test.shell.base

Examples of test.shell.base.BaseProcessContext


      protected void execute(TestPluginLifeCycle lifeCycle, Wiser wiser) throws IOException, MessagingException, ExecutionException, InterruptedException {
        Shell shell = lifeCycle.createShell();
        lifeCycle.bindClass("produce", Commands.ProduceValue.class);
        lifeCycle.bindClass("consume", Commands.ConsumeObject.class);
        Commands.list.clear();
        BaseProcessContext process = BaseProcessContext.create(shell, "produce | mail send -s the_subject -b admin@gmail.com | consume").execute();
        ShellResponse.Ok ok = assertInstance(ShellResponse.Ok.class, process.getResponse());
        Assert.assertEquals(1, wiser.getMessages().size());
        WiserMessage msg = wiser.getMessages().get(0);
        Assert.assertEquals("foo@gmail.com", msg.getEnvelopeSender());
        Assert.assertEquals("admin@gmail.com", msg.getEnvelopeReceiver());
        Assert.assertEquals("the_subject", msg.getMimeMessage().getSubject());
View Full Code Here


    ShellFactory factory = bootstrap.getContext().getPlugin(ShellFactory.class);
    Shell shell = factory.create(null);
    assertNotNull(shell);
    ShellProcess process = shell.createProcess("foo_cmd");
    assertNotNull(process);
    BaseProcessContext pc = BaseProcessContext.create(process).execute();
    assertTrue(pc.getResponse() instanceof ShellResponse.Ok);
    String r = pc.getOutput();
    assertEquals("bar", r);
  }
View Full Code Here

  protected final CompletionMatch assertComplete(String prefix) {
    return shell.complete(prefix);
  }

  protected final String assertOk(String s) {
    BaseProcessContext ctx = execute(s);
    ShellResponse resp = ctx.getResponse();
    if (resp instanceof ShellResponse.Ok) {
      return ctx.getOutput();
    }
    else if (resp instanceof ShellResponse.Error) {
      ShellResponse.Error err = (ShellResponse.Error)resp;
      AssertionFailedError afe = new AssertionFailedError();
      afe.initCause(err.getThrowable());
View Full Code Here

      throw new AssertionFailedError("Was expecting an ok response instead of " + resp);
    }
  }

  protected final <R extends ShellResponse> R assertResponse(Class<R> expectedResponse, String s) {
    BaseProcessContext ctx = execute(s);
    ShellResponse resp = ctx.getResponse();
    if (expectedResponse.isInstance(resp)) {
      return expectedResponse.cast(resp);
    }
    else if (resp instanceof ShellResponse.Error) {
      ShellResponse.Error err = (ShellResponse.Error)resp;
View Full Code Here

  private void doTest(String command) {
    interruptDoCancel = false;
    interruptInterrupted = false;

    //
    final BaseProcessContext ctx = create(command);
    final AtomicReference<Boolean> interrupted = new AtomicReference<Boolean>();
    Thread t = new Thread() {
      @Override
      public void run() {
        try {
          ctx.execute();
        }
        finally {
          interrupted.set(isInterrupted());
        }
      }
    };
    t.start();

    //
    synchronized (interrupLock) {
      if (!interruptDoCancel) {
        try {
          interrupLock.wait(10 * 1000);
        }
        catch (InterruptedException e) {
          throw AbstractTestCase.failure(e);
        }
      }
    }

    // We should have been interrupted
    assertTrue(interruptDoCancel);

    //
    ctx.cancel();
    ShellResponse resp = ctx.getResponse();
    assertEquals(ShellResponse.Cancelled.class, resp.getClass());
    assertTrue(interruptInterrupted);
    while (true) {
      Boolean b = interrupted.get();
      if (b != null) {
View Full Code Here

      }
    }
  }

  public void testLoop() throws Exception {
    final BaseProcessContext ctx = create("invoke " + CancellationTestCase.class.getName() + " loopCallback");
    Thread t = new Thread() {
      @Override
      public void run() {
        ctx.execute();
      }
    };

    //
    loopLatch1 = new CountDownLatch(1);
    loopLatch2 = true;
    loopInterrupted = null;
    t.start();

    //
    loopLatch1.await();
    ctx.cancel();
    loopLatch2 = false;

    //
    ShellResponse resp = ctx.getResponse();
    assertEquals(ShellResponse.Cancelled.class, resp.getClass());
    assertEquals(Boolean.TRUE, loopInterrupted);
  }
View Full Code Here

    //
    ServerAutomaton server = new ServerAutomaton(serverOOS, serverOIS);

    ShellProcess process = server.createProcess("hello");
    BaseProcessContext context = BaseProcessContext.create(process);
    context.execute();
    assertInstance(ShellResponse.Ok.class, context.getResponse());
    assertEquals("juu", context.getOutput());

    //
    t.interrupt();
    assertJoin(t);
  }
View Full Code Here

    //
    ServerAutomaton server = new ServerAutomaton(serverOOS, serverOIS);

    ShellProcess process = server.createProcess("hello");
    BaseProcessContext context = BaseProcessContext.create(process);
    context.execute();
    ShellResponse response = context.getResponse();
    assertInstance(ShellResponse.Close.class, response);

    //
    assertJoin(t);
  }
View Full Code Here

    t.start();

    //
    ServerAutomaton server = new ServerAutomaton(serverOOS, serverOIS);
    ShellProcess process = server.createProcess("hello");
    final BaseProcessContext context = BaseProcessContext.create(process);

    //
    final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
    Thread u = new Thread() {
      @Override
      public void run() {
        context.execute();
        ShellResponse response = context.getResponse();
        assertInstance(ShellResponse.Cancelled.class, response);
      }
    };
    u.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
      public void uncaughtException(Thread t, Throwable e) {
View Full Code Here

    //
    Shell asyncShell = new AsyncShell(Executors.newSingleThreadExecutor(), shell);

    //
    BaseProcessContext ctx = BaseProcessContext.create(asyncShell, "foo");
    ctx.addLineInput("juu");
    ctx.execute();

    //
    ShellResponse resp = ctx.getResponse();

    //
    assertInstance(ShellResponse.Ok.class, resp);
    assertEquals("barjuu", ctx.getOutput());
    ctx.assertNoInput();
  }
View Full Code Here

TOP

Related Classes of test.shell.base.BaseProcessContext

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.