use of org.pentaho.platform.api.scheduler2.SchedulerException in project pentaho-platform by pentaho.
the class SchedulerService method triggerNow.
public Job triggerNow(String jobId) throws SchedulerException {
Job job = getScheduler().getJob(jobId);
if (getPolicy().isAllowed(SchedulerAction.NAME)) {
getScheduler().triggerNow(jobId);
} else {
if (getSession().getName().equals(job.getUserName())) {
getScheduler().triggerNow(jobId);
}
}
// udpate job state
job = getScheduler().getJob(jobId);
return job;
}
use of org.pentaho.platform.api.scheduler2.SchedulerException in project pentaho-platform by pentaho.
the class SchedulerService method getJobs.
public List<Job> getJobs() throws SchedulerException {
IPentahoSession session = getSession();
// this authentication wasn't matching with the job user name,
final String principalName = session.getName();
// changed to get name via the current session
final Boolean canAdminister = canAdminister(session);
List<Job> jobs = getScheduler().getJobs(new IJobFilter() {
@Override
public boolean accept(Job job) {
if (canAdminister) {
return !IBlockoutManager.BLOCK_OUT_JOB_NAME.equals(job.getJobName());
}
return principalName.equals(job.getUserName());
}
});
return jobs;
}
use of org.pentaho.platform.api.scheduler2.SchedulerException in project pentaho-platform by pentaho.
the class PentahoPlatformExporterTest method testExportSchedules_SchedulereThrowsException.
@Test
public void testExportSchedules_SchedulereThrowsException() throws Exception {
when(scheduler.getJobs(null)).thenThrow(new SchedulerException("bad"));
exporterSpy.exportSchedules();
verify(scheduler).getJobs(null);
assertEquals(0, exporterSpy.getExportManifest().getScheduleList().size());
}
use of org.pentaho.platform.api.scheduler2.SchedulerException in project pentaho-platform by pentaho.
the class SchedulerResourceTest method testGetJobError.
@Test
public void testGetJobError() throws Exception {
String jobId = "jobId";
String asCronString = "asCronString";
SchedulerException mockSchedulerException = mock(SchedulerException.class);
doThrow(mockSchedulerException).when(schedulerResource.schedulerService).getJobInfo(jobId);
try {
schedulerResource.getJob(jobId, asCronString);
fail();
} catch (RuntimeException e) {
// correct
}
verify(schedulerResource.schedulerService, times(1)).getJobInfo(jobId);
}
use of org.pentaho.platform.api.scheduler2.SchedulerException in project pentaho-platform by pentaho.
the class SchedulerResourceTest method testCreateJobError.
@Test
public void testCreateJobError() throws Exception {
JobScheduleRequest mockRequest = mock(JobScheduleRequest.class);
SchedulerException mockSchedulerException = mock(SchedulerException.class);
Throwable mockSchedulerExceptionCause = mock(Throwable.class);
doReturn(mockSchedulerExceptionCause).when(mockSchedulerException).getCause();
String schedulerExceptionMessage = "schedulerExceptionMessage";
doReturn(schedulerExceptionMessage).when(mockSchedulerExceptionCause).getMessage();
Response mockSchedulerExceptionResponse = mock(Response.class);
doReturn(mockSchedulerExceptionResponse).when(schedulerResource).buildServerErrorResponse(schedulerExceptionMessage);
IOException mockIOException = mock(IOException.class);
Throwable mockIOExceptionCause = mock(Throwable.class);
doReturn(mockIOExceptionCause).when(mockIOException).getCause();
String ioExceptionMessage = "ioExceptionMessage";
doReturn(ioExceptionMessage).when(mockIOExceptionCause).getMessage();
Response mockIOExceptionResponse = mock(Response.class);
doReturn(mockIOExceptionResponse).when(schedulerResource).buildServerErrorResponse(ioExceptionMessage);
Response mockUnauthorizedResponse = mock(Response.class);
doReturn(mockUnauthorizedResponse).when(schedulerResource).buildStatusResponse(UNAUTHORIZED);
Response mockForbiddenResponse = mock(Response.class);
doReturn(mockForbiddenResponse).when(schedulerResource).buildStatusResponse(FORBIDDEN);
// Test 1
doThrow(mockSchedulerException).when(schedulerResource.schedulerService).createJob(mockRequest);
Response testResponse = schedulerResource.createJob(mockRequest);
assertEquals(mockSchedulerExceptionResponse, testResponse);
// Test 2
doThrow(mockIOException).when(schedulerResource.schedulerService).createJob(mockRequest);
testResponse = schedulerResource.createJob(mockRequest);
assertEquals(mockIOExceptionResponse, testResponse);
// Test 3
SecurityException mockSecurityException = mock(SecurityException.class);
doThrow(mockSecurityException).when(schedulerResource.schedulerService).createJob(mockRequest);
testResponse = schedulerResource.createJob(mockRequest);
assertEquals(mockUnauthorizedResponse, testResponse);
// Test 4
IllegalAccessException mockIllegalAccessException = mock(IllegalAccessException.class);
doThrow(mockIllegalAccessException).when(schedulerResource.schedulerService).createJob(mockRequest);
testResponse = schedulerResource.createJob(mockRequest);
assertEquals(mockForbiddenResponse, testResponse);
verify(mockSchedulerException, times(1)).getCause();
verify(mockSchedulerExceptionCause, times(1)).getMessage();
verify(schedulerResource, times(1)).buildServerErrorResponse(schedulerExceptionMessage);
verify(mockIOException, times(1)).getCause();
verify(mockIOExceptionCause, times(1)).getMessage();
verify(schedulerResource, times(1)).buildServerErrorResponse(ioExceptionMessage);
verify(schedulerResource, times(1)).buildStatusResponse(UNAUTHORIZED);
verify(schedulerResource, times(1)).buildStatusResponse(FORBIDDEN);
verify(schedulerResource.schedulerService, times(4)).createJob(mockRequest);
}
Aggregations