@Test public void testGetBestUserFromTimeRange() throws Exception { long timeOfPlantingTwoWeeksBefore = timeOfPlanting - (2 * TimeConstants.WEEK_IN_MILLISECONDS); _dbInjecter.injectTreeToProject("wood", "Adam", 3, timeOfPlanting, "Project"); _dbInjecter.injectTreeToProject("wood", "Bert", 1, timeOfPlanting, "Project"); _dbInjecter.injectTreeToProject("wood", "Bert", 1, timeOfPlanting, "Project"); _dbInjecter.injectTreeToProject("wood", "Adam", 1, timeOfPlantingTwoWeeksBefore, "Project"); _dbInjecter.injectTreeToProject("wood", "Claus", 1, timeOfPlantingTwoWeeksBefore, "Project"); mockMvc.perform(get(Uris.RANKING_BEST_USER_FOR_TIMERANGE + "{range}", "week").accept("application/json")).andExpect(status().isOk()).andExpect(jsonPath("$.[0].name").value("Adam")) .andExpect(jsonPath("$.[0].amount").value(3)).andExpect(jsonPath("$.[1].name").value("Bert")).andExpect(jsonPath("$.[1].amount").value(2)); mockMvc.perform(get(Uris.RANKING_BEST_USER_FOR_TIMERANGE + "{range}", "year").accept("application/json")).andExpect(status().isOk()).andExpect(jsonPath("$.[0].name").value("Adam")) .andExpect(jsonPath("$.[0].amount").value(4)).andExpect(jsonPath("$.[1].name").value("Bert")).andExpect(jsonPath("$.[1].amount").value(2)); mockMvc.perform(get(Uris.RANKING_BEST_USER_FOR_TIMERANGE + "{range}", "a").accept("application/json")).andExpect(status().isOk()).andExpect(jsonPath("$.[0].name").value("Adam")) .andExpect(jsonPath("$.[0].amount").value(4)).andExpect(jsonPath("$.[1].name").value("Bert")).andExpect(jsonPath("$.[1].amount").value(2)); }
@RequestMapping(value = Uris.RANKING_BEST_USER_FOR_TIMERANGE + "{timeRange}", method = RequestMethod.GET) public List<TreeRankedUserData> getBestUserFromTimeRange(@PathVariable String timeRange) { Long timeRangeEnd = System.currentTimeMillis(); Long timeRangeStart = 0L; switch (timeRange) { case "year": timeRangeStart = timeRangeEnd - TimeConstants.YEAR_IN_MILLISECONDS; break; case "week": timeRangeStart = timeRangeEnd - TimeConstants.WEEK_IN_MILLISECONDS; break; default: timeRangeStart = timeRangeEnd - TimeConstants.YEAR_IN_MILLISECONDS; break; } return _rankingRepository.getBestUserFromTimeRange(timeRangeStart, timeRangeEnd, PageRequest.of(0, 10)); }
RankingController { @RequestMapping(value = Uris.RANKING_BEST_USER_FOR_TIMERANGE + "{timeRange}", method = RequestMethod.GET) public List<TreeRankedUserData> getBestUserFromTimeRange(@PathVariable String timeRange) { Long timeRangeEnd = System.currentTimeMillis(); Long timeRangeStart = 0L; switch (timeRange) { case "year": timeRangeStart = timeRangeEnd - TimeConstants.YEAR_IN_MILLISECONDS; break; case "week": timeRangeStart = timeRangeEnd - TimeConstants.WEEK_IN_MILLISECONDS; break; default: timeRangeStart = timeRangeEnd - TimeConstants.YEAR_IN_MILLISECONDS; break; } return _rankingRepository.getBestUserFromTimeRange(timeRangeStart, timeRangeEnd, PageRequest.of(0, 10)); } }
RankingController { @RequestMapping(value = Uris.RANKING_BEST_USER_FOR_TIMERANGE + "{timeRange}", method = RequestMethod.GET) public List<TreeRankedUserData> getBestUserFromTimeRange(@PathVariable String timeRange) { Long timeRangeEnd = System.currentTimeMillis(); Long timeRangeStart = 0L; switch (timeRange) { case "year": timeRangeStart = timeRangeEnd - TimeConstants.YEAR_IN_MILLISECONDS; break; case "week": timeRangeStart = timeRangeEnd - TimeConstants.WEEK_IN_MILLISECONDS; break; default: timeRangeStart = timeRangeEnd - TimeConstants.YEAR_IN_MILLISECONDS; break; } return _rankingRepository.getBestUserFromTimeRange(timeRangeStart, timeRangeEnd, PageRequest.of(0, 10)); }  }
RankingController { @RequestMapping(value = Uris.RANKING_BEST_USER_FOR_TIMERANGE + "{timeRange}", method = RequestMethod.GET) public List<TreeRankedUserData> getBestUserFromTimeRange(@PathVariable String timeRange) { Long timeRangeEnd = System.currentTimeMillis(); Long timeRangeStart = 0L; switch (timeRange) { case "year": timeRangeStart = timeRangeEnd - TimeConstants.YEAR_IN_MILLISECONDS; break; case "week": timeRangeStart = timeRangeEnd - TimeConstants.WEEK_IN_MILLISECONDS; break; default: timeRangeStart = timeRangeEnd - TimeConstants.YEAR_IN_MILLISECONDS; break; } return _rankingRepository.getBestUserFromTimeRange(timeRangeStart, timeRangeEnd, PageRequest.of(0, 10)); }  @RequestMapping(value = Uris.RANKING_BEST_USER, method = RequestMethod.GET) Page<TreeRankedUserData> getBestUser(@RequestParam(value = "page") int page, @RequestParam(value = "size") int size, @RequestParam(value = "lastYear") boolean lastYear); @RequestMapping(value = Uris.RANKING_LAST_CREATED_USER, method = RequestMethod.GET) List<TimeRankedUserData> getLastUser(); @RequestMapping(value = Uris.RANKING_BEST_ORGANIZATION_TYPE + "{organizationType}", method = RequestMethod.GET) Page<TreeRankedUserData> getBestUserFromOrganizationType(@PathVariable OrganizationType organizationType, @Param(value = "page") int page, @Param(value = "size") int size,
            @RequestParam(value = "lastYear") boolean lastYear); @RequestMapping(value = Uris.RANKING_LAST_PLANTED_TREES, method = RequestMethod.GET) Page<TimeRankedTreeData> getLastPlantedTrees(@Param(value = "page") int page, @Param(value = "size") int size); @RequestMapping(value = Uris.RANKING_BEST_TEAM, method = RequestMethod.GET) Page<TreeRankedUserData> getBestTeams(@Param(value = "page") int page, @Param(value = "size") int size, @RequestParam(value = "lastYear") boolean lastYear); @RequestMapping(value = Uris.RANKING_BEST_USER_FOR_TIMERANGE + "{timeRange}", method = RequestMethod.GET) List<TreeRankedUserData> getBestUserFromTimeRange(@PathVariable String timeRange); @RequestMapping(value = Uris.RANKING_BEST_USER_FOR_PROJECT, method = RequestMethod.GET) Page<TreeRankedUserData> getBestUserForProject(@Param(value = "projectName") String projectName, @Param(value = "page") int page, @Param(value = "size") int size); @RequestMapping(value = Uris.RANKING_BEST_TEAM_FOR_PROJECT, method = RequestMethod.GET) Page<TreeRankedUserData> getBestTeamsForProject(@Param(value = "projectName") String projectName, @Param(value = "page") int page, @Param(value = "size") int size); @RequestMapping(value = Uris.RANKING_LAST_PLANTED_TREES_IN_PROJECT, method = RequestMethod.GET) Page<TimeRankedTreeData> getLastPlantedTreesInProject(@Param(value = "projectName") String projectName, @Param(value = "page") int page, @Param(value = "size") int size); }
