JobManager implements ModeChangeListener { public List<AsyncJobStatus> findJobs(AsyncJobStatusQueryBuilder queryBuilder) { return this.jobCurator.findJobs(queryBuilder); } @Inject  JobManager(
        Configuration configuration,
        SchedulerFactory schedulerFactory,
        CandlepinModeManager modeManager,
        AsyncJobStatusCurator jobCurator,
        OwnerCurator ownerCurator,
        JobMessageDispatcher dispatcher,
        JobMessageReceiver receiver,
        PrincipalProvider principalProvider,
        CandlepinRequestScope scope,
        Injector injector); static Class<? extends AsyncJob> registerJob(String jobKey, Class<? extends AsyncJob> jobClass); static Class<? extends AsyncJob> unregisterJob(String jobKey); static Class<? extends AsyncJob> getJobClass(String jobKey); synchronized void initialize(); void start(); synchronized void start(Object key); void resume(); void resume(Object key); void suspend(); synchronized void suspend(Object key); synchronized void shutdown(); synchronized ManagerState getManagerState(); boolean isJobEnabled(String jobKey); boolean isSchedulerEnabled(); AsyncJobStatus findJob(String jobId); List<AsyncJobStatus> findJobs(AsyncJobStatusQueryBuilder queryBuilder); @Transactional AsyncJobStatus queueJob(JobConfig config); AsyncJobStatus executeJob(JobMessage message); @Transactional AsyncJobStatus cancelJob(String jobId); @Transactional int cleanupJobs(AsyncJobStatusQueryBuilder queryBuilder); @Transactional int abortNonTerminalJobs(AsyncJobStatusQueryBuilder queryBuilder); @Override void handleModeChange(CandlepinModeManager modeManager, Mode previousMode, Mode currentMode);  }
@Test public void testFindJobs() { AsyncJobStatus status1 = this.createJobStatus("test_job-1"); AsyncJobStatus status2 = this.createJobStatus("test_job-2"); AsyncJobStatus status3 = this.createJobStatus("test_job-3"); List<AsyncJobStatus> expected = Arrays.asList(status1, status2, status3); Set<String> jobKeys = Util.asSet("job_key-1", "job_key-2", "job_key-3"); Set<JobState> jobStates = Util.asSet(JobState.QUEUED, JobState.RUNNING, JobState.FINISHED); Set<String> ownerIds = Util.asSet("owner-1", "owner-2", "owner-3"); Date start = Util.yesterday(); Date end = Util.tomorrow(); AsyncJobStatusQueryBuilder input = new AsyncJobStatusQueryBuilder() .setJobKeys(jobKeys) .setJobStates(jobStates) .setOwnerIds(ownerIds) .setStartDate(start) .setEndDate(end); ArgumentCaptor<AsyncJobStatusQueryBuilder> captor = ArgumentCaptor.forClass(AsyncJobStatusQueryBuilder.class); doReturn(expected).when(this.jobCurator).findJobs(eq(input)); JobManager manager = this.createJobManager(); List<AsyncJobStatus> output = manager.findJobs(input); assertNotNull(output); assertEquals(expected, output); verify(this.jobCurator, times(1)).findJobs(captor.capture()); AsyncJobStatusQueryBuilder captured = captor.getValue(); assertNotNull(captured); assertEquals(input, captured); }
@Test public void testFindJobsHandlesNull() { AsyncJobStatus status1 = this.createJobStatus("test_job-1"); AsyncJobStatus status2 = this.createJobStatus("test_job-2"); AsyncJobStatus status3 = this.createJobStatus("test_job-3"); List<AsyncJobStatus> expected = Arrays.asList(status1, status2, status3); ArgumentCaptor<AsyncJobStatusQueryBuilder> captor = ArgumentCaptor.forClass(AsyncJobStatusQueryBuilder.class); doReturn(expected).when(this.jobCurator).findJobs(eq(null)); JobManager manager = this.createJobManager(); List<AsyncJobStatus> output = manager.findJobs(null); assertNotNull(output); assertEquals(expected, output); verify(this.jobCurator, times(1)).findJobs(captor.capture()); AsyncJobStatusQueryBuilder captured = captor.getValue(); assertNull(captured); }