Search in sources :

Example 6 with JobsSearchSettings

use of org.motechproject.scheduler.contract.JobsSearchSettings 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)

Example 7 with JobsSearchSettings

use of org.motechproject.scheduler.contract.JobsSearchSettings 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 8 with JobsSearchSettings

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

the class MotechSchedulerDatabaseServiceImplBundleIT method shouldFilterJobsWithSortingAndPagination.

@Test
public void shouldFilterJobsWithSortingAndPagination() {
    try {
        fakeNow(newDateTime(CURRENT_YEAR + 1, 7, 13, 10, 0, 0));
        addTestJobs();
        JobsSearchSettings jobsSearchSettings = getGridSettings(1, 5, "name", "asc");
        jobsSearchSettings.setName("event");
        List<JobBasicInfo> jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        assertNotNull(jobs);
        assertEquals(5, jobs.size());
        assertEquals(6, databaseService.countJobs(jobsSearchSettings));
        assertEquals(printJobNames(jobs), "test_event_1-job_id1", jobs.get(0).getName());
        jobsSearchSettings.setPage(2);
        jobsSearchSettings.setName("test");
        jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        assertNotNull(jobs);
        assertEquals(1, jobs.size());
        assertEquals(6, databaseService.countJobs(jobsSearchSettings));
        jobsSearchSettings.setPage(3);
        jobsSearchSettings.setRows(2);
        jobsSearchSettings.setSortDirection("desc");
        jobsSearchSettings.setActivity(JobBasicInfo.ACTIVITY_NOTSTARTED);
        jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        assertNotNull(jobs);
        assertEquals(1, jobs.size());
        assertEquals(JobBasicInfo.ACTIVITY_NOTSTARTED, jobs.get(0).getActivity());
        assertEquals(5, databaseService.countJobs(jobsSearchSettings));
        jobsSearchSettings = getGridSettings(1, 2, "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));
        jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        assertEquals(2, jobs.size());
        assertEquals(printJobNames(jobs), "test_event_3-job_id3", jobs.get(0).getName());
        assertEquals(3, databaseService.countJobs(jobsSearchSettings));
        jobsSearchSettings.setSortDirection("desc");
        jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        assertEquals(2, jobs.size());
        assertEquals(printJobNames(jobs), "test_event_6-job_id6-repeat", jobs.get(0).getName());
        assertEquals(3, databaseService.countJobs(jobsSearchSettings));
    } finally {
        stopFakingTime();
    }
}
Also used : JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) JobsSearchSettings(org.motechproject.scheduler.contract.JobsSearchSettings) Test(org.junit.Test)

Example 9 with JobsSearchSettings

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

the class MotechSchedulerDatabaseServiceImplBundleIT method shouldFilterJobsByActivity.

@Test
public void shouldFilterJobsByActivity() {
    try {
        fakeNow(newDateTime(CURRENT_YEAR + 1, 7, 13, 5, 0, 0));
        addTestJobs();
        JobsSearchSettings jobsSearchSettings = getGridSettings(null, null, "name", "asc");
        jobsSearchSettings.setActivity(JobBasicInfo.ACTIVITY_NOTSTARTED);
        List<JobBasicInfo> jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        assertNotNull(jobs);
        assertEquals(5, jobs.size());
        jobsSearchSettings.setActivity(JobBasicInfo.ACTIVITY_ACTIVE);
        jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        assertEquals(1, jobs.size());
    } finally {
        stopFakingTime();
    }
}
Also used : JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) JobsSearchSettings(org.motechproject.scheduler.contract.JobsSearchSettings) Test(org.junit.Test)

Example 10 with JobsSearchSettings

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

the class MotechSchedulerDatabaseServiceImplBundleIT method shouldGetScheduledJobsBasicInfo.

@Test
public void shouldGetScheduledJobsBasicInfo() 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_2", params), "0 0 12 * * ?"));
        schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(new MotechEvent("test_event_2", params), newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0)));
        schedulerService.scheduleRepeatingJob(new RepeatingSchedulableJob(new MotechEvent("test_event_2", params), DateTimeConstants.SECONDS_PER_DAY, newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 18, 12, 0, 0), false));
        schedulerService.scheduleRepeatingPeriodJob(new RepeatingPeriodSchedulableJob(new MotechEvent("test_event_2", params), newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 18, 12, 0, 0), new Period(4, 0, 0, 0), false));
        for (String groupName : scheduler.getJobGroupNames()) {
            for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
                if (jobKey.getName().equals("test_event_2-job_id")) {
                    scheduler.pauseJob(jobKey);
                }
            }
        }
        List<JobBasicInfo> expectedJobBasicInfos = new ArrayList<>();
        expectedJobBasicInfos.add(new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_PAUSED, "test_event_2-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));
        expectedJobBasicInfos.add(new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_OK, "test_event_2-job_id-runonce", DEFAULT_GROUP, format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-15 12:00:00", CURRENT_YEAR + 6), JobBasicInfo.JOBTYPE_RUNONCE, "", false));
        expectedJobBasicInfos.add(new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_OK, "test_event_2-job_id-repeat", DEFAULT_GROUP, format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-18 12:00:00", CURRENT_YEAR + 6), JobBasicInfo.JOBTYPE_REPEATING, "", false));
        expectedJobBasicInfos.add(new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_OK, "test_event_2-job_id-period", DEFAULT_GROUP, format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-18 12:00:00", CURRENT_YEAR + 6), JobBasicInfo.JOBTYPE_PERIOD, "", false));
        List<JobBasicInfo> jobBasicInfos;
        JobsSearchSettings jobsSearchSettings = getGridSettings(0, 10, "name", "asc");
        jobBasicInfos = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        int testJobsCount = 0;
        for (JobBasicInfo job : jobBasicInfos) {
            for (JobBasicInfo expectedJob : expectedJobBasicInfos) {
                if (job.getName().equals(expectedJob.getName())) {
                    testJobsCount += 1;
                    assertEquals(expectedJob.getActivity(), job.getActivity());
                    assertEquals(expectedJob.getStatus(), job.getStatus());
                    assertEquals(expectedJob.getStartDate(), job.getStartDate());
                    assertEquals(expectedJob.getNextFireDate(), job.getNextFireDate());
                }
            }
        }
        assertEquals(4, testJobsCount);
    } finally {
        stopFakingTime();
    }
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Period(org.joda.time.Period) JobsSearchSettings(org.motechproject.scheduler.contract.JobsSearchSettings) RunOnceSchedulableJob(org.motechproject.scheduler.contract.RunOnceSchedulableJob) JobKey(org.quartz.JobKey) RepeatingPeriodSchedulableJob(org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Aggregations

JobsSearchSettings (org.motechproject.scheduler.contract.JobsSearchSettings)13 Test (org.junit.Test)11 JobBasicInfo (org.motechproject.scheduler.contract.JobBasicInfo)11 HashMap (java.util.HashMap)3 MotechEvent (org.motechproject.event.MotechEvent)3 RunOnceSchedulableJob (org.motechproject.scheduler.contract.RunOnceSchedulableJob)3 CronSchedulableJob (org.motechproject.scheduler.contract.CronSchedulableJob)2 RepeatingSchedulableJob (org.motechproject.scheduler.contract.RepeatingSchedulableJob)2 JobsRecords (org.motechproject.scheduler.web.domain.JobsRecords)2 ArrayList (java.util.ArrayList)1 Period (org.joda.time.Period)1 JobDetailedInfo (org.motechproject.scheduler.contract.JobDetailedInfo)1 RepeatingPeriodSchedulableJob (org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob)1 JobKey (org.quartz.JobKey)1