Search in sources :

Example 1 with CronJobTrigger

use of org.pentaho.platform.api.scheduler2.CronJobTrigger in project pentaho-platform by pentaho.

the class RepositoryCleanerSystemListenerTest method reschedulesJob_IfFoundDifferent.

@Test
public void reschedulesJob_IfFoundDifferent() throws Exception {
    final String oldJobId = "oldJobId";
    Job oldJob = new Job();
    oldJob.setJobTrigger(new CronJobTrigger());
    oldJob.setJobId(oldJobId);
    when(scheduler.getJobs(any(IJobFilter.class))).thenReturn(Collections.singletonList(oldJob));
    prepareMp();
    listener.setExecute(Frequency.NOW.getValue());
    assertTrue(listener.startup(null));
    verifyJobRemoved(oldJobId);
    verifyJobCreated(Frequency.NOW);
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) Job(org.pentaho.platform.api.scheduler2.Job) CronJobTrigger(org.pentaho.platform.api.scheduler2.CronJobTrigger) Test(org.junit.Test)

Example 2 with CronJobTrigger

use of org.pentaho.platform.api.scheduler2.CronJobTrigger in project pentaho-platform by pentaho.

the class SchedulerResourceUtilTest method testConvertScheduleRequestToJobTrigger_CronString.

@Test
public void testConvertScheduleRequestToJobTrigger_CronString() throws Exception {
    cron = new CronJobTrigger();
    cron.setCronString("0 45 16 ? * 2#4,2L,6#4,6L *");
    cron.setDuration(200000);
    cron.setStartTime(now);
    cron.setUiPassParam("param");
    cron.setEndTime(now);
    when(scheduleRequest.getCronJobTrigger()).thenReturn(cron);
    IJobTrigger trigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger(scheduleRequest, scheduler);
    assertTrue(trigger instanceof ComplexJobTrigger);
    ComplexJobTrigger trig = (ComplexJobTrigger) trigger;
    assertEquals(now, trig.getStartTime());
    assertEquals(now, trig.getEndTime());
    assertEquals(200000, trig.getDuration());
    assertEquals("param", trig.getUiPassParam());
    List<ITimeRecurrence> recurrences = trig.getDayOfWeekRecurrences().getRecurrences();
    assertEquals(4, recurrences.size());
    QualifiedDayOfWeek rec = (QualifiedDayOfWeek) recurrences.get(0);
    assertEquals("MON", rec.getDayOfWeek().toString());
    assertEquals("FOURTH", rec.getQualifier().toString());
    rec = (QualifiedDayOfWeek) recurrences.get(1);
    assertEquals("MON", rec.getDayOfWeek().toString());
    assertEquals("LAST", rec.getQualifier().toString());
    rec = (QualifiedDayOfWeek) recurrences.get(2);
    assertEquals("FRI", rec.getDayOfWeek().toString());
    assertEquals("FOURTH", rec.getQualifier().toString());
    rec = (QualifiedDayOfWeek) recurrences.get(3);
    assertEquals("FRI", rec.getDayOfWeek().toString());
    assertEquals("LAST", rec.getQualifier().toString());
}
Also used : QualifiedDayOfWeek(org.pentaho.platform.scheduler2.recur.QualifiedDayOfWeek) ITimeRecurrence(org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) CronJobTrigger(org.pentaho.platform.api.scheduler2.CronJobTrigger) Test(org.junit.Test)

Example 3 with CronJobTrigger

use of org.pentaho.platform.api.scheduler2.CronJobTrigger in project pentaho-platform by pentaho.

the class SchedulerResourceUtilTest method testUpdateStartDateForTimeZone_cron.

@Test
public void testUpdateStartDateForTimeZone_cron() throws Exception {
    CronJobTrigger t = new CronJobTrigger();
    t.setStartTime(now);
    when(scheduleRequest.getCronJobTrigger()).thenReturn(t);
    when(scheduleRequest.getTimeZone()).thenReturn("GMT");
    long gmtTime = now.getTime() + TimeZone.getTimeZone("EST").getRawOffset();
    SchedulerResourceUtil.updateStartDateForTimeZone(scheduleRequest);
    assertEquals(gmtTime, scheduleRequest.getCronJobTrigger().getStartTime().getTime());
}
Also used : CronJobTrigger(org.pentaho.platform.api.scheduler2.CronJobTrigger) Test(org.junit.Test)

