use of org.pentaho.platform.api.scheduler2.SchedulerException in project pentaho-platform by pentaho.
the class SchedulerResourceTest method testAddBlockoutError.
@Test
public void testAddBlockoutError() throws Exception {
JobScheduleRequest mockJobScheduleRequest = mock(JobScheduleRequest.class);
Response mockUnauthorizedResponse = mock(Response.class);
doReturn(mockUnauthorizedResponse).when(schedulerResource).buildStatusResponse(UNAUTHORIZED);
// Test 1
IOException mockIOException = mock(IOException.class);
doThrow(mockIOException).when(schedulerResource.schedulerService).addBlockout(mockJobScheduleRequest);
Response testResponse = schedulerResource.addBlockout(mockJobScheduleRequest);
assertEquals(mockUnauthorizedResponse, testResponse);
// Test 2
SchedulerException mockSchedulerException = mock(SchedulerException.class);
doThrow(mockSchedulerException).when(schedulerResource.schedulerService).addBlockout(mockJobScheduleRequest);
testResponse = schedulerResource.addBlockout(mockJobScheduleRequest);
assertEquals(mockUnauthorizedResponse, testResponse);
// Test 3
IllegalAccessException mockIllegalAccessException = mock(IllegalAccessException.class);
doThrow(mockIllegalAccessException).when(schedulerResource.schedulerService).addBlockout(mockJobScheduleRequest);
testResponse = schedulerResource.addBlockout(mockJobScheduleRequest);
assertEquals(mockUnauthorizedResponse, testResponse);
verify(schedulerResource.schedulerService, times(3)).addBlockout(mockJobScheduleRequest);
verify(schedulerResource, times(3)).buildStatusResponse(UNAUTHORIZED);
}
use of org.pentaho.platform.api.scheduler2.SchedulerException in project pentaho-platform by pentaho.
the class SchedulerResourceTest method testRemoveJobError.
@Test
public void testRemoveJobError() throws Exception {
String jobId = "jobId";
JobRequest mockJobRequest = mock(JobRequest.class);
doReturn(jobId).when(mockJobRequest).getJobId();
SchedulerException mockSchedulerException = mock(SchedulerException.class);
doThrow(mockSchedulerException).when(schedulerResource.schedulerService).removeJob(jobId);
try {
schedulerResource.removeJob(mockJobRequest);
fail();
} catch (RuntimeException e) {
// correct
}
verify(schedulerResource.schedulerService, times(1)).removeJob(jobId);
}
use of org.pentaho.platform.api.scheduler2.SchedulerException in project pentaho-platform by pentaho.
the class SchedulerResourceTest method testStartError.
@Test
public void testStartError() throws Exception {
SchedulerException mockSchedulerException = mock(SchedulerException.class);
doThrow(mockSchedulerException).when(schedulerResource.schedulerService).start();
try {
schedulerResource.start();
fail();
} catch (RuntimeException e) {
// correct
}
verify(schedulerResource.schedulerService, times(1)).start();
}
use of org.pentaho.platform.api.scheduler2.SchedulerException in project pentaho-platform by pentaho.
the class QuartzJobKey method parse.
/**
* Parses an existing jobId into a {@link QuartzJobKey}
*
* @param jobId
* an existing jobId
* @return a quartz job key
* @throws SchedulerException
*/
public static QuartzJobKey parse(String jobId) throws SchedulerException {
String delimiter = jobId.contains("\t") || jobId.isEmpty() ? "\t" : ":";
// $NON-NLS-1$
String[] elements = jobId.split(delimiter);
if (elements == null || elements.length < 3) {
throw new SchedulerException(MessageFormat.format(Messages.getInstance().getErrorString("QuartzJobKey.ERROR_0002"), // $NON-NLS-1$
jobId));
}
QuartzJobKey key = new QuartzJobKey();
key.userName = elements[0];
key.jobName = elements[1];
try {
key.timeInMillis = Long.parseLong(elements[2]);
} catch (NumberFormatException ex) {
throw new SchedulerException(MessageFormat.format(Messages.getInstance().getErrorString("QuartzJobKey.ERROR_0002"), // $NON-NLS-1$
jobId));
}
return key;
}
use of org.pentaho.platform.api.scheduler2.SchedulerException in project pentaho-platform by pentaho.
the class QuartzScheduler method getJob.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public Job getJob(String jobId) throws SchedulerException {
try {
Scheduler scheduler = getQuartzScheduler();
QuartzJobKey jobKey = QuartzJobKey.parse(jobId);
String groupName = jobKey.getUserName();
for (Trigger trigger : scheduler.getTriggersOfJob(jobId, groupName)) {
Job job = new Job();
JobDetail jobDetail = scheduler.getJobDetail(jobId, groupName);
if (jobDetail != null) {
JobDataMap jobDataMap = jobDetail.getJobDataMap();
if (jobDataMap != null) {
Map<String, Serializable> wrappedMap = jobDataMap.getWrappedMap();
job.setJobParams(wrappedMap);
}
}
job.setJobId(jobId);
setJobTrigger(scheduler, job, trigger);
job.setUserName(jobDetail.getGroup());
return job;
}
} catch (org.quartz.SchedulerException e) {
throw new SchedulerException(Messages.getInstance().getString("QuartzScheduler.ERROR_0007_FAILED_TO_GET_JOB", jobId), // $NON-NLS-1$
e);
}
return null;
}
Aggregations