protected RestHandler getRestHandler(HttpServletRequest servletRequest) { // TODO Rework to allow sub-services String path = servletRequest.getPathInfo(); // TODO - This shouldnt be on BaseRequestItem String method = servletRequest.getParameter(X_HTTP_METHOD_OVERRIDE); if (method == null) { method = servletRequest.getMethod(); } // Always returns a non-null handler. return dispatcher.getRestHandler(path, method.toUpperCase()); }
protected RestHandler getRestHandler(HttpServletRequest servletRequest) { // TODO Rework to allow sub-services String path = servletRequest.getPathInfo(); // TODO - This shouldnt be on BaseRequestItem String method = servletRequest.getParameter(X_HTTP_METHOD_OVERRIDE); if (method == null) { method = servletRequest.getMethod(); } // Always returns a non-null handler. return dispatcher.getRestHandler(path, method.toUpperCase()); }
protected RestHandler getRestHandler(HttpServletRequest servletRequest) { // TODO Rework to allow sub-services String path = servletRequest.getPathInfo(); // TODO - This shouldnt be on BaseRequestItem String method = servletRequest.getParameter(X_HTTP_METHOD_OVERRIDE); if (method == null) { method = servletRequest.getMethod(); } // Always returns a non-null handler. return dispatcher.getRestHandler(path, method.toUpperCase()); }
protected RestHandler getRestHandler(HttpServletRequest servletRequest) { // TODO Rework to allow sub-services String path = servletRequest.getPathInfo(); // TODO - This shouldnt be on BaseRequestItem String method = servletRequest.getParameter(X_HTTP_METHOD_OVERRIDE); if (method == null) { method = servletRequest.getMethod(); } // Always returns a non-null handler. return dispatcher.getRestHandler(path, method.toUpperCase()); }
protected RestHandler getRestHandler(HttpServletRequest servletRequest) { // TODO Rework to allow sub-services String path = servletRequest.getPathInfo(); // TODO - This shouldnt be on BaseRequestItem String method = servletRequest.getParameter(X_HTTP_METHOD_OVERRIDE); if (method == null) { method = servletRequest.getMethod(); } // Always returns a non-null handler. return dispatcher.getRestHandler(path, method.toUpperCase()); }
@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 testHandleGetSuportedFields() throws Exception { String path = "/activities/@supportedFields"; RestHandler operation = registry.getRestHandler(path, "GET"); replay(); @SuppressWarnings("unchecked") List<Object> received = (List<Object>) operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get(); assertEquals(2, received.size()); assertEquals("id", received.get(0).toString()); assertEquals("title", received.get(1).toString()); 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 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 testHandleDelete() throws Exception { String path = "/activitystreams/john.doe/@self/@app/myObjectId123"; RestHandler operation = registry.getRestHandler(path, "DELETE"); org.easymock.EasyMock.expect(service.deleteActivityEntries(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.of("myObjectId123")), eq(token))).andReturn(Futures.immediateFuture((Void) null)); replay(); assertNull(operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); reset(); }
@Test public void testHandleDelete() throws Exception { String path = "/activitystreams/john.doe/@self/@app/myObjectId123"; RestHandler operation = registry.getRestHandler(path, "DELETE"); org.easymock.EasyMock.expect(service.deleteActivityEntries(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.of("myObjectId123")), eq(token))).andReturn(Futures.immediateFuture((Void) null)); replay(); assertNull(operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); reset(); }
@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(); }
private void assertHandleGetForGroup(GroupId.Type group) throws Exception { String path = "/appdata/john.doe/@" + group.toString() + "/appId"; RestHandler operation = registry.getRestHandler(path, "GET"); DataCollection data = new DataCollection(null); org.easymock.EasyMock.expect(appDataService.getPersonData(eq(JOHN_DOE), eq(new GroupId(group, null)), eq("appId"), eq(ImmutableSet.<String>of()), eq(token))) .andReturn(Futures.immediateFuture(data)); replay(); assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }
private void assertHandleGetForGroup(GroupId.Type group) throws Exception { String path = "/appdata/john.doe/@" + group.toString() + "/appId"; RestHandler operation = registry.getRestHandler(path, "GET"); DataCollection data = new DataCollection(null); org.easymock.EasyMock.expect(appDataService.getPersonData(eq(JOHN_DOE), eq(new GroupId(group, null)), eq("appId"), eq(ImmutableSet.<String>of()), eq(token))) .andReturn(ImmediateFuture.newInstance(data)); replay(); assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }
@Test public void testHandleSimpleGetInvalidateViewer() throws Exception { String path = "/cache/invalidate"; RestHandler operation = registry.getRestHandler(path, "GET"); invalidationService.invalidateUserResources( eq(ImmutableSet.of("userX")), eq(token)); expectLastCall(); replay(); operation.execute(params, null, token, converter).get(); verify(); reset(); }