/** * Allowed end-points /people/{userId}/{groupId} * * examples: /people/john.doe/@all /people/john.doe/@friends /people/john.doe/@self */ @Operation(httpMethods = "PUT", bodyParam = "person") public Future<?> update(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); // Enforce preconditions - exactly one user is specified HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); HandlerPreconditions.requireSingular(userIds, "Multiple userIds not supported"); UserId userId = userIds.iterator().next(); // Update person and return it return personService.updatePerson(Iterables.getOnlyElement(userIds), request.getTypedParameter("person", Person.class), request.getToken()); }
/** * Allowed end-points /people/{userId}/{groupId} * * examples: /people/john.doe/@all /people/john.doe/@friends /people/john.doe/@self */ @Operation(httpMethods = "PUT", bodyParam = "person") public Future<?> update(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); // Enforce preconditions - exactly one user is specified HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); HandlerPreconditions.requireSingular(userIds, "Multiple userIds not supported"); UserId userId = userIds.iterator().next(); // Update person and return it return personService.updatePerson(Iterables.getOnlyElement(userIds), request.getTypedParameter("person", Person.class), request.getToken()); }
@Test public void testHandlePut() throws Exception { String jsonPerson = "{person: {aboutMe: 'A person'}}"; String path = "/people/john.doe/@self"; RestHandler operation = registry.getRestHandler(path, "PUT"); Person person = new PersonImpl(); expect(converter.convertToObject(eq(jsonPerson), eq(Person.class))) .andReturn(person); expect(personService.updatePerson(eq(JOHN_DOE.iterator().next()), eq(person), eq(token))).andReturn(Futures.immediateFuture(person)); replay(); assertEquals(person, operation.execute(Maps.<String, String[]>newHashMap(), new StringReader(jsonPerson), token, converter).get()); verify(); }
@Test public void testHandlePut() throws Exception { String jsonPerson = "{person: {aboutMe: 'A person'}}"; String path = "/people/john.doe/@self"; RestHandler operation = registry.getRestHandler(path, "PUT"); Person person = new PersonImpl(); expect(converter.convertToObject(eq(jsonPerson), eq(Person.class))) .andReturn(person); expect(personService.updatePerson(eq(JOHN_DOE.iterator().next()), eq(person), eq(token))).andReturn(Futures.immediateFuture(person)); replay(); assertEquals(person, operation.execute(Maps.<String, String[]>newHashMap(), new StringReader(jsonPerson), token, converter).get()); verify(); }