Search in sources :

Example 11 with CronSchedulableJob

use of org.motechproject.scheduler.contract.CronSchedulableJob in project motech by motech.

the class SchedulableJobValidatorTest method shouldThrowIllegalArgumentExceptionIfCronExpressionIsNull.

@Test(expected = IllegalArgumentException.class)
public void shouldThrowIllegalArgumentExceptionIfCronExpressionIsNull() {
    CronSchedulableJob job = new CronSchedulableJob(motechEvent, null, DateTime.now().plusHours(1), null, false, true);
    SchedulableJobValidator.validateCronSchedulableJob(job);
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) Test(org.junit.Test)

Example 12 with CronSchedulableJob

use of org.motechproject.scheduler.contract.CronSchedulableJob in project motech by motech.

the class SchedulableJobValidatorTest method shouldThrowIllegalArgumentExceptionIfCronExpressionIsEmpty.

@Test(expected = IllegalArgumentException.class)
public void shouldThrowIllegalArgumentExceptionIfCronExpressionIsEmpty() {
    CronSchedulableJob job = new CronSchedulableJob(motechEvent, "", DateTime.now().plusHours(1), null, false, true);
    SchedulableJobValidator.validateCronSchedulableJob(job);
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) Test(org.junit.Test)

Example 13 with CronSchedulableJob

use of org.motechproject.scheduler.contract.CronSchedulableJob in project motech by motech.

the class SchedulableJobValidatorTest method shouldThrowIllegalArgumentExceptionIfMotechEventIsNullInCronSchedulableJob.

@Test(expected = IllegalArgumentException.class)
public void shouldThrowIllegalArgumentExceptionIfMotechEventIsNullInCronSchedulableJob() {
    CronSchedulableJob job = new CronSchedulableJob(null, "0 0 0 * * ? *", DateTime.now().plusHours(1), null, false, true);
    SchedulableJobValidator.validateCronSchedulableJob(job);
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) Test(org.junit.Test)

Example 14 with CronSchedulableJob

use of org.motechproject.scheduler.contract.CronSchedulableJob in project motech by motech.

the class TestCronSchedulabeJob method equalsTest.

@Test
public void equalsTest() throws Exception {
    String cron1 = "0/5 0 * * * ?";
    String cron2 = "5 0 * * * ?";
    CronSchedulableJob job1 = new CronSchedulableJob(motechEvent1, cron1);
    CronSchedulableJob job1Same = new CronSchedulableJob(motechEvent1, cron1);
    CronSchedulableJob job2 = new CronSchedulableJob(motechEvent2, cron1);
    CronSchedulableJob job3 = new CronSchedulableJob(motechEvent1, cron2);
    assertTrue(job1.equals(job1));
    assertTrue(job1.equals(job1Same));
    assertFalse(job1.equals(null));
    assertFalse(job1.equals(motechEvent1));
    // Same date, different event
    assertFalse(job1.equals(job2));
    // Same event different date
    assertFalse(job1.equals(job3));
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) Test(org.junit.Test)

Example 15 with CronSchedulableJob

use of org.motechproject.scheduler.contract.CronSchedulableJob in project motech by motech.

the class MotechScheduler method scheduleTestEvent.

private static void scheduleTestEvent() {
    Map<String, Object> params = new HashMap<>();
    params.put(MotechSchedulerService.JOB_ID_KEY, TEST_EVENT_NAME);
    MotechEvent motechEvent = new MotechEvent(TEST_SUBJECT, params);
    CronSchedulableJob cronSchedulableJob = new CronSchedulableJob(motechEvent, TEST_CRON_EXPRESSION);
    try {
        LOGGER.info("Scheduling test job: " + cronSchedulableJob);
        schedulerService.scheduleJob(cronSchedulableJob);
    } catch (RuntimeException e) {
        LOGGER.warn("Can not schedule test job.", e);
    }
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent)

Aggregations

CronSchedulableJob (org.motechproject.scheduler.contract.CronSchedulableJob)33 MotechEvent (org.motechproject.event.MotechEvent)27 Test (org.junit.Test)25 HashMap (java.util.HashMap)24 DateTime (org.joda.time.DateTime)10 DateUtil.newDateTime (org.motechproject.commons.date.util.DateUtil.newDateTime)10 JobBasicInfo (org.motechproject.scheduler.contract.JobBasicInfo)8 RepeatingSchedulableJob (org.motechproject.scheduler.contract.RepeatingSchedulableJob)4 RunOnceSchedulableJob (org.motechproject.scheduler.contract.RunOnceSchedulableJob)4 JobKey (org.quartz.JobKey)3 Time (org.motechproject.commons.date.model.Time)2 CronJobId (org.motechproject.scheduler.contract.CronJobId)2 JobsSearchSettings (org.motechproject.scheduler.contract.JobsSearchSettings)2 ArrayList (java.util.ArrayList)1 Period (org.joda.time.Period)1 Before (org.junit.Before)1 DayOfWeekSchedulableJob (org.motechproject.scheduler.contract.DayOfWeekSchedulableJob)1 RepeatingPeriodSchedulableJob (org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob)1 SchedulableJobValidator.validateCronSchedulableJob (org.motechproject.scheduler.validation.SchedulableJobValidator.validateCronSchedulableJob)1 TimeFaker.stopFakingTime (org.motechproject.testing.utils.TimeFaker.stopFakingTime)1