Search in sources :

Example 6 with JobBasicInfo

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

the class MotechSchedulerDatabaseServiceImplBundleIT method shouldGetScheduledJobsBasicInfoWithSortingAndPagination.

@Test
public void shouldGetScheduledJobsBasicInfoWithSortingAndPagination() throws SchedulerException, SQLException {
    try {
        fakeNow(newDateTime(CURRENT_YEAR + 6, 7, 15, 10, 0, 0));
        Map<String, Object> params = new HashMap<>();
        params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
        schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event_2a", params), "0 0 12 * * ?"));
        schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(new MotechEvent("test_event_2b", params), newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0)));
        schedulerService.scheduleRepeatingJob(new RepeatingSchedulableJob(new MotechEvent("test_event_2c", params), DateTimeConstants.SECONDS_PER_DAY, newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 18, 12, 0, 0), false));
        JobBasicInfo expected = new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_OK, "test_event_2a-job_id", DEFAULT_GROUP, format("%s-07-15 10:00:00", CURRENT_YEAR + 6), format("%s-07-15 12:00:00", CURRENT_YEAR + 6), "-", JobBasicInfo.JOBTYPE_CRON, "", false);
        List<JobBasicInfo> jobBasicInfos;
        JobsSearchSettings jobsSearchSettings = getGridSettings(2, 2, "name", "desc");
        jobBasicInfos = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        assertEquals(expected.getActivity(), jobBasicInfos.get(0).getActivity());
        assertEquals(expected.getStatus(), jobBasicInfos.get(0).getStatus());
        assertEquals(expected.getStartDate(), jobBasicInfos.get(0).getStartDate());
        assertEquals(expected.getNextFireDate(), jobBasicInfos.get(0).getNextFireDate());
    } finally {
        stopFakingTime();
    }
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) JobsSearchSettings(org.motechproject.scheduler.contract.JobsSearchSettings) RunOnceSchedulableJob(org.motechproject.scheduler.contract.RunOnceSchedulableJob) Test(org.junit.Test)

Example 7 with JobBasicInfo

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

the class MotechSchedulerDatabaseServiceImplBundleIT method shouldFilterJobsByDate.

@Test
public void shouldFilterJobsByDate() {
    try {
        fakeNow(newDateTime(CURRENT_YEAR + 1, 7, 13, 5, 0, 0));
        addTestJobs();
        JobsSearchSettings jobsSearchSettings = getGridSettings(null, null, "name", "asc");
        jobsSearchSettings.setTimeTo(format("%s-03-15 9:30:00", CURRENT_YEAR + 7));
        jobsSearchSettings.setTimeFrom(format("%s-03-15 9:30:00", CURRENT_YEAR + 3));
        List<JobBasicInfo> jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        assertNotNull(jobs);
        assertEquals(3, jobs.size());
        assertEquals("test_event_3-job_id3", jobs.get(0).getName());
        assertEquals("test_event_5-job_id5-runonce", jobs.get(1).getName());
        assertEquals("test_event_6-job_id6-repeat", jobs.get(2).getName());
        jobsSearchSettings.setTimeTo(format("%s-03-15 9:30:00", CURRENT_YEAR + 5));
        jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        assertNotNull(jobs);
        assertEquals(2, jobs.size());
        jobsSearchSettings.setTimeFrom("");
        jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        assertNotNull(jobs);
        assertEquals(5, jobs.size());
    } finally {
        stopFakingTime();
    }
}
Also used : JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) JobsSearchSettings(org.motechproject.scheduler.contract.JobsSearchSettings) Test(org.junit.Test)

Example 8 with JobBasicInfo

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

the class MotechSchedulerDatabaseServiceImplBundleIT method shouldGetScheduledJobDetailedInfo.

