ViolationsController { @ApiOperation( value = "violations", notes = "Get all violations", response = Violation.class, responseContainer = "List" ) @ApiResponses(value = {@ApiResponse(code = 200, message = "List of all violations")}) @ApiImplicitParams({ @ApiImplicitParam(name = "from", dataType = "date-time", paramType = "query", value = "Include only violations that happened after this point in time. " + "Example: \"2015-05-21T10:24:47.788-02:00\""), @ApiImplicitParam(name = "to", dataType = "date-time", paramType = "query", value = "Include only violations that happened up to this point in time. " + "Example: \"2015-05-21T10:24:47.788-02:00\""), @ApiImplicitParam(name = "page", dataType = "integer", paramType = "query", value = "Results page you want to retrieve (0..N)"), @ApiImplicitParam(name = "size", dataType = "integer", paramType = "query", value = "Number of records per page."), @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query", value = "Sorting criteria in the format: \"property,[asc|desc]\". " + "Default sort order is ascending. " + "Multiple sort criteria are supported.") }) @RequestMapping(method = GET) public Page<Violation> violations( @ApiParam(value = "Include only violations in these accounts") @RequestParam(value = "accounts", required = false) final List<String> accounts, @ApiIgnore @RequestParam(value = "from", required = false) @DateTimeFormat(iso = DATE_TIME) DateTime from, @ApiIgnore @RequestParam(value = "to", required = false) @DateTimeFormat(iso = DATE_TIME) DateTime to, @ApiParam(value = "Include only violations after the one with this id") @RequestParam(value = "last-violation", required = false) final Long lastViolation, @ApiParam(value = "Include only violations where checked field equals this value (i.e. resolved violations)") @RequestParam(value = "checked", required = false, defaultValue = "false") final boolean checked, @ApiParam(value = "Include only violations with a certain severity") @RequestParam(value = "severity", required = false) final Integer severity, @ApiParam(value = "Include only violations with a certain priority") @RequestParam(value = "priority", required = false) final Integer priority, @ApiParam(value = "Include only violations that are audit relevant") @RequestParam(value = "audit-relevant", required = false) final Boolean auditRelevant, @ApiParam(value = "Include only violations with a certain type") @RequestParam(value = "type", required = false) final String type, @ApiParam(value = "Include only violations with a certain types") @RequestParam(value = "types", required = false) final List<String> types, @ApiParam(value = "Include only violations with a certain application name") @RequestParam(value = "application-ids", required = false) final List<String> applicationIds, @ApiParam(value = "Include only violations with a certain application version") @RequestParam(value = "application-version-ids", required = false) final List<String> applicationVersionIds, @ApiParam(value = "show also whitelisted vioaltions") @RequestParam(value = "whitelisted", required = false, defaultValue = "false") final boolean whitelisted, @ApiIgnore @PageableDefault(page = 0, size = 10, sort = "id", direction = ASC) final Pageable pageable) throws NotFoundException { if (from == null) { from = new DateTime(0); } if (to == null) { to = DateTime.now(); } final List<String> allTypes = newArrayList(); if (types != null && !types.isEmpty()) { types.stream().filter(Objects::nonNull).forEach(allTypes::add); } if (type != null) { allTypes.add(type); } return mapBackendToFrontendViolations( violationService.queryViolations( accounts, from, to, lastViolation, checked, severity, priority, auditRelevant, allTypes, whitelisted, applicationIds, applicationVersionIds, pageable)); }  @ApiOperation( value = "violations", notes = "Get one violation", response = Violation.class ) @ApiResponses(value = {@ApiResponse(code = 200, message = "Violation")}) @RequestMapping(value = "/{id}", method = GET) Violation getViolation(
            @ApiParam(value = "Violation id")
            @PathVariable(value = "id")
            final Long id); @ApiOperation( value = "violations", notes = "Get all violations", response = Violation.class, responseContainer = "List" ) @ApiResponses(value = {@ApiResponse(code = 200, message = "List of all violations")}) @ApiImplicitParams({ @ApiImplicitParam(name = "from", dataType = "date-time", paramType = "query", value = "Include only violations that happened after this point in time. " + "Example: \"2015-05-21T10:24:47.788-02:00\""), @ApiImplicitParam(name = "to", dataType = "date-time", paramType = "query", value = "Include only violations that happened up to this point in time. " + "Example: \"2015-05-21T10:24:47.788-02:00\""), @ApiImplicitParam(name = "page", dataType = "integer", paramType = "query", value = "Results page you want to retrieve (0..N)"), @ApiImplicitParam(name = "size", dataType = "integer", paramType = "query", value = "Number of records per page."), @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query", value = "Sorting criteria in the format: \"property,[asc|desc]\". " + "Default sort order is ascending. " + "Multiple sort criteria are supported.") }) @RequestMapping(method = GET) Page<Violation> violations(
            @ApiParam(value = "Include only violations in these accounts")
            @RequestParam(value = "accounts", required = false)
            final List<String> accounts,
            @ApiIgnore
            @RequestParam(value = "from", required = false)
            @DateTimeFormat(iso = DATE_TIME)
            DateTime from,
            @ApiIgnore
            @RequestParam(value = "to", required = false)
            @DateTimeFormat(iso = DATE_TIME)
            DateTime to,
            @ApiParam(value = "Include only violations after the one with this id")
            @RequestParam(value = "last-violation", required = false)
            final Long lastViolation,
            @ApiParam(value = "Include only violations where checked field equals this value (i.e. resolved violations)")
            @RequestParam(value = "checked", required = false, defaultValue = "false")
            final boolean checked,
            @ApiParam(value = "Include only violations with a certain severity")
            @RequestParam(value = "severity", required = false)
            final Integer severity,
            @ApiParam(value = "Include only violations with a certain priority")
            @RequestParam(value = "priority", required = false)
            final Integer priority,
            @ApiParam(value = "Include only violations that are audit relevant")
            @RequestParam(value = "audit-relevant", required = false)
            final Boolean auditRelevant,
            @ApiParam(value = "Include only violations with a certain type")
            @RequestParam(value = "type", required = false)
            final String type,
            @ApiParam(value = "Include only violations with a certain types")
            @RequestParam(value = "types", required = false)
            final List<String> types,
            @ApiParam(value = "Include only violations with a certain application name")
            @RequestParam(value = "application-ids", required = false)
            final List<String> applicationIds,
            @ApiParam(value = "Include only violations with a certain application version")
            @RequestParam(value = "application-version-ids", required = false)
            final List<String> applicationVersionIds,
            @ApiParam(value = "show also whitelisted vioaltions")
            @RequestParam(value = "whitelisted", required = false, defaultValue = "false")
            final boolean whitelisted,
            @ApiIgnore
            @PageableDefault(page = 0, size = 10, sort = "id", direction = ASC) final Pageable pageable); @ApiOperation( value = "Resolve and explain this violation", notes = "Resolve and explain violation", response = Void.class ) @ApiResponses(value = {@ApiResponse(code = 200, message = "Violation resolved successfully")}) @RequestMapping(value = "/{id}/resolution", method = POST) Violation resolveViolations(
            @ApiParam(value = "", required = true)
            @PathVariable("id")
            final Long id,
            @ApiParam(value = "", required = true)
            @RequestBody final String comment,
            @ApiIgnore @AuthenticationPrincipal(errorOnInvalidType = true) final String userId); @ApiResponse(code = 202, message = "Violation successfully accepted!") @ResponseStatus(code = HttpStatus.ACCEPTED) @PostMapping(consumes = APPLICATION_JSON_VALUE) @PreAuthorize("#oauth2.hasScope('fullstop.violation.write')") void createViolation(@Valid @RequestBody CreateViolation violation);  }
@SuppressWarnings("unchecked") @Test public void testViolations() throws Exception { when(violationServiceMock.queryViolations(any(), any(), any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(), any())).thenReturn( new PageImpl<>( newArrayList(violationResult), new PageRequest(0, 20, ASC, "id"), 50)); final ResultActions resultActions = this.mockMvc.perform(get("/api/violations")).andExpect(status().isOk()); resultActions.andExpect(jsonPath("$.content").value(hasSize(1))); verify(violationServiceMock).queryViolations( isNull(List.class), any(DateTime.class), any(DateTime.class), isNull(Long.class), anyBoolean(), isNull(Integer.class), isNull(Integer.class), isNull(Boolean.class), anyListOf(String.class), anyBoolean(), isNull(List.class), isNull(List.class), any()); verify(mockViolationConverter).convert(any(ViolationEntity.class)); }