RankingController { @RequestMapping(value = Uris.RANKING_BEST_USER_FOR_TIMERANGE + "{timeRange}", method = RequestMethod.GET) public List<TreeRankedUserData> getBestUserFromTimeRange(@PathVariable String timeRange) { Long timeRangeEnd = System.currentTimeMillis(); Long timeRangeStart = 0L; switch (timeRange) { case "year": timeRangeStart = timeRangeEnd - TimeConstants.YEAR_IN_MILLISECONDS; break; case "week": timeRangeStart = timeRangeEnd - TimeConstants.WEEK_IN_MILLISECONDS; break; default: timeRangeStart = timeRangeEnd - TimeConstants.YEAR_IN_MILLISECONDS; break; } return _rankingRepository.getBestUserFromTimeRange(timeRangeStart, timeRangeEnd, PageRequest.of(0, 10)); }  @RequestMapping(value = Uris.RANKING_BEST_USER, method = RequestMethod.GET) Page<TreeRankedUserData> getBestUser(@RequestParam(value = "page") int page, @RequestParam(value = "size") int size, @RequestParam(value = "lastYear") boolean lastYear); @RequestMapping(value = Uris.RANKING_LAST_CREATED_USER, method = RequestMethod.GET) List<TimeRankedUserData> getLastUser(); @RequestMapping(value = Uris.RANKING_BEST_ORGANIZATION_TYPE + "{organizationType}", method = RequestMethod.GET) Page<TreeRankedUserData> getBestUserFromOrganizationType(@PathVariable OrganizationType organizationType, @Param(value = "page") int page, @Param(value = "size") int size,
            @RequestParam(value = "lastYear") boolean lastYear); @RequestMapping(value = Uris.RANKING_LAST_PLANTED_TREES, method = RequestMethod.GET) Page<TimeRankedTreeData> getLastPlantedTrees(@Param(value = "page") int page, @Param(value = "size") int size); @RequestMapping(value = Uris.RANKING_BEST_TEAM, method = RequestMethod.GET) Page<TreeRankedUserData> getBestTeams(@Param(value = "page") int page, @Param(value = "size") int size, @RequestParam(value = "lastYear") boolean lastYear); @RequestMapping(value = Uris.RANKING_BEST_USER_FOR_TIMERANGE + "{timeRange}", method = RequestMethod.GET) List<TreeRankedUserData> getBestUserFromTimeRange(@PathVariable String timeRange); @RequestMapping(value = Uris.RANKING_BEST_USER_FOR_PROJECT, method = RequestMethod.GET) Page<TreeRankedUserData> getBestUserForProject(@Param(value = "projectName") String projectName, @Param(value = "page") int page, @Param(value = "size") int size); @RequestMapping(value = Uris.RANKING_BEST_TEAM_FOR_PROJECT, method = RequestMethod.GET) Page<TreeRankedUserData> getBestTeamsForProject(@Param(value = "projectName") String projectName, @Param(value = "page") int page, @Param(value = "size") int size); @RequestMapping(value = Uris.RANKING_LAST_PLANTED_TREES_IN_PROJECT, method = RequestMethod.GET) Page<TimeRankedTreeData> getLastPlantedTreesInProject(@Param(value = "projectName") String projectName, @Param(value = "page") int page, @Param(value = "size") int size);  }