Ejemplo n.º 1
0
  @Test
  public void testUnknownException() throws Throwable {

    // create client service
    Service clientService =
        ProxyUtil.createClientProxy(
            cl, Service.class, false, jsonRpcClient, clientInputStream, clientOutputStream);

    jsonRpcServer.setErrorResolver(AnnotationsErrorResolver.INSTANCE);

    mockCtx.checking(
        new Expectations() {
          {
            one(serviceMock).unresolvedExceptionThrown();
            will(throwException(new IllegalArgumentException("testing")));
            one(serviceMock).undelcaredExceptionThrown();
            will(throwException(new IllegalArgumentException("testing")));
          }
        });

    try {
      clientService.unresolvedExceptionThrown();
      fail("Expecting exception");
    } catch (Throwable t) {
      assertTrue(JsonRpcClientException.class.isInstance(t));
    }

    try {
      clientService.undelcaredExceptionThrown();
      fail("Expecting exception");
    } catch (Throwable t) {
      assertTrue(JsonRpcClientException.class.isInstance(t));
    }
  }
Ejemplo n.º 2
0
  @Test
  public void testAllMethods() throws Throwable {

    // create client service
    Service clientService =
        ProxyUtil.createClientProxy(
            cl, Service.class, false, jsonRpcClient, clientInputStream, clientOutputStream);

    mockCtx.checking(
        new Expectations() {
          {
            one(serviceMock).noOp();
            one(serviceMock).hello();
            will(returnValue("world"));
            one(serviceMock).hello(with("uranus"));
            will(returnValue("uranus"));
          }
        });

    // call it
    clientService.noOp();
    assertEquals("world", clientService.hello());
    assertEquals("uranus", clientService.hello("uranus"));

    // call non-rpc methods
    assertNotNull(clientService.toString());
    assertTrue(clientService.equals(clientService));
    assertFalse(clientService.equals(null));
    clientService.hashCode();
  }
Ejemplo n.º 3
0
  @Test
  public void testException() throws Throwable {

    // create client service
    Service clientService =
        ProxyUtil.createClientProxy(
            cl, Service.class, false, jsonRpcClient, clientInputStream, clientOutputStream);

    mockCtx.checking(
        new Expectations() {
          {
            one(serviceMock).noOp();
            will(throwException(new TestException("testing")));
            one(serviceMock).hello();
            will(throwException(new TestException(null)));
            one(serviceMock).hello(with("uranus"));
            will(throwException(new TestException2()));
          }
        });

    try {
      clientService.noOp();
      fail("Expecting exception");
    } catch (Throwable t) {
      assertEquals("testing", t.getMessage());
      assertTrue(TestException.class.isInstance(t));
    }

    try {
      clientService.hello();
      fail("Expecting exception");
    } catch (Throwable t) {
      assertNull(t.getMessage());
      assertTrue(TestException.class.isInstance(t));
    }

    try {
      clientService.hello("uranus");
      fail("Expecting exception");
    } catch (Throwable t) {
      assertTrue(TestException2.class.isInstance(t));
    }
  }