use of org.motechproject.scheduler.contract.JobBasicInfo in project motech by motech.
the class MotechSchedulerDatabaseServiceImplBundleIT method shouldGetScheduledJobsBasicInfo.
@Test
public void shouldGetScheduledJobsBasicInfo() throws SchedulerException, SQLException {
try {
fakeNow(newDateTime(CURRENT_YEAR + 6, 7, 15, 10, 0, 0));
Map<String, Object> params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event_2", params), "0 0 12 * * ?"));
schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(new MotechEvent("test_event_2", params), newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0)));
schedulerService.scheduleRepeatingJob(new RepeatingSchedulableJob(new MotechEvent("test_event_2", params), DateTimeConstants.SECONDS_PER_DAY, newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 18, 12, 0, 0), false));
schedulerService.scheduleRepeatingPeriodJob(new RepeatingPeriodSchedulableJob(new MotechEvent("test_event_2", params), newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 18, 12, 0, 0), new Period(4, 0, 0, 0), false));
for (String groupName : scheduler.getJobGroupNames()) {
for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
if (jobKey.getName().equals("test_event_2-job_id")) {
scheduler.pauseJob(jobKey);
}
}
}
List<JobBasicInfo> expectedJobBasicInfos = new ArrayList<>();
expectedJobBasicInfos.add(new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_PAUSED, "test_event_2-job_id", DEFAULT_GROUP, format("%s-07-15 10:00:00", CURRENT_YEAR + 6), format("%s-07-15 12:00:00", CURRENT_YEAR + 6), "-", JobBasicInfo.JOBTYPE_CRON, "", false));
expectedJobBasicInfos.add(new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_OK, "test_event_2-job_id-runonce", DEFAULT_GROUP, format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-15 12:00:00", CURRENT_YEAR + 6), JobBasicInfo.JOBTYPE_RUNONCE, "", false));
expectedJobBasicInfos.add(new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_OK, "test_event_2-job_id-repeat", DEFAULT_GROUP, format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-18 12:00:00", CURRENT_YEAR + 6), JobBasicInfo.JOBTYPE_REPEATING, "", false));
expectedJobBasicInfos.add(new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_OK, "test_event_2-job_id-period", DEFAULT_GROUP, format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-18 12:00:00", CURRENT_YEAR + 6), JobBasicInfo.JOBTYPE_PERIOD, "", false));
List<JobBasicInfo> jobBasicInfos;
JobsSearchSettings jobsSearchSettings = getGridSettings(0, 10, "name", "asc");
jobBasicInfos = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
int testJobsCount = 0;
for (JobBasicInfo job : jobBasicInfos) {
for (JobBasicInfo expectedJob : expectedJobBasicInfos) {
if (job.getName().equals(expectedJob.getName())) {
testJobsCount += 1;
assertEquals(expectedJob.getActivity(), job.getActivity());
assertEquals(expectedJob.getStatus(), job.getStatus());
assertEquals(expectedJob.getStartDate(), job.getStartDate());
assertEquals(expectedJob.getNextFireDate(), job.getNextFireDate());
}
}
}
assertEquals(4, testJobsCount);
} finally {
stopFakingTime();
}
}
use of org.motechproject.scheduler.contract.JobBasicInfo in project motech by motech.
the class MotechSchedulerDatabaseServiceImplBundleIT method shouldReturnAllJobsWhenNoFiltersSet.
@Test
public void shouldReturnAllJobsWhenNoFiltersSet() {
try {
fakeNow(newDateTime(CURRENT_YEAR + 1, 7, 13, 5, 0, 0));
addTestJobs();
JobsSearchSettings jobsSearchSettings = new JobsSearchSettings();
List<JobBasicInfo> jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
assertNotNull(jobs);
assertEquals(6, jobs.size());
} finally {
stopFakingTime();
}
}
use of org.motechproject.scheduler.contract.JobBasicInfo in project motech by motech.
the class MotechSchedulerDatabaseServiceImplBundleIT method shouldFilterJobsByName.
@Test
public void shouldFilterJobsByName() {
try {
fakeNow(newDateTime(CURRENT_YEAR + 1, 7, 13, 5, 0, 0));
addTestJobs();
JobsSearchSettings jobsSearchSettings = getGridSettings(null, null, "name", "asc");
jobsSearchSettings.setName("id1");
List<JobBasicInfo> jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
assertNotNull(jobs);
assertEquals(1, jobs.size());
assertEquals(jobs.get(0).getName(), "test_event_1-job_id1");
int rowCount = databaseService.countJobs(jobsSearchSettings);
assertEquals(1, rowCount);
jobsSearchSettings.setName("test_ev");
jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
assertNotNull(jobs);
assertEquals(6, jobs.size());
rowCount = databaseService.countJobs(jobsSearchSettings);
assertEquals(6, rowCount);
jobsSearchSettings.setName("test_event_2-job_id2");
jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
assertNotNull(jobs);
assertEquals(1, jobs.size());
assertEquals(jobs.get(0).getName(), "test_event_2-job_id2");
rowCount = databaseService.countJobs(jobsSearchSettings);
assertEquals(1, rowCount);
} finally {
stopFakingTime();
}
}
use of org.motechproject.scheduler.contract.JobBasicInfo in project motech by motech.
the class JobsControllerTest method shouldGetAllJobsRecordsWhenNoFiltersSet.
@Test
public void shouldGetAllJobsRecordsWhenNoFiltersSet() throws SchedulerException, SQLException {
List<JobBasicInfo> jobBasicInfos = getTestJobBasicInfos();
JobsSearchSettings jobsSearchSettings = new JobsSearchSettings();
when(motechSchedulerDatabaseService.getScheduledJobsBasicInfo(jobsSearchSettings)).thenReturn(jobBasicInfos);
JobsRecords result = jobsController.retrieveJobInfo(jobsSearchSettings);
assertEquals(jobBasicInfos, result.getRows());
verify(motechSchedulerDatabaseService).getScheduledJobsBasicInfo(jobsSearchSettings);
}
Aggregations