@Test public void testNoArgumentClass() throws Exception { JSONObject rpc = new JSONObject("{ method : test.noArg }"); RpcHandler handler = registry.getRpcHandler(rpc); Future<?> future = handler.execute(null, null, converter); assertEquals(TestHandler.NO_ARG_RESPONSE, future.get()); }
@Test public void testRpcWithInputClassThatIsntRequestItem() throws Exception { JSONObject rpc = new JSONObject("{ method : test.echo, params: {value: 'Bob' }}"); RpcHandler handler = registry.getRpcHandler(rpc); Future<?> future = handler.execute(null, null, converter); assertEquals(future.get(), TestHandler.ECHO_PREFIX + "Bob"); }
@Test public void testNoArgumentClass() throws Exception { JSONObject rpc = new JSONObject("{ method : test.noArg }"); RpcHandler handler = registry.getRpcHandler(rpc); Future<?> future = handler.execute(null, null, converter); assertEquals(TestHandler.NO_ARG_RESPONSE, future.get()); }
@Test public void testNoArgumentClass() throws Exception { JSONObject rpc = new JSONObject("{ method : test.noArg }"); RpcHandler handler = registry.getRpcHandler(rpc); Future<?> future = handler.execute(null, null, converter); assertEquals(TestHandler.NO_ARG_RESPONSE, future.get()); }
@Test public void testRpcWithInputClassThatIsntRequestItem() throws Exception { JSONObject rpc = new JSONObject("{ method : test.echo, params: {value: 'Bob' }}"); RpcHandler handler = registry.getRpcHandler(rpc); Future<?> future = handler.execute(null, null, converter); assertEquals(future.get(), TestHandler.ECHO_PREFIX + "Bob"); }
@Test public void testNoArgumentClass() throws Exception { JSONObject rpc = new JSONObject("{ method : test.noArg }"); RpcHandler handler = registry.getRpcHandler(rpc); Future<?> future = handler.execute(null, null, converter); assertEquals(TestHandler.NO_ARG_RESPONSE, future.get()); }
@Test public void testRpcWithInputClassThatIsntRequestItem() throws Exception { JSONObject rpc = new JSONObject("{ method : test.echo, params: {value: 'Bob' }}"); RpcHandler handler = registry.getRpcHandler(rpc); Future<?> future = handler.execute(null, null, converter); assertEquals(future.get(), TestHandler.ECHO_PREFIX + "Bob"); }
@Test public void testRpcWithInputClassThatIsntRequestItem() throws Exception { JSONObject rpc = new JSONObject("{ method : test.echo, params: {value: 'Bob' }}"); RpcHandler handler = registry.getRpcHandler(rpc); Future<?> future = handler.execute(null, null, converter); assertEquals(future.get(), TestHandler.ECHO_PREFIX + "Bob"); }
@Test public void testRpcWithInputClassThatIsntRequestItem() throws Exception { JSONObject rpc = new JSONObject("{ method : test.echo, params: {value: 'Bob' }}"); RpcHandler handler = registry.getRpcHandler(rpc); Future<?> future = handler.execute(null, null, converter); assertEquals(future.get(), TestHandler.ECHO_PREFIX + "Bob"); }
@Test public void testNoArgumentClass() throws Exception { JSONObject rpc = new JSONObject("{ method : test.noArg }"); RpcHandler handler = registry.getRpcHandler(rpc); Future<?> future = handler.execute(null, null, converter); assertEquals(TestHandler.NO_ARG_RESPONSE, future.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 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 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 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 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 testMetadataMultipleGadgets() throws Exception { registerGadgetsHandler(null); JSONObject request = makeMetadataRequest("en", "US", GADGET1_URL, GADGET2_URL); RpcHandler operation = registry.getRpcHandler(request); Object responseObj = operation.execute(emptyFormItems, token, converter).get(); JSONObject response = new JSONObject(converter.convertToString(responseObj)); JSONObject modulePrefs1 = response.getJSONObject(GADGET1_URL).getJSONObject("modulePrefs"); assertEquals(FakeProcessor.SPEC_TITLE, modulePrefs1.getString("title")); JSONObject modulePrefs2 = response.getJSONObject(GADGET2_URL).getJSONObject("modulePrefs"); assertEquals(FakeProcessor.SPEC_TITLE2, modulePrefs2.getString("title")); }
@Test public void testMetadataInvalidUrl() throws Exception { registerGadgetsHandler(null); String badUrl = "[moo]"; JSONObject request = makeMetadataRequest(null, null, null, badUrl); RpcHandler operation = registry.getRpcHandler(request); Object responseObj = operation.execute(emptyFormItems, authContext, converter).get(); JSONObject response = new JSONObject(converter.convertToString(responseObj)); JSONObject gadget = response.getJSONObject(badUrl); assertEquals("Bad url - " + badUrl, gadget.getJSONObject("error").getString("message")); assertEquals(400, gadget.getJSONObject("error").getInt("code")); }