Search in sources :

Example 81 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class TestEventListener method shouldDeleteJobIfItIsUiDefined.

@Test
public void shouldDeleteJobIfItIsUiDefined() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
    JobBasicInfo info = new JobBasicInfo(JobBasicInfo.ACTIVITY_ACTIVE, JobBasicInfo.STATUS_OK, "test_event-job_id", "default", "start-time", "nex-fire-time", "end-time", JobBasicInfo.JOBTYPE_CRON, "test-info", false);
    CronSchedulableJob job = new CronSchedulableJob(new MotechEvent("test_event", params), "0 0 12 * * ?");
    job.setUiDefined(true);
    schedulerService.scheduleJob(job);
    schedulerService.deleteJob(info);
    assertNull(scheduler.getTrigger(triggerKey("test_event-job_id", "default")));
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 82 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class TestEventListener method shouldUnscheduleAllJobsWithAGivenJobIdPrefix.

@Test
public void shouldUnscheduleAllJobsWithAGivenJobIdPrefix() throws SchedulerException {
    Map<String, Object> params = new HashMap<>();
    params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
    schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event1", params), "0 0 12 * * ?"));
    schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event2", params), "0 0 13 * * ?"));
    schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event3", params), "0 0 14 * * ?"));
    schedulerService.unscheduleAllJobs("test_event");
    assertNull(scheduler.getTrigger(triggerKey("test_event1-job_id", "default")));
    assertNull(scheduler.getTrigger(triggerKey("test_event2-job_id", "default")));
    assertNull(scheduler.getTrigger(triggerKey("test_event3-job_id", "default")));
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 83 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class TestEventListener method shouldThrowExceptionForNullStartTime.

@Test(expected = IllegalArgumentException.class)
public void shouldThrowExceptionForNullStartTime() throws SchedulerException {
    Map<String, Object> params = new HashMap<>();
    params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
    schedulerService.scheduleRepeatingJob(new RepeatingSchedulableJob(new MotechEvent("test_event", params), DateTimeConstants.SECONDS_PER_DAY, null, newDateTime(2020, 7, 18, 12, 0, 0), false));
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 84 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class TestEventListener method shouldNotPauseJobIfItIsNotUiDefined.

@Test(expected = MotechSchedulerException.class)
public void shouldNotPauseJobIfItIsNotUiDefined() throws Exception {
    try {
        Map<String, Object> params = new HashMap<>();
        params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
        JobBasicInfo info = new JobBasicInfo(JobBasicInfo.ACTIVITY_ACTIVE, JobBasicInfo.STATUS_OK, "test_event-job_id", "default", "start-time", "nex-fire-time", "end-time", JobBasicInfo.JOBTYPE_CRON, "test-info", true);
        schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event", params), "0 0 12 * * ?"));
        assertEquals(NORMAL, scheduler.getTriggerState(triggerKey("test_event-job_id", "default")));
        schedulerService.pauseJob(info);
    } finally {
        assertEquals(NORMAL, scheduler.getTriggerState(triggerKey("test_event-job_id", "default")));
    }
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 85 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class SettingsServiceImpl method saveBundleSettings.

@Override
public void saveBundleSettings(Settings settings, long bundleId) throws IOException {
    Properties props = ParamParser.constructProperties(settings);
    configurationService.addOrUpdateProperties(getBundleSymbolicName(bundleId), getVersion(bundleId), settings.getSection(), props, getBundleDefaultProperties(bundleId).get(settings.getSection()));
    Map<String, Object> params = new HashMap<>();
    params.put(ConfigurationConstants.BUNDLE_ID, bundleId);
    params.put(ConfigurationConstants.BUNDLE_SYMBOLIC_NAME, getBundleSymbolicName(bundleId));
    params.put(ConfigurationConstants.BUNDLE_SECTION, settings.getSection());
    MotechEvent bundleSettingsChangedEvent = new MotechEvent(ConfigurationConstants.BUNDLE_SETTINGS_CHANGED_EVENT_SUBJECT, params);
    eventRelay.sendEventMessage(bundleSettingsChangedEvent);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Properties(java.util.Properties) MotechEvent(org.motechproject.event.MotechEvent)

Aggregations

MotechEvent (org.motechproject.event.MotechEvent)138 Test (org.junit.Test)87 HashMap (java.util.HashMap)79 CronSchedulableJob (org.motechproject.scheduler.contract.CronSchedulableJob)28 DateTime (org.joda.time.DateTime)25 DateUtil.newDateTime (org.motechproject.commons.date.util.DateUtil.newDateTime)20 ArrayList (java.util.ArrayList)14 RepeatingSchedulableJob (org.motechproject.scheduler.contract.RepeatingSchedulableJob)13 RunOnceSchedulableJob (org.motechproject.scheduler.contract.RunOnceSchedulableJob)11 JobBasicInfo (org.motechproject.scheduler.contract.JobBasicInfo)10 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)8 Matchers.anyString (org.mockito.Matchers.anyString)7 EventListener (org.motechproject.event.listener.EventListener)7 CronJobId (org.motechproject.scheduler.contract.CronJobId)7 Task (org.motechproject.tasks.domain.mds.task.Task)7 JobId (org.motechproject.scheduler.contract.JobId)6 RepeatingJobId (org.motechproject.scheduler.contract.RepeatingJobId)6 Time (org.motechproject.commons.date.model.Time)5 DayOfWeekSchedulableJob (org.motechproject.scheduler.contract.DayOfWeekSchedulableJob)5 RepeatingPeriodSchedulableJob (org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob)5