PreferencesService extends Service { @POST @Consumes(APPLICATION_JSON) @GenerateLink(rel = LINK_REL_PREFERENCES) @ApiOperation( value = "Saves preferences of logged in user", notes = "All the existing user's preferences will be override by this method") @ApiResponses({ @ApiResponse(code = 204, message = "Preferences successfully saved"), @ApiResponse(code = 400, message = "Request doesn't contain new preferences"), @ApiResponse(code = 500, message = "Couldn't save preferences due to internal server error") }) public void save(Map<String, String> preferences) throws BadRequestException, ServerException { if (preferences == null) { throw new BadRequestException("Required non-null new preferences"); } preferenceManager.save(userId(), preferences); }  @GET @Produces(APPLICATION_JSON) @GenerateLink(rel = LINK_REL_PREFERENCES) @ApiOperation( value = "Gets preferences of logged in user", notes = "If not all the preferences needed then 'filter' may be used, " + "basically it is regex for filtering preferences by names") @ApiResponses({ @ApiResponse(code = 200, message = "Preferences successfully fetched"), @ApiResponse(code = 500, message = "Internal Server Error") }) Map<String, String> find(
      @ApiParam(
              "Regex for filtering preferences by names, e.g. '.*github.*' "
                  + "will return all the preferences which name contains github")
          @QueryParam("filter")
          String filter); @POST @Consumes(APPLICATION_JSON) @GenerateLink(rel = LINK_REL_PREFERENCES) @ApiOperation( value = "Saves preferences of logged in user", notes = "All the existing user's preferences will be override by this method") @ApiResponses({ @ApiResponse(code = 204, message = "Preferences successfully saved"), @ApiResponse(code = 400, message = "Request doesn't contain new preferences"), @ApiResponse(code = 500, message = "Couldn't save preferences due to internal server error") }) void save(Map<String, String> preferences); @PUT @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @GenerateLink(rel = LINK_REL_PREFERENCES) @ApiOperation( value = "Updates preferences of logged in user", notes = "The merge strategy is used for update, which means that " + "existing preferences with keys equal to update preference keys will " + "be replaces with new values, and new preferences will be added") @ApiResponses({ @ApiResponse( code = 200, message = "Preferences successfully updated, response contains " + "all the user preferences"), @ApiResponse(code = 400, message = "Request doesn't contain preferences update"), @ApiResponse(code = 500, message = "Couldn't update preferences due to internal server error") }) Map<String, String> update(Map<String, String> preferences); @DELETE @Consumes(APPLICATION_JSON) @GenerateLink(rel = LINK_REL_PREFERENCES) @ApiOperation( value = "Remove preferences of logged in user.", notes = "If names are not specified, then all the user's preferences will be removed, " + "otherwise only the preferences which names are listed") @ApiResponses({ @ApiResponse(code = 204, message = "Preferences successfully removed"), @ApiResponse(code = 500, message = "Couldn't remove preferences due to internal server error") }) void removePreferences(@ApiParam("Preferences to remove") List<String> names);  }
@Test public void shouldSavePreferences() throws Exception { final Map<String, String> preferences = ImmutableMap.of( "pref1", "value1", "pref2", "value2", "pref3", "value3"); final Response response = given() .auth() .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) .contentType("application/json") .body(preferences) .when() .post(SECURE_PATH + "/preferences"); assertEquals(response.getStatusCode(), 204); verify(preferenceManager).save(SUBJECT.getUserId(), preferences); }