Search in sources :

Example 26 with JobScheduleRequest

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

the class SchedulerServiceTest method testGetBlockStatus.

@Test
public void testGetBlockStatus() throws Exception {
    JobScheduleRequest jobScheduleRequestMock = mock(JobScheduleRequest.class);
    BlockStatusProxy blockStatusProxyMock = mock(BlockStatusProxy.class);
    IJobTrigger jobTrigger = mock(IJobTrigger.class);
    doReturn(jobTrigger).when(schedulerService).convertScheduleRequestToJobTrigger(jobScheduleRequestMock);
    doReturn(true).when(schedulerService.blockoutManager).isPartiallyBlocked(jobTrigger);
    doReturn(true).when(schedulerService.blockoutManager).willFire(jobTrigger);
    doReturn(blockStatusProxyMock).when(schedulerService).getBlockStatusProxy(anyBoolean(), anyBoolean());
    // Test 1
    BlockStatusProxy blockStatusProxy = schedulerService.getBlockStatus(jobScheduleRequestMock);
    assertNotNull(blockStatusProxy);
    // Test 2
    doReturn(false).when(schedulerService.blockoutManager).isPartiallyBlocked(jobTrigger);
    blockStatusProxy = schedulerService.getBlockStatus(jobScheduleRequestMock);
    assertNotNull(blockStatusProxy);
    verify(schedulerService, times(2)).convertScheduleRequestToJobTrigger(jobScheduleRequestMock);
    verify(schedulerService.blockoutManager, times(2)).isPartiallyBlocked(jobTrigger);
    verify(schedulerService, times(2)).getBlockStatusProxy(anyBoolean(), anyBoolean());
    verify(schedulerService.blockoutManager, times(1)).willFire(jobTrigger);
}
Also used : BlockStatusProxy(org.pentaho.platform.web.http.api.resources.proxies.BlockStatusProxy) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Test(org.junit.Test)

Example 27 with JobScheduleRequest

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

the class SchedulerServiceTest method testAddBlockoutException.

@Test
public void testAddBlockoutException() throws Exception {
    // Test 1
    JobScheduleRequest jobScheduleRequest = mock(JobScheduleRequest.class);
    doReturn(false).when(schedulerService).canAdminister();
    try {
        schedulerService.addBlockout(jobScheduleRequest);
        fail();
    } catch (IllegalAccessException e) {
    // Should catch exception
    }
    // Test 2
    Job jobMock = mock(Job.class);
    JobScheduleParam jobScheduleParamMock1 = mock(JobScheduleParam.class);
    JobScheduleParam jobScheduleParamMock2 = mock(JobScheduleParam.class);
    List<JobScheduleParam> jobScheduleParams = new ArrayList<>();
    doReturn(true).when(schedulerService).canAdminister();
    doNothing().when(jobScheduleRequest).setActionClass(anyString());
    doReturn(jobScheduleParams).when(jobScheduleRequest).getJobParameters();
    doReturn(jobScheduleParamMock1).when(schedulerService).getJobScheduleParam(anyString(), anyString());
    doReturn(jobScheduleParamMock2).when(schedulerService).getJobScheduleParam(anyString(), anyLong());
    doNothing().when(schedulerService).updateStartDateForTimeZone(jobScheduleRequest);
    doReturn(jobMock).when(schedulerService).createJob(any(JobScheduleRequest.class));
    doThrow(new IOException()).when(schedulerService).createJob(jobScheduleRequest);
    try {
        schedulerService.addBlockout(jobScheduleRequest);
        fail();
    } catch (IOException e) {
    // Should catch exception
    }
    // Test 3
    doThrow(new SchedulerException("")).when(schedulerService).createJob(jobScheduleRequest);
    try {
        schedulerService.addBlockout(jobScheduleRequest);
        fail();
    } catch (SchedulerException e) {
    // Should catch exception
    }
    verify(schedulerService, times(3)).canAdminister();
    verify(jobScheduleRequest, times(2)).setActionClass(anyString());
    verify(jobScheduleRequest, times(4)).getJobParameters();
    verify(schedulerService, times(2)).createJob(any(JobScheduleRequest.class));
}
Also used : JobScheduleParam(org.pentaho.platform.web.http.api.resources.JobScheduleParam) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Test(org.junit.Test)

Example 28 with JobScheduleRequest

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

the class SchedulerServiceTest method testUpdateBlockoutException.

@Test
public void testUpdateBlockoutException() throws Exception {
    String jobId = "jobId";
    JobScheduleRequest jobScheduleRequest = mock(JobScheduleRequest.class);
    Job job = mock(Job.class);
    // Test 1
    doReturn(false).when(schedulerService).canAdminister();
    try {
        schedulerService.updateBlockout(jobId, jobScheduleRequest);
        fail();
    } catch (IllegalAccessException e) {
    // Should catch the exception
    }
    // Test 2
    doReturn(true).when(schedulerService).canAdminister();
    doThrow(new SchedulerException("")).when(schedulerService).removeJob(anyString());
    try {
        schedulerService.updateBlockout(jobId, jobScheduleRequest);
        fail();
    } catch (SchedulerException e) {
    // Should catch the exception
    }
    // Test 3
    doReturn(false).when(schedulerService).removeJob(anyString());
    try {
        schedulerService.updateBlockout(jobId, jobScheduleRequest);
        fail();
    } catch (IllegalAccessException e) {
    // Should catch the exception
    }
    // Test 4
    doReturn(true).when(schedulerService).removeJob(anyString());
    doThrow(new IOException()).when(schedulerService).addBlockout(jobScheduleRequest);
    try {
        schedulerService.updateBlockout(jobId, jobScheduleRequest);
        fail();
    } catch (IOException e) {
    // Should catch the exception
    }
    // Test 5
    doThrow(new SchedulerException("")).when(schedulerService).addBlockout(jobScheduleRequest);
    try {
        schedulerService.updateBlockout(jobId, jobScheduleRequest);
        fail();
    } catch (SchedulerException e) {
    // Should catch the exception
    }
    verify(schedulerService, times(5)).canAdminister();
    verify(schedulerService, times(4)).removeJob(anyString());
    verify(schedulerService, times(2)).addBlockout(jobScheduleRequest);
}
Also used : SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Matchers.anyString(org.mockito.Matchers.anyString) IOException(java.io.IOException) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Test(org.junit.Test)

Example 29 with JobScheduleRequest

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

the class SolutionImportHandlerIT method createJobScheduleRequest.

private JobScheduleRequest createJobScheduleRequest(String name, JobState jobState) {
    JobScheduleRequest scheduleRequest = mock(JobScheduleRequest.class);
    doReturn(TestAction.class.getName()).when(scheduleRequest).getActionClass();
    doReturn(name).when(scheduleRequest).getJobName();
    doReturn(jobState).when(scheduleRequest).getJobState();
    return scheduleRequest;
}
Also used : JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest)

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