@Test
public void shouldGetScheduledJobDetailedInfo() throws SchedulerException, SQLException {
    try {
        fakeNow(newDateTime(CURRENT_YEAR + 6, 7, 15, 10, 0, 0));
        JobDetailedInfo jobDetailedInfo = null;
        Map<String, Object> params = new HashMap<>();
        params.put(MotechSchedulerService.JOB_ID_KEY, "job_id_2");
        params.put("param1", "value1");
        params.put("param2", "value2");
        schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(new MotechEvent("test_event_2", params), newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0)));
        JobsSearchSettings jobsSearchSettings = getGridSettings(0, 10, "name", "asc");
        for (JobBasicInfo job : databaseService.getScheduledJobsBasicInfo(jobsSearchSettings)) {
            if (job.getName().equals("test_event_2-job_id_2-runonce")) {
                jobDetailedInfo = databaseService.getScheduledJobDetailedInfo(job);
            }
        }
        assertNotNull(jobDetailedInfo);
        assertEquals("test_event_2", jobDetailedInfo.getEventInfoList().get(0).getSubject());
        assertEquals(4, jobDetailedInfo.getEventInfoList().get(0).getParameters().size());
    } finally {
        stopFakingTime();
    }
}
Also used : JobDetailedInfo(org.motechproject.scheduler.contract.JobDetailedInfo) HashMap(java.util.HashMap) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) JobsSearchSettings(org.motechproject.scheduler.contract.JobsSearchSettings) RunOnceSchedulableJob(org.motechproject.scheduler.contract.RunOnceSchedulableJob) Test(org.junit.Test)

Example 9 with JobBasicInfo

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

the class JobsControllerTest method setUp.

@Before
public void setUp() {
    initMocks(this);
    testJobBasicInfo1 = new JobBasicInfo(JobBasicInfo.ACTIVITY_ACTIVE, JobBasicInfo.STATUS_OK, "myCronJobEvent-myJobIdKey_CronJob", DEFAULT_GROUP, "2002-01-01 00:00:00", "2010-01-01 00:00:00", "-", "Cron", "0 0 10 * * ?", false);
    testJobBasicInfo2 = new JobBasicInfo(JobBasicInfo.ACTIVITY_FINISHED, JobBasicInfo.STATUS_PAUSED, "myDayOfWeekEvent-myJobIdKey_DayOfWeek", DEFAULT_GROUP, "2001-01-01 00:00:00", "2010-01-01 00:00:00", "2011-01-01 00:00:00", "Cron", "0 10 12 ? * 4,5", false);
    testJobBasicInfo3 = new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_BLOCKED, "myRepeatingJobEvent-myJobIdKey_RepeatingJob-repeat", DEFAULT_GROUP, "2003-01-01 00:00:00", "2010-01-01 00:00:00", "2010-01-01 00:00:00", JobBasicInfo.JOBTYPE_REPEATING, "2 / 12", false);
    testJobBasicInfo4 = new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_ERROR, "myRunOnceEvent-myJobIdKey_RunOnce-runonce", DEFAULT_GROUP, "2004-01-01 00:00:00", "2010-01-01 00:00:00", "-", JobBasicInfo.JOBTYPE_RUNONCE, "-", false);
}
Also used : JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) Before(org.junit.Before)

Example 10 with JobBasicInfo

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

the class JobsControllerTest method shouldGetJobeDetailedInfo.

@Test
public void shouldGetJobeDetailedInfo() throws SchedulerException, SQLException {
    List<JobBasicInfo> jobBasicInfos = getTestJobBasicInfos();
    JobsSearchSettings jobsSearchSettings = getDefaultGridSettings();
    when(motechSchedulerDatabaseService.getScheduledJobsBasicInfo(jobsSearchSettings)).thenReturn(jobBasicInfos);
    jobsController.retrieveJobInfo(jobsSearchSettings);
    jobsController.retrieveJobDetailedInfo(testJobBasicInfo3);
    verify(motechSchedulerDatabaseService).getScheduledJobDetailedInfo(testJobBasicInfo3);
}
Also used : JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) JobsSearchSettings(org.motechproject.scheduler.contract.JobsSearchSettings) 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