GetJobDetailsHandler implements OutputOperationHandler<GetJobDetails, JobDetail> { @Override public JobDetail doOperation(final GetJobDetails operation, final Context context, final Store store) throws OperationException { if (null == store.getJobTracker()) { throw new OperationException("The Job Tracker has not been configured", SERVICE_UNAVAILABLE); } final String jobId = null != operation.getJobId() ? operation.getJobId() : context.getJobId(); return store.getJobTracker().getJob(jobId, context.getUser()); }  @Override JobDetail doOperation(final GetJobDetails operation, final Context context, final Store store);  }
@Test public void shouldThrowExceptionIfJobTrackerIsNotConfigured() { final GetJobDetailsHandler handler = new GetJobDetailsHandler(); final GetJobDetails operation = mock(GetJobDetails.class); final Store store = mock(Store.class); final User user = mock(User.class); given(store.getJobTracker()).willReturn(null); try { handler.doOperation(operation, new Context(user), store); fail("Exception expected"); } catch (final OperationException e) { assertNotNull(e.getMessage()); } }
@Test public void shouldGetJobDetailsByDelegatingToJobTrackerWithOperationJobId() throws OperationException { final String jobId = "jobId"; final GetJobDetailsHandler handler = new GetJobDetailsHandler(); final GetJobDetails operation = new GetJobDetails.Builder() .jobId(jobId) .build(); final Store store = mock(Store.class); final JobTracker jobTracker = mock(JobTracker.class); final User user = mock(User.class); final JobDetail jobsDetail = mock(JobDetail.class); final Context context = new Context(user); given(store.getJobTracker()).willReturn(jobTracker); given(jobTracker.getJob(jobId, user)).willReturn(jobsDetail); final JobDetail result = handler.doOperation(operation, context, store); assertSame(jobsDetail, result); }
@Test public void shouldGetJobDetailsByDelegatingToJobTrackerWithContextJobId() throws OperationException { final GetJobDetailsHandler handler = new GetJobDetailsHandler(); final GetJobDetails operation = new GetJobDetails(); final Store store = mock(Store.class); final JobTracker jobTracker = mock(JobTracker.class); final User user = mock(User.class); final JobDetail jobsDetail = mock(JobDetail.class); final Context context = new Context.Builder() .user(user) .build(); final String jobId = context.getJobId(); given(store.getJobTracker()).willReturn(jobTracker); given(jobTracker.getJob(jobId, user)).willReturn(jobsDetail); final JobDetail result = handler.doOperation(operation, context, store); assertSame(jobsDetail, result); }