use of org.motechproject.scheduler.contract.DayOfWeekSchedulableJob in project motech by motech.
the class TestEventListener method shouldScheduleDayOfWeekJob.
@Test
public void shouldScheduleDayOfWeekJob() throws SchedulerException {
try {
fakeNow(newDateTime(2020, 7, 15, 10, 0, 0));
Map<String, Object> params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
schedulerService.scheduleDayOfWeekJob(new DayOfWeekSchedulableJob(new MotechEvent("test_event", params), // friday
newDateTime(2020, 7, 10), newDateTime(2020, 7, 22), asList(DayOfWeek.Monday, DayOfWeek.Thursday), new Time(10, 10), false));
List<DateTime> fireTimes = getFireTimes("test_event-job_id");
assertEquals(asList(newDateTime(2020, 7, 13, 10, 10, 0), newDateTime(2020, 7, 16, 10, 10, 0), newDateTime(2020, 7, 20, 10, 10, 0)), fireTimes);
} finally {
stopFakingTime();
}
}
use of org.motechproject.scheduler.contract.DayOfWeekSchedulableJob in project motech by motech.
the class MotechSchedulerDatabaseServiceImplBundleIT method addTestJobs.
private void addTestJobs() {
Map<String, Object> params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id1");
// this job should be active
schedulerService.scheduleDayOfWeekJob(new DayOfWeekSchedulableJob(new MotechEvent("test_event_1", params), new DateTime(CURRENT_YEAR - 1, 3, 10, 0, 0), new DateTime(CURRENT_YEAR + 2, 3, 22, 0, 0), Arrays.asList(DayOfWeek.Monday, DayOfWeek.Thursday), new Time(10, 10), false));
params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id2");
schedulerService.scheduleDayOfWeekJob(new DayOfWeekSchedulableJob(new MotechEvent("test_event_2", params), new DateTime(CURRENT_YEAR + 1, 7, 10, 0, 0), new DateTime(CURRENT_YEAR + 3, 7, 22, 0, 0), Arrays.asList(DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday), new Time(10, 10), false));
params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id3");
schedulerService.scheduleDayOfWeekJob(new DayOfWeekSchedulableJob(new MotechEvent("test_event_3", params), new DateTime(CURRENT_YEAR + 4, 7, 10, 0, 0), new DateTime(CURRENT_YEAR + 5, 7, 22, 0, 0), Arrays.asList(DayOfWeek.Monday, DayOfWeek.Thursday), new Time(10, 10), false));
params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id4");
schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event_4", params), "0 0 12 * * ?"));
params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id5");
schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(new MotechEvent("test_event_5", params), newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0)));
params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id6");
schedulerService.scheduleRepeatingJob(new RepeatingSchedulableJob(new MotechEvent("test_event_6", params), DateTimeConstants.SECONDS_PER_DAY, newDateTime(CURRENT_YEAR + 4, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 4, 7, 18, 12, 0, 0), false));
}
use of org.motechproject.scheduler.contract.DayOfWeekSchedulableJob in project motech by motech.
the class SchedulableJobValidatorTest method shouldThrowIllegalArgumentExceptionIfTimeIsNull.
@Test(expected = IllegalArgumentException.class)
public void shouldThrowIllegalArgumentExceptionIfTimeIsNull() {
DayOfWeekSchedulableJob job = new DayOfWeekSchedulableJob(null, DateTime.now(), null, new ArrayList<>(), null, false, true);
SchedulableJobValidator.validateDayOfWeekSchedulableJob(job);
}
use of org.motechproject.scheduler.contract.DayOfWeekSchedulableJob in project motech by motech.
the class TestEventListener method shouldScheduleInterveningDayOfWeekJob.
@Test
public void shouldScheduleInterveningDayOfWeekJob() throws SchedulerException {
try {
fakeNow(newDateTime(2020, 7, 15, 10, 0, 0));
Map<String, Object> params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
schedulerService.scheduleDayOfWeekJob(new DayOfWeekSchedulableJob(new MotechEvent("test_event", params), // friday
newDateTime(2020, 7, 10), newDateTime(2020, 7, 22), asList(DayOfWeek.Monday, DayOfWeek.Thursday), new Time(10, 10), true));
List<DateTime> fireTimes = getFireTimes("test_event-job_id");
assertEquals(asList(newDateTime(2020, 7, 16, 10, 10, 0), newDateTime(2020, 7, 20, 10, 10, 0)), fireTimes);
} finally {
stopFakingTime();
}
}
use of org.motechproject.scheduler.contract.DayOfWeekSchedulableJob in project motech by motech.
the class SchedulableJobValidatorTest method shouldThrowIllegalArgumentExceptionIfDaysAreNull.
@Test(expected = IllegalArgumentException.class)
public void shouldThrowIllegalArgumentExceptionIfDaysAreNull() {
DayOfWeekSchedulableJob job = new DayOfWeekSchedulableJob(motechEvent, DateTime.now(), null, null, Time.valueOf("16:15"), false, true);
SchedulableJobValidator.validateDayOfWeekSchedulableJob(job);
}
Aggregations