CalvalusExecuteOperation { public ExecuteResponse execute(Execute executeRequest) throws InvalidProcessorIdException, WpsProductionException, WpsResultProductException, ProductionException, IOException { if(isQuotationRequest(executeRequest.getDataInputs())) { CalvalusExecuteResponseConverter executeResponse = new CalvalusExecuteResponseConverter(); ExecuteResponse processBriefType1 = executeResponse.getQuotationResponse((String)this.processFacade.getRequestHeaderMap().get("remoteUser"), (String)this.processFacade.getRequestHeaderMap().get("remoteRef"), executeRequest.getDataInputs()); ProcessBriefType responseFormType1 = getQuotationBriefType(executeRequest); processBriefType1.setProcess(responseFormType1); return processBriefType1; } ProcessBriefType processBriefType = getProcessBriefType(executeRequest); ResponseFormType responseFormType = executeRequest.getResponseForm(); ResponseDocumentType responseDocumentType = responseFormType.getResponseDocument(); boolean isAsynchronous = responseDocumentType.isStatus(); boolean isLineage = responseDocumentType.isLineage(); if (processFacade instanceof LocalFacade) { GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis(); } CalvalusExecuteResponseConverter executeResponse = new CalvalusExecuteResponseConverter(); if (isAsynchronous) { LocalProductionStatus status = processFacade.orderProductionAsynchronous(executeRequest); ExecuteResponse asyncExecuteResponse; if (isLineage) { List<DocumentOutputDefinitionType> outputType = executeRequest.getResponseForm().getResponseDocument().getOutput(); asyncExecuteResponse = executeResponse.getAcceptedWithLineageResponse(status.getJobId(), executeRequest.getDataInputs(), outputType, context.getServerContext()); } else { asyncExecuteResponse = executeResponse.getAcceptedResponse(status.getJobId(), context.getServerContext()); } asyncExecuteResponse.setProcess(processBriefType); return asyncExecuteResponse; } else { LocalProductionStatus status = processFacade.orderProductionSynchronous(executeRequest); ExecuteResponse syncExecuteResponse; if (!ProcessState.COMPLETED.toString().equals(status.getState())) { syncExecuteResponse = executeResponse.getFailedResponse(status.getMessage()); } else if (isLineage) { List<DocumentOutputDefinitionType> outputType = executeRequest.getResponseForm().getResponseDocument().getOutput(); syncExecuteResponse = executeResponse.getSuccessfulWithLineageResponse(status.getResultUrls(), executeRequest.getDataInputs(), outputType); } else { syncExecuteResponse = executeResponse.getSuccessfulResponse(status.getResultUrls(), status.getStopTime()); } syncExecuteResponse.setProcess(processBriefType); return syncExecuteResponse; } } CalvalusExecuteOperation(String processId, WpsRequestContext context); ExecuteResponse execute(Execute executeRequest);  }
@Test public void canExecuteAsync() throws Exception { ResponseFormType mockResponseForm = mock(ResponseFormType.class); ResponseDocumentType mockResponseDocument = mock(ResponseDocumentType.class); DataInputsType mockDataInputs = getDataInputs(); when(mockResponseDocument.isStatus()).thenReturn(true); when(mockResponseDocument.isLineage()).thenReturn(false); when(mockResponseForm.getResponseDocument()).thenReturn(mockResponseDocument); when(mockExecuteRequest.getDataInputs()).thenReturn(mockDataInputs); when(mockExecuteRequest.getResponseForm()).thenReturn(mockResponseForm); when(mockExecuteRequest.getIdentifier()).thenReturn(WpsTypeConverter.str2CodeType("process1")); when(mockExecuteRequest.getDataInputs()).thenReturn(new DataInputsType()); configureProcessingMock(); CalvalusFacade mockCalvalusFacade = mock(CalvalusFacade.class); Production mockProduction = mock(Production.class); LocalProductionStatus mockStatus = mock(LocalProductionStatus.class); when(mockStatus.getJobId()).thenReturn("process-00"); when(mockProduction.getId()).thenReturn("process-00"); when(mockCalvalusFacade.orderProductionAsynchronous(any(Execute.class))).thenReturn(mockStatus); PowerMockito.whenNew(CalvalusFacade.class).withArguments(any(WpsRequestContext.class)).thenReturn(mockCalvalusFacade); executeOperation = new CalvalusExecuteOperation(MOCK_PROCESSOR_ID, mockRequestContext); ExecuteResponse executeResponse = executeOperation.execute(mockExecuteRequest); assertThat(executeResponse.getStatus().getProcessAccepted(), equalTo("The request has been accepted. In order to check the status, use GetStatus with JobId 'process-00'.")); assertThat(executeResponse.getStatusLocation(), equalTo("http: assertThat(executeResponse.getProcess().getIdentifier().getValue(), equalTo("process1")); }
@Test public void canExecuteSync() throws Exception { ResponseFormType mockResponseForm = mock(ResponseFormType.class); ResponseDocumentType mockResponseDocument = mock(ResponseDocumentType.class); DataInputsType mockDataInputs = getDataInputs(); when(mockResponseDocument.isStatus()).thenReturn(false); when(mockResponseDocument.isLineage()).thenReturn(false); when(mockResponseForm.getResponseDocument()).thenReturn(mockResponseDocument); when(mockExecuteRequest.getDataInputs()).thenReturn(mockDataInputs); when(mockExecuteRequest.getResponseForm()).thenReturn(mockResponseForm); when(mockExecuteRequest.getIdentifier()).thenReturn(WpsTypeConverter.str2CodeType("process1")); when(mockExecuteRequest.getDataInputs()).thenReturn(new DataInputsType()); configureProcessingMock(); CalvalusFacade mockCalvalusFacade = mock(CalvalusFacade.class); Production mockProduction = mock(Production.class); List<String> resultUrlList = new ArrayList<>(); resultUrlList.add("resultUrl1"); resultUrlList.add("resultUrl2"); LocalProductionStatus mockStatus = mock(LocalProductionStatus.class); when(mockStatus.getJobId()).thenReturn("process-00"); when(mockStatus.getState()).thenReturn(ProcessState.COMPLETED.toString()); when(mockStatus.getStopTime()).thenReturn(new Date(1451606400000L)); when(mockStatus.getResultUrls()).thenReturn(resultUrlList); when(mockProduction.getId()).thenReturn("process-00"); when(mockCalvalusFacade.orderProductionSynchronous(any(Execute.class))).thenReturn(mockStatus); when(mockCalvalusFacade.getProduction(anyString())).thenReturn(mockProduction); PowerMockito.whenNew(CalvalusFacade.class).withArguments(any(WpsRequestContext.class)).thenReturn(mockCalvalusFacade); executeOperation = new CalvalusExecuteOperation(MOCK_PROCESSOR_ID, mockRequestContext); ExecuteResponse executeResponse = executeOperation.execute(mockExecuteRequest); assertThat(executeResponse.getStatus().getProcessSucceeded(), equalTo("The request has been processed successfully.")); assertThat(executeResponse.getProcess().getIdentifier().getValue(), equalTo("process1")); assertThat(executeResponse.getStatus().getCreationTime().toString(), equalTo("2016-01-01T01:00:00.000+01:00")); assertThat(executeResponse.getProcessOutputs().getOutput().size(), equalTo(2)); assertThat(executeResponse.getProcessOutputs().getOutput().get(0).getReference().getHref(), equalTo("resultUrl1")); assertThat(executeResponse.getProcessOutputs().getOutput().get(1).getReference().getHref(), equalTo("resultUrl2")); }
@Test public void canReturnQuotation() throws Exception { DataInputsType mockDataInputs = getQuotationDataInputs(); when(mockExecuteRequest.getDataInputs()).thenReturn(mockDataInputs); when(mockExecuteRequest.getIdentifier()).thenReturn(WpsTypeConverter.str2CodeType("process1")); configureProcessingMock(); CalvalusFacade mockCalvalusFacade = mock(CalvalusFacade.class); Map<String, String> mockRequestHeaderMap = new HashMap<>(); mockRequestHeaderMap.put("remoteUser", "user"); mockRequestHeaderMap.put("remoteRef", "ref-1"); when(mockCalvalusFacade.getRequestHeaderMap()).thenReturn(mockRequestHeaderMap); PowerMockito.whenNew(CalvalusFacade.class).withArguments(any(WpsRequestContext.class)).thenReturn(mockCalvalusFacade); executeOperation = new CalvalusExecuteOperation(MOCK_PROCESSOR_ID, mockRequestContext); ExecuteResponse executeResponse = executeOperation.execute(mockExecuteRequest); assertThat(executeResponse.getStatus().getProcessSucceeded(), equalTo("The request has been quoted successfully.")); assertThat(executeResponse.getProcess().getIdentifier().getValue(), equalTo("process1")); assertThat(executeResponse.getProcessOutputs().getOutput().size(), equalTo(1)); assertThat(executeResponse.getProcessOutputs().getOutput().get(0).getData().getComplexData().getContent().size(), equalTo(1)); assertThat((String) executeResponse.getProcessOutputs().getOutput().get(0).getData().getComplexData().getContent().get(0), containsString( "{\n" + " \"id\": \"ref-1\",\n" + " \"account\": {\n" + " \"platform\": \"Brockmann Consult GmbH Processing Center\",\n" + " \"username\": \"user\",\n" + " \"ref\": \"ref-1\"\n" + " },\n \"compound\": {\n" + " \"id\": \"any-id\",\n" + " \"name\": \"processName\",\n" + " \"type\": \"processType\"\n" + " },\n \"quantity\": [\n" + " {\n" + " \"id\": \"CPU_MILLISECONDS\",\n" + " \"value\": 1\n" + " },\n" + " {\n" + " \"id\": \"PHYSICAL_MEMORY_BYTES\",\n" + " \"value\": 1\n" + " },\n" + " {\n" + " \"id\": \"PROC_VOLUME_BYTES\",\n" + " \"value\": 2\n" + " },\n" + " {\n" + " \"id\": \"PROC_INSTANCE\",\n" + " \"value\": 1\n" + " }\n" + " ],\n" + " \"hostName\": \"www.brockmann-consult.de\",\n")); }