@Test public void testFutureDispatch() throws Exception { // Test calling a handler method which does not return a future RestHandler handler = registry.getRestHandler("/test", "POST"); Future<?> future = handler.execute(Maps.<String, String[]>newHashMap(), null, null, null); assertEquals(TestHandler.CREATE_RESPONSE, future.get()); }
@Test public void testRestWithInputClassThatIsntRequestItem() throws Exception { RestHandler handler = registry.getRestHandler("/test/echo", "GET"); String[] value = {"Bob"}; Future<?> future = handler.execute(ImmutableMap.of("value", value), null, null, converter); assertEquals(future.get(), TestHandler.ECHO_PREFIX + "Bob"); }
@Test public void testNonFutureDispatch() throws Exception { // Test calling a handler method which does not return a future RestHandler handler = registry.getRestHandler("/test", "GET"); Future<?> future = handler.execute(Maps.<String, String[]>newHashMap(), null, null, null); assertEquals(TestHandler.GET_RESPONSE, future.get()); }
@Test public void testNonFutureDispatch() throws Exception { // Test calling a handler method which does not return a future RestHandler handler = registry.getRestHandler("/test", "GET"); Future<?> future = handler.execute(Maps.<String, String[]>newHashMap(), null, null, null); assertEquals(TestHandler.GET_RESPONSE, future.get()); }
@Test public void testRestWithInputClassThatIsntRequestItem() throws Exception { RestHandler handler = registry.getRestHandler("/test/echo", "GET"); String[] value = {"Bob"}; Future<?> future = handler.execute(ImmutableMap.of("value", value), null, null, converter); assertEquals(future.get(), TestHandler.ECHO_PREFIX + "Bob"); }
@Test public void testRestWithInputClassThatIsntRequestItem() throws Exception { RestHandler handler = registry.getRestHandler("/test/echo", "GET"); String[] value = {"Bob"}; Future<?> future = handler.execute(ImmutableMap.of("value", value), null, null, converter); assertEquals(future.get(), TestHandler.ECHO_PREFIX + "Bob"); }
@Test public void testFutureDispatch() throws Exception { // Test calling a handler method which does not return a future RestHandler handler = registry.getRestHandler("/test", "POST"); Future<?> future = handler.execute(Maps.<String, String[]>newHashMap(), null, null, null); assertEquals(TestHandler.CREATE_RESPONSE, future.get()); }
@Test public void testNonFutureDispatch() throws Exception { // Test calling a handler method which does not return a future RestHandler handler = registry.getRestHandler("/test", "GET"); Future<?> future = handler.execute(Maps.<String, String[]>newHashMap(), null, null, null); assertEquals(TestHandler.GET_RESPONSE, future.get()); }
@Test public void testRestWithInputClassThatIsntRequestItem() throws Exception { RestHandler handler = registry.getRestHandler("/test/echo", "GET"); String[] value = {"Bob"}; Future<?> future = handler.execute(ImmutableMap.of("value", value), null, null, converter); assertEquals(future.get(), TestHandler.ECHO_PREFIX + "Bob"); }
@Test public void testNonFutureDispatch() throws Exception { // Test calling a handler method which does not return a future RestHandler handler = registry.getRestHandler("/test", "GET"); Future<?> future = handler.execute(Maps.<String, String[]>newHashMap(), null, null, null); assertEquals(TestHandler.GET_RESPONSE, future.get()); }
@Test public void testNonFutureDispatch() throws Exception { // Test calling a handler method which does not return a future RestHandler handler = registry.getRestHandler("/test", "GET"); Future<?> future = handler.execute(Maps.<String, String[]>newHashMap(), null, null, null); assertEquals(TestHandler.GET_RESPONSE, future.get()); }
@Test public void testFailTokenAuthInvalidateAppResource() throws Exception { String path = "/cache/invalidate"; RestHandler operation = registry.getRestHandler(path, "POST"); params.put(InvalidationHandler.KEYS_PARAM, new String[]{"http://www.example.org/gadget.xml"}); try { operation.execute(params, null, token, converter).get(); fail("Expected error"); } catch (ExecutionException ee) { assertTrue(ee.getCause() instanceof ProtocolException); } }
@Test public void testFailTokenAuthInvalidateAppResource() throws Exception { String path = "/cache/invalidate"; RestHandler operation = registry.getRestHandler(path, "POST"); params.put(InvalidationHandler.KEYS_PARAM, new String[]{"http://www.example.org/gadget.xml"}); try { operation.execute(params, null, token, converter).get(); fail("Expected error"); } catch (ExecutionException ee) { assertTrue(ee.getCause() instanceof ProtocolException); } }
@Test public void testFailTokenAuthInvalidateAppResource() throws Exception { String path = "/cache/invalidate"; RestHandler operation = registry.getRestHandler(path, "POST"); params.put(InvalidationHandler.KEYS_PARAM, new String[]{"http://www.example.org/gadget.xml"}); try { operation.execute(params, null, token, converter).get(); fail("Expected error"); } catch (ExecutionException ee) { assertTrue(ee.getCause() instanceof ProtocolException); } }
@Test public void testHandleGetSelf() throws Exception { String path = "/people/john.doe/@self"; RestHandler operation = registry.getRestHandler(path, "GET"); Person data = new PersonImpl(); expect(personService.getPerson(eq(JOHN_DOE.iterator().next()), eq(DEFAULT_FIELDS), eq(token))).andReturn(Futures.immediateFuture(data)); replay(); assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }
@Test public void testHandleGetSelf() throws Exception { String path = "/people/john.doe/@self"; RestHandler operation = registry.getRestHandler(path, "GET"); Person data = new PersonImpl(); expect(personService.getPerson(eq(JOHN_DOE.iterator().next()), eq(DEFAULT_FIELDS), eq(token))).andReturn(Futures.immediateFuture(data)); replay(); assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }
@Test public void testHandleAnonymousUser() throws Exception { String path = "/people/-1"; RestHandler operation = registry.getRestHandler(path, "GET"); Person data = new PersonImpl(); expect(personService.getPerson(eq(ANONYMOUS), eq(DEFAULT_FIELDS), eq(token))).andReturn(Futures.immediateFuture(data)); replay(); assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }
@Test public void testHandleDelete() throws Exception { String path = "/activities/john.doe/@self/@app/1"; RestHandler operation = registry.getRestHandler(path, "DELETE"); org.easymock.EasyMock.expect(activityService.deleteActivities(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.of("1")), eq(token))).andReturn(Futures.immediateFuture((Void) null)); replay(); assertNull(operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); reset(); }
@Test public void testHandleGetSelf() throws Exception { String path = "/people/john.doe/@self"; RestHandler operation = registry.getRestHandler(path, "GET"); Person data = new PersonImpl(); expect(personService.getPerson(eq(JOHN_DOE.iterator().next()), eq(DEFAULT_FIELDS), eq(token))).andReturn(ImmediateFuture.newInstance(data)); replay(); assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }
@Test public void testHandleAnonymousUser() throws Exception { String path = "/people/-1"; RestHandler operation = registry.getRestHandler(path, "GET"); Person data = new PersonImpl(); expect(personService.getPerson(eq(ANONYMOUS), eq(DEFAULT_FIELDS), eq(token))).andReturn(Futures.immediateFuture(data)); replay(); assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }