@Test public void testRestPath() { DefaultHandlerRegistry.RestPath restPath = new DefaultHandlerRegistry.RestPath("/service/const1/{p1}/{p2}+/const2/{p3}", null); DefaultHandlerRegistry.RestInvocationWrapper wrapper = restPath.accept("service/const1/a/b,c/const2/d".split("/")); assertArrayEquals(wrapper.pathParams.get("p1"), new String[]{"a"}); assertArrayEquals(wrapper.pathParams.get("p2"), new String[]{"b","c"}); assertArrayEquals(wrapper.pathParams.get("p3"), new String[]{"d"}); wrapper = restPath.accept("service/const1/a/b/const2".split("/")); assertArrayEquals(wrapper.pathParams.get("p1"), new String[]{"a"}); assertArrayEquals(wrapper.pathParams.get("p2"), new String[]{"b"}); assertNull(wrapper.pathParams.get("p3")); assertNull(restPath.accept("service/const1/{p1}/{p2}+".split("/"))); assertNull(restPath.accept("service/constmiss/{p1}/{p2}+/const2".split("/"))); }
@Test public void testSupportedRpcServices() throws Exception { assertEquals(registry.getSupportedRpcServices(), Sets.newHashSet("test.create", "test.get", "test.overridden", "test.exception", "test.futureException", "test.override.rpcname", "test.echo", "test.noArg")); }
@Test public void testGetHandlerRPC() throws Exception { assertNotNull(registry.getRpcHandler(new JSONObject("{method : test.get}"))); }
@Test public void testFutureException() throws Exception { // Test calling a handler method which does not return a future JSONObject rpc = new JSONObject("{ method : test.futureException }"); RpcHandler handler = registry.getRpcHandler(rpc); Future<?> future = handler.execute(null, null, null); try { future.get(); fail("Service method did not produce ExecutionException from Future"); } catch (ExecutionException ee) { assertSame(ee.getCause().getClass(), ProtocolException.class); } }
@Test public void testNonFutureException() throws Exception { // Test calling a handler method which does not return a future JSONObject rpc = new JSONObject("{ method : test.exception }"); RpcHandler handler = registry.getRpcHandler(rpc); Future<?> future = handler.execute(null, null, null); try { future.get(); fail("Service method did not produce NullPointerException from Future"); } catch (ExecutionException ee) { assertSame(ee.getCause().getClass(), NullPointerException.class); } }
@Test public void testFutureException() throws Exception { // Test calling a handler method which does not return a future JSONObject rpc = new JSONObject("{ method : test.futureException }"); RpcHandler handler = registry.getRpcHandler(rpc); Future<?> future = handler.execute(null, null, null); try { future.get(); fail("Service method did not produce ExecutionException from Future"); } catch (ExecutionException ee) { assertSame(ee.getCause().getClass(), ProtocolException.class); } }
@Test public void testSupportedRpcServices() throws Exception { assertEquals(registry.getSupportedRpcServices(), Sets.newHashSet("test.create", "test.get", "test.overridden", "test.exception", "test.futureException", "test.override.rpcname", "test.echo", "test.noArg")); }
@Test public void testOverrideHandlerRPC() throws Exception { assertNotNull(registry.getRpcHandler(new JSONObject("{method : test.overidden}"))); }
@Test public void testRestPath() { DefaultHandlerRegistry.RestPath restPath = new DefaultHandlerRegistry.RestPath("/service/const1/{p1}/{p2}+/const2/{p3}", null); DefaultHandlerRegistry.RestInvocationWrapper wrapper = restPath.accept("service/const1/a/b,c/const2/d".split("/")); assertArrayEquals(wrapper.pathParams.get("p1"), new String[]{"a"}); assertArrayEquals(wrapper.pathParams.get("p2"), new String[]{"b","c"}); assertArrayEquals(wrapper.pathParams.get("p3"), new String[]{"d"}); wrapper = restPath.accept("service/const1/a/b/const2".split("/")); assertArrayEquals(wrapper.pathParams.get("p1"), new String[]{"a"}); assertArrayEquals(wrapper.pathParams.get("p2"), new String[]{"b"}); assertNull(wrapper.pathParams.get("p3")); assertNull(restPath.accept("service/const1/{p1}/{p2}+".split("/"))); assertNull(restPath.accept("service/constmiss/{p1}/{p2}+/const2".split("/"))); }
@Test public void testNonFutureException() throws Exception { // Test calling a handler method which does not return a future JSONObject rpc = new JSONObject("{ method : test.exception }"); RpcHandler handler = registry.getRpcHandler(rpc); Future<?> future = handler.execute(null, null, null); try { future.get(); fail("Service method did not produce NullPointerException from Future"); } catch (ExecutionException ee) { assertSame(ee.getCause().getClass(), NullPointerException.class); } }
@Test public void testSupportedRestServices() throws Exception { assertEquals(registry.getSupportedRestServices(), Sets.newHashSet("GET /test/{someParam}/{someOtherParam}", "PUT /test/{someParam}/{someOtherParam}", "DELETE /test/{someParam}/{someOtherParam}", "POST /test/{someParam}/{someOtherParam}", "GET /test/overridden/method", "GET /test/echo")); }
@Test public void testOverrideHandlerRPC() throws Exception { assertNotNull(registry.getRpcHandler(new JSONObject("{method : test.overidden}"))); }
@Test public void testRestPath() { DefaultHandlerRegistry.RestPath restPath = new DefaultHandlerRegistry.RestPath("/service/const1/{p1}/{p2}+/const2/{p3}", null); DefaultHandlerRegistry.RestInvocationWrapper wrapper = restPath.accept("service/const1/a/b,c/const2/d".split("/")); assertArrayEquals(wrapper.pathParams.get("p1"), new String[]{"a"}); assertArrayEquals(wrapper.pathParams.get("p2"), new String[]{"b","c"}); assertArrayEquals(wrapper.pathParams.get("p3"), new String[]{"d"}); wrapper = restPath.accept("service/const1/a/b/const2".split("/")); assertArrayEquals(wrapper.pathParams.get("p1"), new String[]{"a"}); assertArrayEquals(wrapper.pathParams.get("p2"), new String[]{"b"}); assertNull(wrapper.pathParams.get("p3")); assertNull(restPath.accept("service/const1/{p1}/{p2}+".split("/"))); assertNull(restPath.accept("service/constmiss/{p1}/{p2}+/const2".split("/"))); }
@Test public void testFutureException() throws Exception { // Test calling a handler method which does not return a future JSONObject rpc = new JSONObject("{ method : test.futureException }"); RpcHandler handler = registry.getRpcHandler(rpc); Future<?> future = handler.execute(null, null, null); try { future.get(); fail("Service method did not produce ExecutionException from Future"); } catch (ExecutionException ee) { assertSame(ee.getCause().getClass(), ProtocolException.class); } }
@Test public void testSupportedRpcServices() throws Exception { assertEquals(registry.getSupportedRpcServices(), Sets.newHashSet("test.create", "test.get", "test.overridden", "test.exception", "test.futureException", "test.override.rpcname", "test.echo", "test.noArg")); }
@Test public void testGetHandlerRPC() throws Exception { assertNotNull(registry.getRpcHandler(new JSONObject("{method : test.get}"))); }
@Test public void testRestPath() { DefaultHandlerRegistry.RestPath restPath = new DefaultHandlerRegistry.RestPath("/service/const1/{p1}/{p2}+/const2/{p3}", null); DefaultHandlerRegistry.RestInvocationWrapper wrapper = restPath.accept("service/const1/a/b,c/const2/d".split("/")); assertArrayEquals(wrapper.pathParams.get("p1"), new String[]{"a"}); assertArrayEquals(wrapper.pathParams.get("p2"), new String[]{"b","c"}); assertArrayEquals(wrapper.pathParams.get("p3"), new String[]{"d"}); wrapper = restPath.accept("service/const1/a/b/const2".split("/")); assertArrayEquals(wrapper.pathParams.get("p1"), new String[]{"a"}); assertArrayEquals(wrapper.pathParams.get("p2"), new String[]{"b"}); assertNull(wrapper.pathParams.get("p3")); assertNull(restPath.accept("service/const1/{p1}/{p2}+".split("/"))); assertNull(restPath.accept("service/constmiss/{p1}/{p2}+/const2".split("/"))); }
@Test public void testNonFutureException() throws Exception { // Test calling a handler method which does not return a future JSONObject rpc = new JSONObject("{ method : test.exception }"); RpcHandler handler = registry.getRpcHandler(rpc); Future<?> future = handler.execute(null, null, null); try { future.get(); fail("Service method did not produce NullPointerException from Future"); } catch (ExecutionException ee) { assertSame(ee.getCause().getClass(), NullPointerException.class); } }
@Test public void testSupportedRpcServices() throws Exception { assertEquals(registry.getSupportedRpcServices(), Sets.newHashSet("test.create", "test.get", "test.overridden", "test.exception", "test.futureException", "test.override.rpcname", "test.echo", "test.noArg")); }
@Test public void testOverrideHandlerRPCName() throws Exception { assertNotNull(registry.getRpcHandler(new JSONObject("{method : test.override.rpcname}"))); }