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));
}
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);
}
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");
}
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();
}
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));
}
Aggregations