JobStatusCalculator { public StatusDetail statusDetail(final JobDefinition jobDefinition) { try { final List<JobInfo> jobs = jobRepository.findLatestBy(jobDefinition.jobType(), numberOfJobs + 1); return jobs.isEmpty() ? statusDetailWhenNoJobAvailable(jobDefinition) : toStatusDetail(jobs, jobDefinition); } catch (final Exception e) { LOG.error(LOAD_JOBS_EXCEPTION_MESSAGE + ": " + e.getMessage(), e); return StatusDetail.statusDetail(jobDefinition.jobName(), ERROR, LOAD_JOBS_EXCEPTION_MESSAGE); } } JobStatusCalculator(final String key,
                               final int numberOfJobs,
                               final int maxFailedJobs,
                               final JobRepository jobRepository,
                               final JobMetaRepository jobMetaRepository,
                               final String managementContextPath); static JobStatusCalculator warningOnLastJobFailed(final String key,
                                                             final JobRepository jobRepository,
                                                             final JobMetaRepository jobMetaRepository,
                                                             final String managementContextPath); static JobStatusCalculator errorOnLastJobFailed(final String key,
                                                           final JobRepository jobRepository,
                                                           final JobMetaRepository jobMetaRepository,
                                                           final String managementContextPath); static JobStatusCalculator errorOnLastNumJobsFailed(final String key,
                                                               final int numJobs,
                                                               final JobRepository jobRepository,
                                                               final JobMetaRepository jobMetaRepository,
                                                               final String managementContextPath
    ); String getKey(); StatusDetail statusDetail(final JobDefinition jobDefinition); JobMeta getJobMeta(final String jobType);  }
@Test public void shouldAcceptIfNoJobRan() { when(jobRepository.findLatestBy(anyString(), eq(1+1))).thenReturn(emptyList()); final StatusDetail statusDetail = errorOnLastJobFailed.statusDetail(jobDefinition); assertThat(statusDetail.getStatus(), is(Status.OK)); }
@Test public void shouldHaveName() { final List<JobInfo> jobInfos = singletonList(someStoppedJob(OK, 1)); when(jobRepository.findLatestBy(anyString(), eq(1+1))).thenReturn(jobInfos); final StatusDetail statusDetail = errorOnLastJobFailed.statusDetail(jobDefinition); assertThat(statusDetail.getName(), is("test")); }