Search in sources :

Example 16 with JobScheduleRequest

use of org.pentaho.platform.web.http.api.resources.JobScheduleRequest in project pentaho-platform by pentaho.

the class ScheduleExportUtilTest method testCreateJobScheduleRequest_SimpleJobTrigger.

@Test
public void testCreateJobScheduleRequest_SimpleJobTrigger() throws Exception {
    String jobName = "JOB";
    Job job = mock(Job.class);
    SimpleJobTrigger trigger = mock(SimpleJobTrigger.class);
    when(job.getJobTrigger()).thenReturn(trigger);
    when(job.getJobName()).thenReturn(jobName);
    JobScheduleRequest jobScheduleRequest = ScheduleExportUtil.createJobScheduleRequest(job);
    assertNotNull(jobScheduleRequest);
    assertEquals(jobName, jobScheduleRequest.getJobName());
    assertEquals(trigger, jobScheduleRequest.getSimpleJobTrigger());
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Test(org.junit.Test)

Example 17 with JobScheduleRequest

use of org.pentaho.platform.web.http.api.resources.JobScheduleRequest in project pentaho-platform by pentaho.

the class ScheduleExportUtilTest method testCreateJobScheduleRequest_CronJobTrigger.

@Test
public void testCreateJobScheduleRequest_CronJobTrigger() throws Exception {
    String jobName = "JOB";
    Job job = mock(Job.class);
    CronJobTrigger trigger = mock(CronJobTrigger.class);
    when(job.getJobTrigger()).thenReturn(trigger);
    when(job.getJobName()).thenReturn(jobName);
    JobScheduleRequest jobScheduleRequest = ScheduleExportUtil.createJobScheduleRequest(job);
    assertNotNull(jobScheduleRequest);
    assertEquals(jobName, jobScheduleRequest.getJobName());
    assertEquals(trigger, jobScheduleRequest.getCronJobTrigger());
}
Also used : 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)

Example 18 with JobScheduleRequest

use of org.pentaho.platform.web.http.api.resources.JobScheduleRequest in project pentaho-platform by pentaho.

the class ScheduleExportUtilTest method testCreateJobScheduleRequest_TimeZoneJobParam.

@Test
public void testCreateJobScheduleRequest_TimeZoneJobParam() throws Exception {
    String jobName = "JOB";
    String timeZone = "America/New_York";
    Map<String, Serializable> params = new HashMap<>();
    params.put(IBlockoutManager.TIME_ZONE_PARAM, timeZone);
    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(timeZone, jobScheduleRequest.getTimeZone());
    assertEquals(timeZone, 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)

Example 19 with JobScheduleRequest

use of org.pentaho.platform.web.http.api.resources.JobScheduleRequest in project pentaho-platform by pentaho.

the class SolutionImportHandlerTest method testImportSchedules.

@Test
public void testImportSchedules() throws Exception {
    List<JobScheduleRequest> schedules = new ArrayList<>();
    JobScheduleRequest scheduleRequest = Mockito.spy(new JobScheduleRequest());
    schedules.add(scheduleRequest);
    SolutionImportHandler spyHandler = Mockito.spy(importHandler);
    Response response = Mockito.mock(Response.class);
    Mockito.when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
    Mockito.when(response.getEntity()).thenReturn("job id");
    Mockito.doReturn(response).when(spyHandler).createSchedulerJob(Mockito.any(SchedulerResource.class), Mockito.eq(scheduleRequest));
    mockSchedulerPause();
    spyHandler.importSchedules(schedules);
    Mockito.verify(spyHandler).createSchedulerJob(Mockito.any(SchedulerResource.class), Mockito.eq(scheduleRequest));
    Assert.assertEquals(1, ImportSession.getSession().getImportedScheduleJobIds().size());
}
Also used : Response(javax.ws.rs.core.Response) ArrayList(java.util.ArrayList) SchedulerResource(org.pentaho.platform.web.http.api.resources.SchedulerResource) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Test(org.junit.Test)

Example 20 with JobScheduleRequest

use of org.pentaho.platform.web.http.api.resources.JobScheduleRequest in project pentaho-platform by pentaho.

the class SolutionImportHandlerTest method testImportSchedules_FailsToCreateScheduleWithSpaceOnWindows.

@Test
public void testImportSchedules_FailsToCreateScheduleWithSpaceOnWindows() throws Exception {
    String sep = File.separator;
    System.setProperty("file.separator", "\\");
    List<JobScheduleRequest> schedules = new ArrayList<>();
    JobScheduleRequest scheduleRequest = Mockito.spy(new JobScheduleRequest());
    scheduleRequest.setInputFile("/home/admin/scheduled Transform.ktr");
    scheduleRequest.setOutputFile("/home/admin/scheduled Transform*");
    schedules.add(scheduleRequest);
    SolutionImportHandler spyHandler = Mockito.spy(importHandler);
    ScheduleRequestMatcher throwMatcher = new ScheduleRequestMatcher("/home/admin/scheduled Transform.ktr", "/home/admin/scheduled Transform*");
    Mockito.doThrow(new IOException("error creating schedule")).when(spyHandler).createSchedulerJob(Mockito.any(SchedulerResource.class), Mockito.argThat(throwMatcher));
    Response response = Mockito.mock(Response.class);
    Mockito.when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
    Mockito.when(response.getEntity()).thenReturn("job id");
    ScheduleRequestMatcher goodMatcher = new ScheduleRequestMatcher("/home/admin/scheduled_Transform.ktr", "/home/admin/scheduled_Transform*");
    Mockito.doReturn(response).when(spyHandler).createSchedulerJob(Mockito.any(SchedulerResource.class), Mockito.argThat(goodMatcher));
    mockSchedulerPause();
    spyHandler.importSchedules(schedules);
    Mockito.verify(spyHandler, Mockito.times(2)).createSchedulerJob(Mockito.any(SchedulerResource.class), Mockito.any(JobScheduleRequest.class));
    Assert.assertEquals(1, ImportSession.getSession().getImportedScheduleJobIds().size());
    System.setProperty("file.separator", sep);
}
Also used : Response(javax.ws.rs.core.Response) ArrayList(java.util.ArrayList) SchedulerResource(org.pentaho.platform.web.http.api.resources.SchedulerResource) IOException(java.io.IOException) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Test(org.junit.Test)

Aggregations

JobScheduleRequest (org.pentaho.platform.web.http.api.resources.JobScheduleRequest)29 Test (org.junit.Test)24 Job (org.pentaho.platform.api.scheduler2.Job)19 ArrayList (java.util.ArrayList)11 Serializable (java.io.Serializable)10 HashMap (java.util.HashMap)9 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)9 JobScheduleParam (org.pentaho.platform.web.http.api.resources.JobScheduleParam)8 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)7 IOException (java.io.IOException)6 SchedulerResource (org.pentaho.platform.web.http.api.resources.SchedulerResource)5 Date (java.util.Date)4 Response (javax.ws.rs.core.Response)4 Matchers.anyString (org.mockito.Matchers.anyString)4 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)4 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)3 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)3 ComplexJobTriggerProxy (org.pentaho.platform.web.http.api.resources.ComplexJobTriggerProxy)3 Map (java.util.Map)2