JobIdParameterValidator extends EngineParameterValidator<AbstractJobIdRequest> { @Override public void validate(AbstractJobIdRequest request) throws OwsExceptionReport { JobId jobId = request.getJobId(); if (jobId == null || jobId.getValue() == null || jobId.getValue().isEmpty()) { throw new MissingParameterValueException(JOB_ID); } if (!getEngine().hasJob(jobId)) { throw new NoSuchJobException(JOB_ID, jobId.getValue()); } boolean resultReady = false; try { resultReady = getEngine().getResult(jobId).isDone(); } catch (EngineException e) { } if (!resultReady && request instanceof GetResultRequest) { throw new ResultNotReadyException(JOB_ID, jobId.getValue()); } }  @Override void validate(AbstractJobIdRequest request);  }
@Test public void testValidationGetStatus() throws OwsExceptionReport, JobNotFoundException { EngineImpl engine = Mockito.mock(EngineImpl.class); Mockito.when(engine.hasJob(Mockito.any())).thenReturn(true); Mockito.when(engine.getResult(Mockito.any())).thenReturn(new FutureTask<>(() -> {}, null)); JobIdParameterValidator val = new JobIdParameterValidator(); val.setEngine(engine); GetStatusRequest gsr = new GetStatusRequest("WPS", "2.0.0"); gsr.setJobId("test-job"); val.validate(gsr); }
@Test(expected = ResultNotReadyException.class) public void testValidationGetResultNoResult() throws OwsExceptionReport, JobNotFoundException { EngineImpl engine = Mockito.mock(EngineImpl.class); Mockito.when(engine.hasJob(Mockito.any())).thenReturn(true); Mockito.when(engine.getResult(Mockito.any())).thenReturn(new FutureTask<>(() -> {}, null)); JobIdParameterValidator val = new JobIdParameterValidator(); val.setEngine(engine); GetResultRequest grr = new GetResultRequest("WPS", "2.0.0"); grr.setJobId("test-job"); val.validate(grr); }
@Test public void testValidationGetResult() throws OwsExceptionReport, JobNotFoundException, InterruptedException, ExecutionException { EngineImpl engine = Mockito.mock(EngineImpl.class); Mockito.when(engine.hasJob(Mockito.any())).thenReturn(true); Result r = new Result(); Future fr = Mockito.mock(Future.class); Mockito.when(fr.isDone()).thenReturn(true); Mockito.when(fr.get()).thenReturn(r); Mockito.when(engine.getResult(Mockito.any())).thenReturn(fr); JobIdParameterValidator val = new JobIdParameterValidator(); val.setEngine(engine); GetResultRequest grr = new GetResultRequest("WPS", "2.0.0"); grr.setJobId("test-job"); val.validate(grr); }