ProfileService extends Service { @GET @Path("/{id}") @Produces(APPLICATION_JSON) @GenerateLink(rel = LINK_REL_CURRENT_PROFILE) @ApiOperation("Get profile by user's id") @ApiResponses({ @ApiResponse(code = 200, message = "The response contains requested profile entity"), @ApiResponse( code = 404, message = "Profile for the user with requested identifier doesn't exist"), @ApiResponse(code = 500, message = "Couldn't retrieve profile due to internal server error") }) public ProfileDto getById(@ApiParam("User identifier") @PathParam("id") String userId) throws NotFoundException, ServerException { return linksInjector.injectLinks( asDto(profileManager.getById(userId), userManager.getById(userId)), getServiceContext()); }  @GET @Produces(APPLICATION_JSON) @GenerateLink(rel = LINK_REL_CURRENT_PROFILE) @ApiOperation("Get profile of the logged in user") @ApiResponses({ @ApiResponse(code = 200, message = "The response contains requested profile entity"), @ApiResponse(code = 404, message = "Currently logged in user doesn't have profile"), @ApiResponse(code = 500, message = "Couldn't retrieve profile due to internal server error") }) ProfileDto getCurrent(); @GET @Path("/{id}") @Produces(APPLICATION_JSON) @GenerateLink(rel = LINK_REL_CURRENT_PROFILE) @ApiOperation("Get profile by user's id") @ApiResponses({ @ApiResponse(code = 200, message = "The response contains requested profile entity"), @ApiResponse( code = 404, message = "Profile for the user with requested identifier doesn't exist"), @ApiResponse(code = 500, message = "Couldn't retrieve profile due to internal server error") }) ProfileDto getById(@ApiParam("User identifier") @PathParam("id") String userId); @PUT @Path("/{id}/attributes") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation( value = "Update the profile attributes of the user with requested identifier", notes = "The replace strategy is used for the update, so all the existing profile " + "attributes will be override by the profile update") @ApiResponses({ @ApiResponse( code = 200, message = "The profile successfully updated and the response contains " + "newly updated profile entity"), @ApiResponse( code = 404, message = "When profile for the user with requested identifier doesn't exist"), @ApiResponse(code = 500, message = "Couldn't retrieve profile due to internal server error") }) ProfileDto updateAttributesById(
      @ApiParam("Id of the user") @PathParam("id") String userId,
      @ApiParam("New profile attributes") Map<String, String> updates); @PUT @Path("/attributes") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @GenerateLink(rel = LINK_REL_CURRENT_PROFILE_ATTRIBUTES) @ApiOperation( value = "Update the profile attributes of the currently logged in user", notes = "The replace strategy is used for the update, so all the existing profile " + "attributes will be override with incoming values") ProfileDto updateAttributes(
      @ApiParam("New profile attributes") Map<String, String> updates); @DELETE @Path("/attributes") @GenerateLink(rel = LINK_REL_CURRENT_PROFILE_ATTRIBUTES) @Consumes(APPLICATION_JSON) @ApiOperation( value = "Remove profile attributes which names are equal to given", notes = "If names list is not send, all the attributes will be removed, " + "if there are no attributes which names equal to some of the given names, " + "then those names are skipped.") @ApiResponses({ @ApiResponse(code = 204, message = "Attributes successfully removed"), @ApiResponse(code = 500, message = "Couldn't remove attributes due to internal server error") }) void removeAttributes(
      @ApiParam("The names of the profile attributes to remove") List<String> names);  }
@Test public void shouldBeAbleToRemoveSpecifiedAttributes() throws Exception { when(profileManager.getById(SUBJECT.getUserId())) .thenReturn( new ProfileImpl( SUBJECT.getUserId(), ImmutableMap.of( "attr1", "value1", "attr2", "value2", "attr3", "value3"))); final Response response = given() .auth() .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) .when() .contentType("application/json") .body(asList("attr1", "attr3")) .delete(SECURE_PATH + "/profile/attributes"); assertEquals(response.getStatusCode(), 204); verify(profileManager).update(profileCaptor.capture()); final Profile profile = profileCaptor.getValue(); assertEquals(profile.getAttributes(), ImmutableMap.of("attr2", "value2")); }
@Test public void shouldRemoveAllAttributeIfNoSpecified() throws Exception { when(profileManager.getById(SUBJECT.getUserId())) .thenReturn( new ProfileImpl( SUBJECT.getUserId(), ImmutableMap.of( "attr1", "value1", "attr2", "value2", "attr3", "value3"))); final Response response = given() .auth() .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) .when() .contentType("application/json") .delete(SECURE_PATH + "/profile/attributes"); assertEquals(response.getStatusCode(), 204); verify(profileManager).update(profileCaptor.capture()); final Profile profile = profileCaptor.getValue(); assertTrue(profile.getAttributes().isEmpty()); }