ViolationsCountController { @RequestMapping(value = "/{account}", method = GET) @ApiResponses(@ApiResponse(code = 200, message = "Violation count of one account by app version and type", response = CountByAppVersionAndType.class, responseContainer = "List")) @ApiImplicitParams({ @ApiImplicitParam(name = "from", dataType = "date-time", paramType = "query", value = "Include only violations, that have been created after this timestamp. " + "Example: \"2015-05-21T10:24:47.788-02:00\""), @ApiImplicitParam(name = "to", dataType = "date-time", paramType = "query", value = "Include only violations, that have been created before this timestamp. " + "Example: \"2015-05-21T10:24:47.788-02:00\"") }) public List<CountByAppVersionAndType> countByAppVersionAndType( @ApiParam("an account id") @PathVariable final String account, @ApiIgnore @RequestParam @DateTimeFormat(iso = DATE_TIME) final Optional<DateTime> from, @ApiIgnore @RequestParam @DateTimeFormat(iso = DATE_TIME) final Optional<DateTime> to, @ApiParam("count only violations that have been resolved (true), or that are still open (false)") @RequestParam(value = "resolved",required = false, defaultValue = "false") final boolean resolved, @ApiParam("count only violations that have been whitelisted (true), or that are not whitelisted (false)") @RequestParam(value = "whitelisted",required = false, defaultValue = "false") final boolean whitelisted) { return violationRepository.countByAppVersionAndType(account, from, to, resolved, whitelisted); } @Autowired  ViolationsCountController(final ViolationRepository violationRepository); @RequestMapping(method = GET) @ApiResponses(@ApiResponse(code = 200, message = "Violation count by account and type", response = CountByAccountAndType.class, responseContainer = "List")) @ApiImplicitParams({ @ApiImplicitParam(name = "from", dataType = "date-time", paramType = "query", value = "Include only violations, that have been created after this timestamp. " + "Example: \"2015-05-21T10:24:47.788-02:00\""), @ApiImplicitParam(name = "to", dataType = "date-time", paramType = "query", value = "Include only violations, that have been created before this timestamp. " + "Example: \"2015-05-21T10:24:47.788-02:00\"") }) List<CountByAccountAndType> countByAccountAndTypes(
            @ApiParam("a list of account ids for filtering, leave blank to request all accounts")
            @RequestParam final
            Optional<Set<String>> accounts,
            @ApiIgnore
            @RequestParam
            @DateTimeFormat(iso = DATE_TIME) final
            Optional<DateTime> from,
            @ApiIgnore
            @RequestParam
            @DateTimeFormat(iso = DATE_TIME) final
            Optional<DateTime> to,
            @ApiParam("count only violations that have been resolved (true), or that are still open (false)")
            @RequestParam(value = "resolved",required = false, defaultValue = "false")
            final boolean resolved,
            @ApiParam("count only violations that have been whitelisted (true), or that are not whitelisted (false)")
            @RequestParam(value = "whitelisted",required = false, defaultValue = "false")
            final boolean whitelisted); @RequestMapping(value = "/{account}", method = GET) @ApiResponses(@ApiResponse(code = 200, message = "Violation count of one account by app version and type", response = CountByAppVersionAndType.class, responseContainer = "List")) @ApiImplicitParams({ @ApiImplicitParam(name = "from", dataType = "date-time", paramType = "query", value = "Include only violations, that have been created after this timestamp. " + "Example: \"2015-05-21T10:24:47.788-02:00\""), @ApiImplicitParam(name = "to", dataType = "date-time", paramType = "query", value = "Include only violations, that have been created before this timestamp. " + "Example: \"2015-05-21T10:24:47.788-02:00\"") }) List<CountByAppVersionAndType> countByAppVersionAndType(
            @ApiParam("an account id")
            @PathVariable final
            String account,
            @ApiIgnore
            @RequestParam
            @DateTimeFormat(iso = DATE_TIME) final
            Optional<DateTime> from,
            @ApiIgnore
            @RequestParam
            @DateTimeFormat(iso = DATE_TIME) final
            Optional<DateTime> to,
            @ApiParam("count only violations that have been resolved (true), or that are still open (false)")
            @RequestParam(value = "resolved",required = false, defaultValue = "false")
            final boolean resolved,
            @ApiParam("count only violations that have been whitelisted (true), or that are not whitelisted (false)")
            @RequestParam(value = "whitelisted",required = false, defaultValue = "false")
            final boolean whitelisted);  }
@Test public void testCountByAppVersionAndType() throws Exception { final DateTime from = DateTime.now(); final DateTime to = DateTime.now(); when(mockViolationRepository.countByAppVersionAndType(anyString(), any(), any(), eq(true), eq(false))) .thenReturn(newArrayList( new CountByAppVersionAndType("app1", "1.0", "OOPS", 40), new CountByAppVersionAndType("app1", "2.0", "OOPS", 10), new CountByAppVersionAndType(null, null, "OOPS", 15))); mockMvc.perform(get("/api/violation-count/{account}", "account001") .param("resolved", "true").param("from", from.toString()).param("to", to.toString()).param("whitelisted", "false")) .andExpect(status().isOk()) .andExpect(jsonPath("$").isArray()) .andExpect(jsonPath("$", hasSize(3))); verify(mockViolationRepository).countByAppVersionAndType(eq("account001"), eq(Optional.of(from)), eq(Optional.of(to)), eq(true), eq(false)); }