コード例 #1
0
ファイル: ProxyUtilTest.java プロジェクト: DenMette/vestige
 /**
  * *********************************************************************** Test parsing method.
  * **********************************************************************
  */
 @Test
 public void testParseProxySettings2() {
   FixedProxySelector rs =
       ProxyUtil.parseProxySettings("http://http_proxy.unit-test.invalid:8080/");
   List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI);
   assertEquals("HTTP @ http_proxy.unit-test.invalid:8080", psList.get(0).toString());
 }
コード例 #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();
  }
コード例 #3
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));
    }
  }
コード例 #4
0
 /**
  * Determine whether the given object (which can be a Javassist proxy) inherits from the given
  * class. This allows us to detect inheritance without having to do instanceof, which requires
  * that the class be present at compile time.
  */
 public static boolean objectInheritsFrom(Object object, String clsName) {
   Class<?> cls = ProxyUtil.getNonProxyClass(object);
   while (!"java.lang.Object".equals(cls.getName())) {
     if (clsName.equals(cls.getName())) return true;
     cls = cls.getSuperclass();
   }
   return false;
 }
コード例 #5
0
ファイル: NetUtil.java プロジェクト: 1eksus/migool
 public static String getPage(String url, String proxy) {
   try {
     ProxyUtil.Proxy p = ProxyUtil.parse(proxy);
     return getPage(
         new URL(url),
         new Proxy(Proxy.Type.HTTP, new InetSocketAddress(p.getHost(), p.getPort())));
   } catch (Exception e) {
     return null;
   }
 }
コード例 #6
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));
    }
  }
コード例 #7
0
ファイル: ProxyUtilTest.java プロジェクト: DenMette/vestige
 /**
  * *********************************************************************** Test parsing method.
  * **********************************************************************
  */
 @Test
 public void testParseProxySettings5() {
   FixedProxySelector rs = ProxyUtil.parseProxySettings("192.123.123.1:8080");
   List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI);
   assertEquals("HTTP @ 192.123.123.1:8080", psList.get(0).toString());
 }