Search in sources :

Example 61 with SchedulerException

use of org.pentaho.platform.api.scheduler2.SchedulerException 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 62 with SchedulerException

use of org.pentaho.platform.api.scheduler2.SchedulerException 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 63 with SchedulerException

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

the class SchedulerServiceTest method testRemoveJob.

@Test
public void testRemoveJob() throws SchedulerException {
    Job job = mock(Job.class);
    doReturn(job).when(schedulerService).getJob(anyString());
    doReturn(true).when(schedulerService).isScheduleAllowed();
    doNothing().when(schedulerService.scheduler).removeJob(anyString());
    doReturn(IScheduler.SchedulerStatus.RUNNING).when(schedulerService.scheduler).getStatus();
    schedulerService.removeJob("job-id");
}
Also used : Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 64 with SchedulerException

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

the class SchedulerServiceTest method testShutdownException.

@Test
public void testShutdownException() throws SchedulerException {
    doReturn(true).when(schedulerService.policy).isAllowed(SchedulerAction.NAME);
    doThrow(new SchedulerException("")).when(schedulerService.scheduler).shutdown();
    try {
        schedulerService.shutdown();
        fail();
    } catch (SchedulerException e) {
    // Should go here
    }
    verify(schedulerService.policy).isAllowed(SchedulerAction.NAME);
    verify(schedulerService.scheduler).shutdown();
}
Also used : SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Test(org.junit.Test)

Example 65 with SchedulerException

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

the class SchedulerServiceTest method testGetContentCleanerJobException.

@Test
public void testGetContentCleanerJobException() throws Exception {
    IJobFilter jobFilter = mock(IJobFilter.class);
    List<Job> jobs = new ArrayList<>();
    IPentahoSession session = mock(IPentahoSession.class);
    doReturn(session).when(schedulerService).getSession();
    doReturn("sessionName").when(session).getName();
    doReturn(true).when(schedulerService.policy).isAllowed(AdministerSecurityAction.NAME);
    doReturn(jobFilter).when(schedulerService).getJobFilter(anyBoolean(), anyString());
    doThrow(new SchedulerException("")).when(schedulerService.scheduler).getJobs(any(IJobFilter.class));
    try {
        schedulerService.getContentCleanerJob();
        fail();
    } catch (SchedulerException e) {
    // Should catch the exception
    }
    verify(schedulerService).getSession();
    verify(session).getName();
    verify(schedulerService.policy).isAllowed(AdministerSecurityAction.NAME);
    verify(schedulerService.scheduler).getJobs(any(IJobFilter.class));
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Aggregations

SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)51 Test (org.junit.Test)49 Job (org.pentaho.platform.api.scheduler2.Job)43 IScheduler (org.pentaho.platform.api.scheduler2.IScheduler)23 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)18 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)16 Serializable (java.io.Serializable)15 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)11 Date (java.util.Date)10 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)9 Scheduler (org.quartz.Scheduler)9 ArrayList (java.util.ArrayList)8 IJobFilter (org.pentaho.platform.api.scheduler2.IJobFilter)8 IOException (java.io.IOException)6 Calendar (java.util.Calendar)6 HashMap (java.util.HashMap)6 CronTrigger (org.quartz.CronTrigger)6 SimpleTrigger (org.quartz.SimpleTrigger)6 Trigger (org.quartz.Trigger)6 Response (javax.ws.rs.core.Response)5