Example 4 with CronJobTrigger

use of org.pentaho.platform.api.scheduler2.CronJobTrigger in project pentaho-platform by pentaho.

the class ScheduleExportUtilTest method testCreateJobScheduleRequest_MultipleTypesJobParam.

@Test
public void testCreateJobScheduleRequest_MultipleTypesJobParam() throws Exception {
    String jobName = "JOB";
    Long l = Long.MAX_VALUE;
    Date d = new Date();
    Boolean b = true;
    Map<String, Serializable> params = new HashMap<>();
    params.put("NumberValue", l);
    params.put("DateValue", d);
    params.put("BooleanValue", b);
    Job job = mock(Job.class);
    CronJobTrigger trigger = mock(CronJobTrigger.class);
    when(job.getJobTrigger()).thenReturn(trigger);
    when(job.getJobName()).thenReturn(jobName);
    when(job.getJobParams()).thenReturn(params);
    JobScheduleRequest jobScheduleRequest = ScheduleExportUtil.createJobScheduleRequest(job);
    for (JobScheduleParam jobScheduleParam : jobScheduleRequest.getJobParameters()) {
        assertTrue(jobScheduleParam.getValue().equals(l) || jobScheduleParam.getValue().equals(d) || jobScheduleParam.getValue().equals(b));
    }
}
Also used : JobScheduleParam(org.pentaho.platform.web.http.api.resources.JobScheduleParam) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Date(java.util.Date) CronJobTrigger(org.pentaho.platform.api.scheduler2.CronJobTrigger) Test(org.junit.Test)

Example 5 with CronJobTrigger

use of org.pentaho.platform.api.scheduler2.CronJobTrigger in project pentaho-platform by pentaho.

the class ScheduleExportUtilTest method testCreateJobScheduleRequest_ActionClassJobParam.

@Test
public void testCreateJobScheduleRequest_ActionClassJobParam() throws Exception {
    String jobName = "JOB";
    String actionClass = "com.pentaho.Action";
    Map<String, Serializable> params = new HashMap<>();
    params.put(QuartzScheduler.RESERVEDMAPKEY_ACTIONCLASS, actionClass);
    Job job = mock(Job.class);
    CronJobTrigger trigger = mock(CronJobTrigger.class);
    when(job.getJobTrigger()).thenReturn(trigger);
    when(job.getJobName()).thenReturn(jobName);
    when(job.getJobParams()).thenReturn(params);
    JobScheduleRequest jobScheduleRequest = ScheduleExportUtil.createJobScheduleRequest(job);
    assertEquals(actionClass, jobScheduleRequest.getActionClass());
    assertEquals(actionClass, jobScheduleRequest.getJobParameters().get(0).getValue());
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) CronJobTrigger(org.pentaho.platform.api.scheduler2.CronJobTrigger) Test(org.junit.Test)

Aggregations

CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)11 Test (org.junit.Test)10 Job (org.pentaho.platform.api.scheduler2.Job)8 JobScheduleRequest (org.pentaho.platform.web.http.api.resources.JobScheduleRequest)8 Serializable (java.io.Serializable)7 HashMap (java.util.HashMap)6 JobScheduleParam (org.pentaho.platform.web.http.api.resources.JobScheduleParam)4 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)3 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Map (java.util.Map)2 Matchers.anyString (org.mockito.Matchers.anyString)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)2 IBackgroundExecutionStreamProvider (org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider)2 ComplexJobTriggerProxy (org.pentaho.platform.web.http.api.resources.ComplexJobTriggerProxy)2 RepositoryFileStreamProvider (org.pentaho.platform.web.http.api.resources.RepositoryFileStreamProvider)2 SchedulerOutputPathResolver (org.pentaho.platform.web.http.api.resources.SchedulerOutputPathResolver)2 IJobFilter (org.pentaho.platform.api.scheduler2.IJobFilter)1