CalvalusGetStatusOperation extends WpsOperation { public ExecuteResponse getStatus(String jobId) throws JobNotFoundException, InvalidProcessorIdException, SqlStoreException { String localJobIdRegex = ".*-((\\d{4}((0[13578]|1[02])(0[1-9]|[12]\\d|3[01])|(0[13456789]|1[012])(0[1-9]|" + "[12]\\d|30)|02(0[1-9]|1\\d|2[0-8])))|(\\d{2}[02468][048]|\\d{2}[13579][26])0229){0,8}_.*"; if (jobId.matches(localJobIdRegex)) { try { return getLocalProcessExecuteResponse(jobId); } catch (JobNotFoundException _) {} } return getCalvalusExecuteResponse(jobId); } CalvalusGetStatusOperation(WpsRequestContext context); ExecuteResponse getStatus(String jobId);  }
@Test public void canGetInProgressStatus() throws Exception { ProductionRequest mockProductionRequest = getMockProductionRequest(); when(mockProduction.getProductionRequest()).thenReturn(mockProductionRequest); when(mockCalvalusFacade.getProduction(anyString())).thenReturn(mockProduction); ArrayList<String> dummyList = new ArrayList<>(); when(mockCalvalusFacade.getProductResultUrls("job-01")).thenReturn(dummyList); CalvalusWpsProcessStatus mockStatus = getInProgressProcessStatus(); PowerMockito.whenNew(CalvalusWpsProcessStatus.class).withArguments(mockProduction, dummyList).thenReturn(mockStatus); PowerMockito.whenNew(CalvalusFacade.class).withArguments(any(WpsRequestContext.class)).thenReturn(mockCalvalusFacade); Calendar calendar = Calendar.getInstance(); getStatusOperation = new CalvalusGetStatusOperation(mockRequestContext); ExecuteResponse executeResponse = getStatusOperation.getStatus("job-01"); assertThat(executeResponse.getProcess().getIdentifier().getValue(), equalTo("mockBundle~1.0~mockProcessor")); assertThat(executeResponse.getProcess().getProcessVersion(), equalTo("1.0")); assertThat(executeResponse.getStatus().getCreationTime().getDay(), equalTo(calendar.get(Calendar.DAY_OF_MONTH))); assertThat(executeResponse.getStatus().getCreationTime().getMonth(), equalTo(calendar.get(Calendar.MONTH) + 1)); assertThat(executeResponse.getStatus().getCreationTime().getYear(), equalTo(calendar.get(Calendar.YEAR))); assertThat(executeResponse.getStatus().getProcessStarted().getPercentCompleted(), equalTo(40)); assertThat(executeResponse.getStatus().getProcessStarted().getValue(), equalTo("RUNNING")); }
@Test public void canGetInProgressStatusLocalProcess() throws Exception { LocalProductionStatus mockStatus = getInProgressLocalProcessStatus(); PowerMockito.mockStatic(GpfProductionService.class); HashMap<String, Object> mockJobParameters = getMockJobParameters(); LocalJob mockJob = mock(LocalJob.class); when(mockJob.getStatus()).thenReturn(mockStatus); when(mockJob.getParameters()).thenReturn(mockJobParameters); LocalProductionService mockLocalProductionService = mock(LocalProductionService.class); when(mockLocalProductionService.getJob("urban1-20160919_160202392")).thenReturn(mockJob); PowerMockito.when(GpfProductionService.getProductionServiceSingleton()).thenReturn(mockLocalProductionService); Calendar calendar = Calendar.getInstance(); getStatusOperation = new CalvalusGetStatusOperation(mockRequestContext); ExecuteResponse executeResponse = getStatusOperation.getStatus("urban1-20160919_160202392"); assertThat(executeResponse.getProcess().getIdentifier().getValue(), equalTo("local~0.0.1~Subset")); assertThat(executeResponse.getProcess().getProcessVersion(), equalTo("0.0.1")); assertThat(executeResponse.getStatus().getCreationTime().getDay(), equalTo(calendar.get(Calendar.DAY_OF_MONTH))); assertThat(executeResponse.getStatus().getCreationTime().getMonth(), equalTo(calendar.get(Calendar.MONTH) + 1)); assertThat(executeResponse.getStatus().getCreationTime().getYear(), equalTo(calendar.get(Calendar.YEAR))); assertThat(executeResponse.getStatus().getProcessStarted().getPercentCompleted(), equalTo(40)); assertThat(executeResponse.getStatus().getProcessStarted().getValue(), equalTo("RUNNING")); }
@Test public void canThrowJobNotFoundExceptionWhenProductionNull() throws Exception { when(mockCalvalusFacade.getProduction(anyString())).thenReturn(null); PowerMockito.whenNew(CalvalusFacade.class).withArguments(any(WpsRequestContext.class)).thenReturn(mockCalvalusFacade); thrownException.expect(JobNotFoundException.class); thrownException.expectMessage("Parameter 'JobId job-01' has an invalid value."); getStatusOperation = new CalvalusGetStatusOperation(mockRequestContext); getStatusOperation.getStatus("job-01"); }
@Test public void canCatchProductionExceptionWhenGetInProgressStatus() throws Exception { when(mockProductionService.getProduction(anyString())).thenReturn(mockProduction); when(mockCalvalusFacade.getProduction(anyString())).thenThrow(new IOException("Production error")); PowerMockito.whenNew(CalvalusFacade.class).withArguments(any(WpsRequestContext.class)).thenReturn(mockCalvalusFacade); thrownException.expect(JobNotFoundException.class); thrownException.expectMessage("Parameter 'JobId job-01' has an invalid value."); getStatusOperation = new CalvalusGetStatusOperation(mockRequestContext); getStatusOperation.getStatus("job-01"); }
@Test public void canGetFailedStatus() throws Exception { ProductionRequest mockProductionRequest = getMockProductionRequest(); when(mockProduction.getProductionRequest()).thenReturn(mockProductionRequest); when(mockCalvalusFacade.getProduction(anyString())).thenReturn(mockProduction); ArrayList<String> dummyList = new ArrayList<>(); when(mockCalvalusFacade.getProductResultUrls("job-01")).thenReturn(dummyList); CalvalusWpsProcessStatus mockStatus = getFailedProcessStatus(); PowerMockito.whenNew(CalvalusWpsProcessStatus.class).withArguments(mockProduction, dummyList).thenReturn(mockStatus); PowerMockito.whenNew(CalvalusFacade.class).withArguments(any(WpsRequestContext.class)).thenReturn(mockCalvalusFacade); Calendar calendar = Calendar.getInstance(); getStatusOperation = new CalvalusGetStatusOperation(mockRequestContext); ExecuteResponse getStatusResponse = getStatusOperation.getStatus("job-01"); assertThat(getStatusResponse.getProcess().getIdentifier().getValue(), equalTo("mockBundle~1.0~mockProcessor")); assertThat(getStatusResponse.getProcess().getProcessVersion(), equalTo("1.0")); assertThat(getStatusResponse.getStatus().getCreationTime().getDay(), equalTo(calendar.get(Calendar.DAY_OF_MONTH))); assertThat(getStatusResponse.getStatus().getCreationTime().getMonth(), equalTo(calendar.get(Calendar.MONTH) + 1)); assertThat(getStatusResponse.getStatus().getCreationTime().getYear(), equalTo(calendar.get(Calendar.YEAR))); assertThat(getStatusResponse.getStatus().getProcessFailed().getExceptionReport().getVersion(), equalTo("1.0.0")); assertThat(getStatusResponse.getStatus().getProcessFailed().getExceptionReport().getException().get(0).getExceptionCode(), equalTo("NoApplicableCode")); assertThat(getStatusResponse.getStatus().getProcessFailed().getExceptionReport().getException().get(0).getExceptionText().get(0), equalTo("Error in processing the job")); }
@Test public void canGetFailedStatusLocalProcess() throws Exception { LocalProductionStatus mockStatus = getFailedLocalProcessStatus(); PowerMockito.mockStatic(GpfProductionService.class); HashMap<String, Object> mockJobParameters = getMockJobParameters(); LocalJob mockJob = mock(LocalJob.class); when(mockJob.getStatus()).thenReturn(mockStatus); when(mockJob.getParameters()).thenReturn(mockJobParameters); LocalProductionService mockLocalProductionService = mock(LocalProductionService.class); when(mockLocalProductionService.getJob("urban1-20160919_160202392")).thenReturn(mockJob); PowerMockito.when(GpfProductionService.getProductionServiceSingleton()).thenReturn(mockLocalProductionService); Calendar calendar = Calendar.getInstance(); getStatusOperation = new CalvalusGetStatusOperation(mockRequestContext); ExecuteResponse getStatusResponse = getStatusOperation.getStatus("urban1-20160919_160202392"); assertThat(getStatusResponse.getProcess().getIdentifier().getValue(), equalTo("local~0.0.1~Subset")); assertThat(getStatusResponse.getProcess().getProcessVersion(), equalTo("0.0.1")); assertThat(getStatusResponse.getStatus().getCreationTime().getDay(), equalTo(calendar.get(Calendar.DAY_OF_MONTH))); assertThat(getStatusResponse.getStatus().getCreationTime().getMonth(), equalTo(calendar.get(Calendar.MONTH) + 1)); assertThat(getStatusResponse.getStatus().getCreationTime().getYear(), equalTo(calendar.get(Calendar.YEAR))); assertThat(getStatusResponse.getStatus().getProcessFailed().getExceptionReport().getVersion(), equalTo("1.0.0")); assertThat(getStatusResponse.getStatus().getProcessFailed().getExceptionReport().getException().get(0).getExceptionCode(), equalTo("NoApplicableCode")); assertThat(getStatusResponse.getStatus().getProcessFailed().getExceptionReport().getException().get(0).getExceptionText().get(0), equalTo("Error in processing the job")); }
@Test public void canGetSuccessfulStatus() throws Exception { ProductionRequest mockProductionRequest = getMockProductionRequest(); when(mockProduction.getProductionRequest()).thenReturn(mockProductionRequest); when(mockCalvalusFacade.getProduction(anyString())).thenReturn(mockProduction); List<String> mockResultUrlList = getMockResultUrlList(); when(mockCalvalusFacade.getProductResultUrls("job-01")).thenReturn(mockResultUrlList); CalvalusWpsProcessStatus mockStatus = getDoneAndSuccessfulProcessStatus(mockResultUrlList); PowerMockito.whenNew(CalvalusWpsProcessStatus.class).withArguments(mockProduction, mockResultUrlList).thenReturn(mockStatus); PowerMockito.whenNew(CalvalusFacade.class).withArguments(any(WpsRequestContext.class)).thenReturn(mockCalvalusFacade); getStatusOperation = new CalvalusGetStatusOperation(mockRequestContext); ExecuteResponse getStatusResponse = getStatusOperation.getStatus("job-01"); assertThat(getStatusResponse.getProcess().getIdentifier().getValue(), equalTo("mockBundle~1.0~mockProcessor")); assertThat(getStatusResponse.getProcess().getProcessVersion(), equalTo("1.0")); assertThat(getStatusResponse.getStatus().getCreationTime().toString(), equalTo("2016-01-01T01:00:00.000+01:00")); assertThat(getStatusResponse.getProcessOutputs().getOutput().get(0).getIdentifier().getValue(), equalTo("production_result")); assertThat(getStatusResponse.getProcessOutputs().getOutput().get(0).getReference().getHref(), equalTo("http: assertThat(getStatusResponse.getProcessOutputs().getOutput().get(1).getIdentifier().getValue(), equalTo("production_result")); assertThat(getStatusResponse.getProcessOutputs().getOutput().get(1).getReference().getHref(), equalTo("http: }
@Test public void canGetSuccessfulStatusLocalProcess() throws Exception { List<String> dummyList = getMockResultUrlList(); when(mockCalvalusFacade.getProductResultUrls("urban1-20160919_160202392")).thenReturn(dummyList); LocalProductionStatus mockStatus = getDoneAndSuccessfulLocalProcessStatus(dummyList); PowerMockito.mockStatic(GpfProductionService.class); HashMap<String, Object> mockJobParameters = getMockJobParameters(); LocalJob mockJob = mock(LocalJob.class); when(mockJob.getStatus()).thenReturn(mockStatus); when(mockJob.getParameters()).thenReturn(mockJobParameters); LocalProductionService mockLocalProductionService = mock(LocalProductionService.class); when(mockLocalProductionService.getJob("urban1-20160919_160202392")).thenReturn(mockJob); PowerMockito.when(GpfProductionService.getProductionServiceSingleton()).thenReturn(mockLocalProductionService); getStatusOperation = new CalvalusGetStatusOperation(mockRequestContext); ExecuteResponse getStatusResponse = getStatusOperation.getStatus("urban1-20160919_160202392"); assertThat(getStatusResponse.getProcess().getIdentifier().getValue(), equalTo("local~0.0.1~Subset")); assertThat(getStatusResponse.getProcess().getProcessVersion(), equalTo("0.0.1")); assertThat(getStatusResponse.getStatus().getCreationTime().toString(), equalTo("2016-01-01T01:00:00.000+01:00")); assertThat(getStatusResponse.getProcessOutputs().getOutput().get(0).getIdentifier().getValue(), equalTo("production_result")); assertThat(getStatusResponse.getProcessOutputs().getOutput().get(0).getReference().getHref(), equalTo("http: assertThat(getStatusResponse.getProcessOutputs().getOutput().get(1).getIdentifier().getValue(), equalTo("production_result")); assertThat(getStatusResponse.getProcessOutputs().getOutput().get(1).getReference().getHref(), equalTo("http: }
@Test public void canThrowExceptionWhenJobUnavailableLocalProcess() throws Exception { PowerMockito.mockStatic(GpfProductionService.class); HashMap<String, LocalJob> statusMap = new HashMap<>(); LocalProductionService mockLocalProductionService = mock(LocalProductionService.class); PowerMockito.when(GpfProductionService.getProductionServiceSingleton()).thenReturn(mockLocalProductionService); thrownException.expect(JobNotFoundException.class); thrownException.expectMessage("Parameter 'JobId urban1-20160919_160202392' has an invalid value."); getStatusOperation = new CalvalusGetStatusOperation(mockRequestContext); getStatusOperation.getStatus("urban1-20160919_160202392"); }