Search in sources :

Example 21 with JobScheduleRequest

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

the class SolutionImportHandlerTest method testFileIsScheduleInputSource.

@Test
public void testFileIsScheduleInputSource() {
    ExportManifest manifest = Mockito.mock(ExportManifest.class);
    SolutionImportHandler spyHandler = Mockito.spy(importHandler);
    List<JobScheduleRequest> scheduleRequests = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        JobScheduleRequest jobScheduleRequest = new JobScheduleRequest();
        jobScheduleRequest.setInputFile("/public/test/file" + i);
        scheduleRequests.add(jobScheduleRequest);
    }
    Assert.assertFalse(spyHandler.fileIsScheduleInputSource(manifest, null));
    Mockito.when(manifest.getScheduleList()).thenReturn(scheduleRequests);
    Assert.assertFalse(spyHandler.fileIsScheduleInputSource(manifest, "/public/file"));
    Assert.assertTrue(spyHandler.fileIsScheduleInputSource(manifest, "/public/test/file3"));
    Assert.assertTrue(spyHandler.fileIsScheduleInputSource(manifest, "public/test/file3"));
}
Also used : ArrayList(java.util.ArrayList) ExportManifest(org.pentaho.platform.plugin.services.importexport.exportManifest.ExportManifest) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Test(org.junit.Test)

Example 22 with JobScheduleRequest

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

the class SolutionImportHandlerTest method testImportSchedules_FailsToCreateScheduleWithSpace.

@Test
public void testImportSchedules_FailsToCreateScheduleWithSpace() throws Exception {
    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());
}
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)

Example 23 with JobScheduleRequest

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

the class SolutionImportHandlerTest method testImportSchedules_FailsToCreateSchedule.

@Test
public void testImportSchedules_FailsToCreateSchedule() throws Exception {
    List<JobScheduleRequest> schedules = new ArrayList<>();
    JobScheduleRequest scheduleRequest = Mockito.spy(new JobScheduleRequest());
    scheduleRequest.setInputFile("/home/admin/scheduledTransform.ktr");
    scheduleRequest.setOutputFile("/home/admin/scheduledTransform*");
    schedules.add(scheduleRequest);
    SolutionImportHandler spyHandler = Mockito.spy(importHandler);
    Mockito.doThrow(new IOException("error creating schedule")).when(spyHandler).createSchedulerJob(Mockito.any(SchedulerResource.class), Mockito.eq(scheduleRequest));
    mockSchedulerPause();
    spyHandler.importSchedules(schedules);
    Assert.assertEquals(0, ImportSession.getSession().getImportedScheduleJobIds().size());
}
Also used : 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)

Example 24 with JobScheduleRequest

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

the class SchedulerServiceTest method testUpdateBlockout.

@Test
public void testUpdateBlockout() throws Exception {
    String jobId = "jobId";
    JobScheduleRequest jobScheduleRequest = mock(JobScheduleRequest.class);
    Job jobMock = mock(Job.class);
    doReturn(true).when(schedulerService).canAdminister();
    doReturn(true).when(schedulerService).removeJob(anyString());
    doReturn(jobMock).when(schedulerService).addBlockout(jobScheduleRequest);
    Job job = schedulerService.updateBlockout(jobId, jobScheduleRequest);
    assertNotNull(job);
    verify(schedulerService).canAdminister();
    verify(schedulerService).removeJob(anyString());
    verify(schedulerService).addBlockout(jobScheduleRequest);
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Test(org.junit.Test)

Example 25 with JobScheduleRequest

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

the class SchedulerServiceTest method testGetBlockStatusException.

@Test
public void testGetBlockStatusException() throws Exception {
    JobScheduleRequest jobScheduleRequestMock = mock(JobScheduleRequest.class);
    doThrow(new SchedulerException("")).when(schedulerService).convertScheduleRequestToJobTrigger(jobScheduleRequestMock);
    try {
        schedulerService.getBlockStatus(jobScheduleRequestMock);
        fail();
    } catch (SchedulerException e) {
    // Should catch the exception
    }
    verify(schedulerService).convertScheduleRequestToJobTrigger(jobScheduleRequestMock);
}
Also used : SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) 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