Search in sources :

Example 16 with SchedulerException

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);
}
Also used : Response(javax.ws.rs.core.Response) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) IOException(java.io.IOException) Test(org.junit.Test)

Example 17 with SchedulerException

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);
}
Also used : SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Test(org.junit.Test)

Example 18 with SchedulerException

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();
}
Also used : SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Test(org.junit.Test)

Example 19 with SchedulerException

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;
}
Also used : SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException)

Example 20 with SchedulerException

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;
}
Also used : JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) Serializable(java.io.Serializable) CronTrigger(org.quartz.CronTrigger) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) JobTrigger(org.pentaho.platform.api.scheduler2.JobTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Scheduler(org.quartz.Scheduler) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler) Job(org.pentaho.platform.api.scheduler2.Job)

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