private Future<?> setupBodyRequest(String method) throws ProtocolException { String jsonActivityEntry = "{title: 'hi mom!', object: {id: 'testObject'}}"; String path = "/activitystreams/john.doe/@self/@app"; RestHandler operation = registry.getRestHandler(path, method); ActivityEntry entry = new ActivityEntryImpl(); org.easymock.EasyMock.expect(converter.convertToObject(eq(jsonActivityEntry), eq(ActivityEntry.class))) .andReturn(entry); org.easymock.EasyMock.expect(service.createActivityEntry(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.<String>of()), eq(entry), eq(token))).andReturn(Futures.immediateFuture((ActivityEntry) null)); replay(); return operation.execute(Maps.<String, String[]>newHashMap(), new StringReader(jsonActivityEntry), token, converter); }
private Future<?> setupBodyRequest(String method) throws ProtocolException { String jsonActivityEntry = "{title: 'hi mom!', object: {id: 'testObject'}}"; String path = "/activitystreams/john.doe/@self/@app"; RestHandler operation = registry.getRestHandler(path, method); ActivityEntry entry = new ActivityEntryImpl(); org.easymock.EasyMock.expect(converter.convertToObject(eq(jsonActivityEntry), eq(ActivityEntry.class))) .andReturn(entry); org.easymock.EasyMock.expect(service.createActivityEntry(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.<String>of()), eq(entry), eq(token))).andReturn(Futures.immediateFuture((ActivityEntry) null)); replay(); return operation.execute(Maps.<String, String[]>newHashMap(), new StringReader(jsonActivityEntry), token, converter); }
@Test public void testHandlePost() throws Exception { String jsonActivityEntry = "{title: 'hi mom!', object: {id: 'testObject'}}"; String path = "/activitystreams/john.doe/@self/@app"; RestHandler operation = registry.getRestHandler(path, "POST"); ActivityEntry entry = new ActivityEntryImpl(); org.easymock.EasyMock.expect(converter.convertToObject(eq(jsonActivityEntry), eq(ActivityEntry.class))) .andReturn(entry); org.easymock.EasyMock.expect(service.createActivityEntry(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.<String>of()), eq(entry), eq(token))).andReturn(Futures.immediateFuture((ActivityEntry) null)); replay(); Future<?> future = operation.execute(Maps.<String, String[]>newHashMap(), new StringReader(jsonActivityEntry), token, converter); assertNull(future.get()); verify(); reset(); }
/** * Allowed end-points /activitystreams/{userId}/@self/{appId} * * Examples: /activitystreams/john.doe/@self/{appId} - postBody is an activity object * * @param request a {@link org.apache.shindig.social.opensocial.service.SocialRequestItem} object. * @return a {@link java.util.concurrent.Future} object. * @throws org.apache.shindig.protocol.ProtocolException if any. */ @Operation(httpMethods="POST", bodyParam = "activity") public Future<?> create(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); List<String> activityIds = request.getListParameter("activityId"); HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); HandlerPreconditions.requireSingular(userIds, "Multiple userIds not supported"); HandlerPreconditions.requireEmpty(activityIds, "Cannot specify activity ID in create"); return service.createActivityEntry(Iterables.getOnlyElement(userIds), request.getGroup(), request.getAppId(), request.getFields(), request.getTypedParameter("activity", ActivityEntry.class), request.getToken()); }
@Test public void testHandlePost() throws Exception { String jsonActivityEntry = "{title: 'hi mom!', object: {id: 'testObject'}}"; String path = "/activitystreams/john.doe/@self/@app"; RestHandler operation = registry.getRestHandler(path, "POST"); ActivityEntry entry = new ActivityEntryImpl(); org.easymock.EasyMock.expect(converter.convertToObject(eq(jsonActivityEntry), eq(ActivityEntry.class))) .andReturn(entry); org.easymock.EasyMock.expect(service.createActivityEntry(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.<String>of()), eq(entry), eq(token))).andReturn(Futures.immediateFuture((ActivityEntry) null)); replay(); Future<?> future = operation.execute(Maps.<String, String[]>newHashMap(), new StringReader(jsonActivityEntry), token, converter); assertNull(future.get()); verify(); reset(); }
/** * Allowed end-points /activitystreams/{userId}/@self/{appId} * * Examples: /activitystreams/john.doe/@self/{appId} - postBody is an activity object * * @param request a {@link org.apache.shindig.social.opensocial.service.SocialRequestItem} object. * @return a {@link java.util.concurrent.Future} object. * @throws org.apache.shindig.protocol.ProtocolException if any. */ @Operation(httpMethods="POST", bodyParam = "activity") public Future<?> create(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); List<String> activityIds = request.getListParameter("activityId"); HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); HandlerPreconditions.requireSingular(userIds, "Multiple userIds not supported"); HandlerPreconditions.requireEmpty(activityIds, "Cannot specify activity ID in create"); return service.createActivityEntry(Iterables.getOnlyElement(userIds), request.getGroup(), request.getAppId(), request.getFields(), request.getTypedParameter("activity", ActivityEntry.class), request.getToken()); }