/** * Allowed end-points /activitystreams/{userId}/@self/{appId}/{activityId} * * Examples: /activitystreams/john.doe/@self/1/object2 - 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="PUT", bodyParam = "activity") public Future<?> update(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.requireSingular(activityIds, "Must specify exactly one activity ID"); return service.updateActivityEntry(Iterables.getOnlyElement(userIds), request.getGroup(), request.getAppId(), request.getFields(), request.getTypedParameter("activity", ActivityEntry.class), activityIds.iterator().next(), request.getToken()); }
/** * Allowed end-points /activitystreams/{userId}/@self/{appId}/{activityId} * * Examples: /activitystreams/john.doe/@self/1/object2 - 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="PUT", bodyParam = "activity") public Future<?> update(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.requireSingular(activityIds, "Must specify exactly one activity ID"); return service.updateActivityEntry(Iterables.getOnlyElement(userIds), request.getGroup(), request.getAppId(), request.getFields(), request.getTypedParameter("activity", ActivityEntry.class), activityIds.iterator().next(), request.getToken()); }
@Test public void testHandlePut() throws Exception { String jsonActivityEntry = "{title: 'hi mom!', object: {id: 'testObject'}}"; String path = "/activitystreams/john.doe/@self/@app/testObject"; RestHandler operation = registry.getRestHandler(path, "PUT"); ActivityEntry entry = new ActivityEntryImpl(); org.easymock.EasyMock.expect(converter.convertToObject(eq(jsonActivityEntry), eq(ActivityEntry.class))) .andReturn(entry); org.easymock.EasyMock.expect(service.updateActivityEntry(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.<String>of()), eq(entry), eq("testObject"), 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(); }
@Test public void testHandlePut() throws Exception { String jsonActivityEntry = "{title: 'hi mom!', object: {id: 'testObject'}}"; String path = "/activitystreams/john.doe/@self/@app/testObject"; RestHandler operation = registry.getRestHandler(path, "PUT"); ActivityEntry entry = new ActivityEntryImpl(); org.easymock.EasyMock.expect(converter.convertToObject(eq(jsonActivityEntry), eq(ActivityEntry.class))) .andReturn(entry); org.easymock.EasyMock.expect(service.updateActivityEntry(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.<String>of()), eq(entry), eq("testObject"), 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(); }