Search in sources :

Example 1 with DayOfWeekSchedulableJob

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();
    }
}
Also used : HashMap(java.util.HashMap) DayOfWeekSchedulableJob(org.motechproject.scheduler.contract.DayOfWeekSchedulableJob) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) Time(org.motechproject.commons.date.model.Time) DateTime(org.joda.time.DateTime) TimeFaker.stopFakingTime(org.motechproject.testing.utils.TimeFaker.stopFakingTime) MotechEvent(org.motechproject.event.MotechEvent) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 2 with DayOfWeekSchedulableJob

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));
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) DayOfWeekSchedulableJob(org.motechproject.scheduler.contract.DayOfWeekSchedulableJob) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) Time(org.motechproject.commons.date.model.Time) DateTime(org.joda.time.DateTime) TimeFaker.stopFakingTime(org.motechproject.testing.utils.TimeFaker.stopFakingTime) MotechEvent(org.motechproject.event.MotechEvent) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) DateTime(org.joda.time.DateTime) RunOnceSchedulableJob(org.motechproject.scheduler.contract.RunOnceSchedulableJob)

Example 3 with DayOfWeekSchedulableJob

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);
}
Also used : DayOfWeekSchedulableJob(org.motechproject.scheduler.contract.DayOfWeekSchedulableJob) Test(org.junit.Test)

Example 4 with DayOfWeekSchedulableJob

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();
    }
}
Also used : HashMap(java.util.HashMap) DayOfWeekSchedulableJob(org.motechproject.scheduler.contract.DayOfWeekSchedulableJob) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) Time(org.motechproject.commons.date.model.Time) DateTime(org.joda.time.DateTime) TimeFaker.stopFakingTime(org.motechproject.testing.utils.TimeFaker.stopFakingTime) MotechEvent(org.motechproject.event.MotechEvent) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 5 with DayOfWeekSchedulableJob

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);
}
Also used : DayOfWeekSchedulableJob(org.motechproject.scheduler.contract.DayOfWeekSchedulableJob) Test(org.junit.Test)

Aggregations

DayOfWeekSchedulableJob (org.motechproject.scheduler.contract.DayOfWeekSchedulableJob)10 Test (org.junit.Test)7 DateTime (org.joda.time.DateTime)4 Time (org.motechproject.commons.date.model.Time)4 MotechEvent (org.motechproject.event.MotechEvent)4 HashMap (java.util.HashMap)3 DateUtil.newDateTime (org.motechproject.commons.date.util.DateUtil.newDateTime)3 TimeFaker.stopFakingTime (org.motechproject.testing.utils.TimeFaker.stopFakingTime)3 DayOfWeek (org.motechproject.commons.date.model.DayOfWeek)1 CronSchedulableJob (org.motechproject.scheduler.contract.CronSchedulableJob)1 RepeatingSchedulableJob (org.motechproject.scheduler.contract.RepeatingSchedulableJob)1 RunOnceSchedulableJob (org.motechproject.scheduler.contract.RunOnceSchedulableJob)1 CronExpressionUtil (org.motechproject.scheduler.util.CronExpressionUtil)1 CronTrigger (org.quartz.CronTrigger)1