Search in sources :

Example 11 with JobBasicInfo

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

the class JobsControllerTest method shouldGetJobsRecords.

@Test
public void shouldGetJobsRecords() throws SchedulerException, SQLException {
    List<JobBasicInfo> jobBasicInfos = getTestJobBasicInfos();
    JobsSearchSettings jobsSearchSettings = getDefaultGridSettings();
    when(motechSchedulerDatabaseService.getScheduledJobsBasicInfo(jobsSearchSettings)).thenReturn(jobBasicInfos);
    JobsRecords result = jobsController.retrieveJobInfo(jobsSearchSettings);
    assertEquals(jobBasicInfos, result.getRows());
    verify(motechSchedulerDatabaseService).getScheduledJobsBasicInfo(jobsSearchSettings);
}
Also used : JobsRecords(org.motechproject.scheduler.web.domain.JobsRecords) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) JobsSearchSettings(org.motechproject.scheduler.contract.JobsSearchSettings) Test(org.junit.Test)

Example 12 with JobBasicInfo

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

the class JobsController method retrieveJobInfo.

/**
 * Returns job information sorted and filtered as defined in {@code jobsGridSettings}.
 *
 * @param jobsSearchSettings  the setting by which returned records are sorted and filtered
 * @return sorted and filtered job records
 */
@RequestMapping(value = "/jobs", method = RequestMethod.GET)
@ResponseBody
public JobsRecords retrieveJobInfo(JobsSearchSettings jobsSearchSettings) throws SchedulerException, SQLException {
    List<JobBasicInfo> jobs = motechSchedulerDatabaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
    int rowCount = jobs.size() == 0 ? 0 : motechSchedulerDatabaseService.countJobs(jobsSearchSettings);
    if (jobsSearchSettings.getRows() == null) {
        int defaultRowsNumber = 10;
        jobsSearchSettings.setRows(defaultRowsNumber);
    }
    if (jobsSearchSettings.getPage() == null) {
        int defaultPage = 1;
        jobsSearchSettings.setPage(defaultPage);
    }
    previousJobsRecords = new JobsRecords(jobsSearchSettings.getPage(), jobsSearchSettings.getRows(), rowCount, jobs);
    return previousJobsRecords;
}
Also used : JobsRecords(org.motechproject.scheduler.web.domain.JobsRecords) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 13 with JobBasicInfo

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

the class TestEventListener method shouldNotResumeJobIfJobDoesNotExist.

@Test(expected = MotechSchedulerException.class)
public void shouldNotResumeJobIfJobDoesNotExist() throws Exception {
    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.resumeJob(info);
}
Also used : JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) Test(org.junit.Test)

Example 14 with JobBasicInfo

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

the class TestEventListener method shouldPauseJobIfItIsUiDefined.

@Test
public void shouldPauseJobIfItIsUiDefined() 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);
    assertEquals(NORMAL, scheduler.getTriggerState(triggerKey("test_event-job_id", "default")));
    schedulerService.pauseJob(info);
    assertEquals(PAUSED, 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 15 with JobBasicInfo

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

the class TestEventListener method shouldNotPauseJobIfJobDoesNotExist.

@Test(expected = MotechSchedulerException.class)
public void shouldNotPauseJobIfJobDoesNotExist() throws Exception {
    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.pauseJob(info);
}
Also used : JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) Test(org.junit.Test)

Aggregations

JobBasicInfo (org.motechproject.scheduler.contract.JobBasicInfo)24 Test (org.junit.Test)21 JobsSearchSettings (org.motechproject.scheduler.contract.JobsSearchSettings)11 HashMap (java.util.HashMap)10 MotechEvent (org.motechproject.event.MotechEvent)10 CronSchedulableJob (org.motechproject.scheduler.contract.CronSchedulableJob)8 JobKey (org.quartz.JobKey)4 ArrayList (java.util.ArrayList)3 RepeatingSchedulableJob (org.motechproject.scheduler.contract.RepeatingSchedulableJob)3 RunOnceSchedulableJob (org.motechproject.scheduler.contract.RunOnceSchedulableJob)3 JobsRecords (org.motechproject.scheduler.web.domain.JobsRecords)3 Period (org.joda.time.Period)2 RepeatingPeriodSchedulableJob (org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Before (org.junit.Before)1 JobDetailedInfo (org.motechproject.scheduler.contract.JobDetailedInfo)1 MotechSchedulerJobRetrievalException (org.motechproject.scheduler.exception.MotechSchedulerJobRetrievalException)1