RuleController { @RequestMapping(method = POST) @ApiOperation(value = "adds a new rule for whitelisting violations", authorizations = {@Authorization(value = "oauth", scopes = {@AuthorizationScope(scope = "uid", description = "")})}) @ApiResponses(value = {@ApiResponse(code = 201, message = "New rule saved successfully")}) @ResponseStatus(CREATED) public RuleEntity addWhitelisting(@RequestBody final RuleDTO ruleDTO, @ApiIgnore @AuthenticationPrincipal(errorOnInvalidType = true) final String userId) throws ForbiddenException { checkPermission(userId); return ruleEntityService.save(ruleDTO); }  @RequestMapping(method = GET) @ApiOperation(value = "Shows a list of all rules", response = RuleEntity.class, responseContainer = "List", authorizations = {@Authorization(value = "oauth", scopes = {@AuthorizationScope(scope = "uid", description = "")})}) // TODO only valid rules? @ApiResponses(value = {@ApiResponse(code = 200, message = "There you go")}) @ResponseStatus(OK) List<RuleEntity> showWhitelistings(@ApiIgnore @AuthenticationPrincipal(errorOnInvalidType = true) final String userId); @RequestMapping(method = POST) @ApiOperation(value = "adds a new rule for whitelisting violations", authorizations = {@Authorization(value = "oauth", scopes = {@AuthorizationScope(scope = "uid", description = "")})}) @ApiResponses(value = {@ApiResponse(code = 201, message = "New rule saved successfully")}) @ResponseStatus(CREATED) RuleEntity addWhitelisting(@RequestBody final RuleDTO ruleDTO,  @ApiIgnore @AuthenticationPrincipal(errorOnInvalidType = true) final String userId); @RequestMapping(value = "/{id}", method = GET) @ApiOperation(value = "adds a new rule for whitelisting violations", response = RuleEntity.class, authorizations = {@Authorization(value = "oauth", scopes = {@AuthorizationScope(scope = "uid", description = "")})}) @ApiResponses(value = {@ApiResponse(code = 200, message = "There you go")}) @ResponseStatus(OK) RuleEntity getWhitelisting(@PathVariable("id")
                                      final Long id, @ApiIgnore @AuthenticationPrincipal(errorOnInvalidType = true) final String userId); @RequestMapping(value = "/{id}", method = PUT) @ApiOperation(value = "updates a rule by invalidating it and creating a new rule", authorizations = {@Authorization(value = "oauth", scopes = {@AuthorizationScope(scope = "uid", description = "")})}) @ApiResponses(value = {@ApiResponse(code = 200, message = "Updated")}) @ResponseStatus(OK) RuleEntity updateWhitelisting(@RequestBody final RuleDTO ruleDTO,
                                         @PathVariable("id") final Long id,
                                         @ApiIgnore @AuthenticationPrincipal(errorOnInvalidType = true) final String userId); @RequestMapping(value = "/{id}", method = DELETE) @ApiOperation(value = "Sets a new expiry date on a rule. If there is no given expiry date, it defaults to now() and the rule is invalid immediately", authorizations = {@Authorization(value = "oauth", scopes = {@AuthorizationScope(scope = "uid", description = "")})}) @ApiResponses(value = {@ApiResponse(code = 204, message = "Deleted")}) @ResponseStatus(NO_CONTENT) void expireWhitelistRule(@PathVariable("id") final Long id,
                                   @RequestParam(value = "expiryDate", required = false)
                                   @DateTimeFormat(iso = DATE_TIME)
                                   final DateTime expiryDate,
                                   @AuthenticationPrincipal(errorOnInvalidType = true) final String userId);  }
@Test public void testAddWhitelisting() throws Exception { final RuleDTO ruleDTO = new RuleDTO(); ruleDTO.setAccountId("1234"); when(ruleEntityService.save(any(RuleDTO.class))).thenReturn(ruleEntity); final ObjectMapper objectMapper = new ObjectMapper(); final String ruleAsJson = objectMapper.writeValueAsString(ruleDTO); final ResultActions resultActions = mockMvc.perform(post("/api/whitelisting-rules").contentType(APPLICATION_JSON).content(ruleAsJson)); resultActions.andExpect(jsonPath("$.id").value(1)).andExpect(jsonPath("$.account_id").value("1234")); verify(ruleEntityService).save(any(RuleDTO.class)); verify(teamOperationsMock).getTeamIdsByUser(anyString()); verify(ruleControllerPropertiesMock).getAllowedTeams(); }