JobResultsServiceImpl implements JobResultsService { public List<JobResult> getJobResults() { List<JobInstance> jobInstancesByJobName = jobExplorer.findJobInstancesByJobName(AbstractEmployeeJobConfig.EMPLOYEE_JOB, 0, Integer.MAX_VALUE); DateTime currentTime = new DateTime(); List<JobStartParams> months = getJobStartParamsPreviousMonths(currentTime.getYear(), currentTime.getMonthOfYear()); final Map<JobStartParams, JobResult> jobResultMap = getMapOfJobResultsForJobInstances(jobInstancesByJobName); List<JobResult> collect = months .stream() .map(mapJobStartParamsToJobResult(jobResultMap)) .sorted((comparing(onYear).thenComparing(comparing(onMonth))).reversed()) .collect(Collectors.toList()); return collect; }  List<JobResult> getJobResults(); List<JobStartParams> getJobStartParamsPreviousMonths(int year, int month); static final int NUMBER_OF_MONTHS; }
@Test public void testGetFinishedJobResults_DifferentDates_SortingIsDescOnYearAndMonth() throws Exception { JobInstance jobInstance1 = new JobInstance(1L, EmployeeJobConfigSingleJvm.EMPLOYEE_JOB); JobInstance jobInstance2 = new JobInstance(2L, EmployeeJobConfigSingleJvm.EMPLOYEE_JOB); List<JobInstance> jobInstances = asList(jobInstance1, jobInstance2); when(jobExplorer.findJobInstancesByJobName(EmployeeJobConfigSingleJvm.EMPLOYEE_JOB, 0, MAX_VALUE)) .thenReturn(jobInstances); JobExecution jobInstance1_jobExecution1 = createJobExecution(jobInstance1, createJobParameters(2014, 5)); when(jobExplorer.getJobExecutions(jobInstance1)).thenReturn(asList(jobInstance1_jobExecution1)); JobExecution jobInstance2_jobExecution1 = createJobExecution(jobInstance2, createJobParameters(2013, 6)); JobExecution jobInstance2_jobExecution2 = createJobExecution(jobInstance2, createJobParameters(2013, 6)); when(jobExplorer.getJobExecutions(jobInstance2)).thenReturn(asList(jobInstance2_jobExecution1, jobInstance2_jobExecution2)); List<JobResult> jobResults = jobResultsService.getJobResults(); verify(jobExplorer).findJobInstancesByJobName(EmployeeJobConfigSingleJvm.EMPLOYEE_JOB, 0, MAX_VALUE); verify(jobExplorer).getJobExecutions(jobInstance1); verify(jobExplorer).getJobExecutions(jobInstance2); assertThat(jobResults).hasSize(6); }
@Test public void testGetFinishedJobResults_SameDates_SortingIsDescOnDate() throws Exception { JobInstance jobInstance1 = new JobInstance(1L, EmployeeJobConfigSingleJvm.EMPLOYEE_JOB); when(jobExplorer.findJobInstancesByJobName(EmployeeJobConfigSingleJvm.EMPLOYEE_JOB, 0, MAX_VALUE)) .thenReturn(asList(jobInstance1)); DateTime dateTime = new DateTime(); JobExecution jobInstance1_jobExecution1 = new JobExecution(jobInstance1, 1L, createJobParameters(dateTime.getYear(), dateTime.getMonthOfYear()), null); jobInstance1_jobExecution1.setEndTime(getDateOfDay(3)); JobExecution jobInstance1_jobExecution2 = new JobExecution(jobInstance1, 2L, createJobParameters(dateTime.getYear(), dateTime.getMonthOfYear()), null); jobInstance1_jobExecution2.setEndTime(getDateOfDay(4)); when(jobExplorer.getJobExecutions(jobInstance1)).thenReturn(asList(jobInstance1_jobExecution1, jobInstance1_jobExecution2)); List<JobResult> jobResults = jobResultsService.getJobResults(); assertThat(jobResults.get(0).getJobExecutionResults().get(0).getEndTime()).isAfter(jobResults.get(0).getJobExecutionResults().get(1).getEndTime()); }
@Test public void testGetJobResults_Returns_Last6Months() { List<JobResult> jobResults = jobResultsService.getJobResults(); assertThat(jobResults).hasSize(6); }