@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 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")); }
@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")); }
@Test public void testMetadataOneGadgetFailure() throws Exception { registerGadgetsHandler(null); JSONObject request = makeMetadataRequest(null, null, GADGET1_URL); urlGenerator.throwRandomFault = true; RpcHandler operation = registry.getRpcHandler(request); Object responseObj = operation.execute(emptyFormItems, token, converter).get(); JSONObject response = new JSONObject(converter.convertToString(responseObj)); JSONObject gadget = response.getJSONObject(GADGET1_URL); assertEquals(GadgetsHandler.FAILURE_METADATA, gadget.getString("error")); }
@Test public void testMetadataNoContainerRequest() throws Exception { registerGadgetsHandler(null); JSONObject request = makeMetadataNoContainerRequest(GADGET1_URL); RpcHandler operation = registry.getRpcHandler(request); try { operation.execute(emptyFormItems, authContext, converter).get(); fail("Missing container"); } catch (Exception e) { assertTrue(e.getMessage().contains("Missing container")); } }
@Test(expected = ExecutionException.class) public void testMetadataInvalidUrl() throws Exception { registerGadgetsHandler(null); JSONObject request = makeMetadataRequest(null, null, "[moo]"); RpcHandler operation = registry.getRpcHandler(request); operation.execute(emptyFormItems, token, converter).get(); }
@Test public void testMetadataNoContainerRequest() throws Exception { registerGadgetsHandler(null); JSONObject request = makeMetadataNoContainerRequest(GADGET1_URL); RpcHandler operation = registry.getRpcHandler(request); try { operation.execute(emptyFormItems, authContext, converter).get(); fail("Missing container"); } catch (Exception e) { assertTrue(e.getMessage().contains("Missing container")); } }
@Test public void testMetadataOneGadgetNoRequestTokenTTLParam() throws Exception { registerGadgetsHandler(null); setupGadgetAdminStore(); setupMockRegistry(Lists.newArrayList("core")); JSONObject request = makeMetadataRequest(null, null, null, GADGET1_URL); RpcHandler operation = registry.getRpcHandler(request); Object responseObj = operation.execute(emptyFormItems, authContext, converter).get(); JSONObject response = new JSONObject(converter.convertToString(responseObj)); assertFalse(response.getJSONObject(FakeProcessor.SPEC_URL.toString()).has("tokenTTL")); }
@Test public void testMetadataEmptyRequest() throws Exception { registerGadgetsHandler(null); JSONObject request = makeMetadataRequest(null, null, null); RpcHandler operation = registry.getRpcHandler(request); Object empty = operation.execute(emptyFormItems, authContext, converter).get(); JsonAssert.assertJsonEquals("{}", converter.convertToString(empty)); }
@Test public void testCajaES53Request() throws Exception { registerGadgetsHandler(null); JSONObject request = makeCajaRequest(null); RpcHandler operation = registry.getRpcHandler(request); Object empty = operation.execute(emptyFormItems, authContext, converter).get(); JsonAssert.assertJsonEquals("{}", converter.convertToString(empty)); }
@Test public void testMetadataEmptyRequest() throws Exception { registerGadgetsHandler(null); JSONObject request = makeMetadataRequest(null, null); RpcHandler operation = registry.getRpcHandler(request); Object empty = operation.execute(emptyFormItems, token, converter).get(); JsonAssert.assertJsonEquals("{}", converter.convertToString(empty)); }
@Test public void testCajaEmptyRequest() throws Exception { registerGadgetsHandler(null); JSONObject request = makeCajaRequest(null); RpcHandler operation = registry.getRpcHandler(request); Object empty = operation.execute(emptyFormItems, authContext, converter).get(); JsonAssert.assertJsonEquals("{}", converter.convertToString(empty)); }