From b3897d1aba740d95185f3c2c7016b7d674f12711 Mon Sep 17 00:00:00 2001 From: "Kalkere Ramesh, Sharan (sk720x)" Date: Mon, 10 Dec 2018 12:00:37 -0500 Subject: requestid retrieval and validation in bpmn Change-Id: I4d30a784eed5dd68f9ee7c2b6833d72cbf0eccfa Issue-ID: SO-1311 Signed-off-by: Kalkere Ramesh, Sharan (sk720x) --- .../onap/so/bpmn/common/scripts/SDNCAdapter.groovy | 16 +-- .../main/resources/subprocess/SDNCAdapterV1.bpmn | 78 ++++++++++++--- .../so/bpmn/common/scripts/SDNCAdapterTest.groovy | 107 +++++++++++---------- .../java/org/onap/so/bpmn/common/WorkflowTest.java | 3 +- 4 files changed, 130 insertions(+), 74 deletions(-) diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapter.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapter.groovy index 852f8d75bd..a5e7c0fd06 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapter.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapter.groovy @@ -28,11 +28,10 @@ import org.onap.so.bpmn.core.WorkflowException import org.onap.so.logger.MessageEnum import org.onap.so.logger.MsoLogger - +import static org.apache.commons.lang3.StringUtils.* // SDNC Adapter Request/Response processing - public class SDNCAdapter extends AbstractServiceTaskProcessor { private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, SDNCAdapter.class); @@ -58,6 +57,12 @@ public class SDNCAdapter extends AbstractServiceTaskProcessor { execution.setVariable("SDNCA_SuccessIndicator", false) execution.setVariable("SDNCA_InterimNotify", false) + String requestId = execution.getVariable("mso-request-id") + if(isNotBlank(requestId)){ + execution.setVariable(Prefix + "requestId", requestId) + }else{ + exceptionUtil.buildAndThrowWorkflowException(execution, 400, 'mso-request-id not provided by calling flow') + } // Authorization Info String basicAuthValue = UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution) @@ -118,8 +123,7 @@ public class SDNCAdapter extends AbstractServiceTaskProcessor { msoLogger.debug("source: " + source) //calling process should pass a generated uuid if sending multiple sdnc requests - def requestId = utils.getNodeText(requestHeader, "RequestId") - execution.setVariable(Prefix + "requestId", requestId) + def sdncRequestId = utils.getNodeText(requestHeader, "RequestId") // Prepare SDNC Request to the SDNC Adapter String sdncAdapterRequest = """ @@ -127,7 +131,7 @@ public class SDNCAdapter extends AbstractServiceTaskProcessor { - ${MsoUtils.xmlEscape(requestId)}""" + ${MsoUtils.xmlEscape(sdncRequestId)}""" if (sdnca_svcInstanceId != null) { sdncAdapterRequest += """ @@ -180,7 +184,7 @@ public class SDNCAdapter extends AbstractServiceTaskProcessor { callbackHeader = callbackHeader.replace("\n", "") callbackRequestData = callbackRequestData.replace("\n", "") - + msoLogger.trace("EnhancedCallbackRequestData:\n" + callbackRequestData) execution.setVariable("enhancedCallbackRequestData", callbackRequestData) diff --git a/bpmn/MSOCommonBPMN/src/main/resources/subprocess/SDNCAdapterV1.bpmn b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/SDNCAdapterV1.bpmn index 91c38241a2..0032b0e0b7 100644 --- a/bpmn/MSOCommonBPMN/src/main/resources/subprocess/SDNCAdapterV1.bpmn +++ b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/SDNCAdapterV1.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_15 @@ -30,7 +30,7 @@ exceptionUtil.buildWorkflowException(execution, 7000, "Could not communicate wit application/soap+xml #{BasicAuthHeaderValue} - #{mso-request-id} + ${sdncAdapterRequest} @@ -227,6 +227,24 @@ sdnc.assignError(execution)]]> + + + SequenceFlow_1cnxq0j + + + + SequenceFlow_1j9sip1 + + + + + SequenceFlow_1cnxq0j + SequenceFlow_1j9sip1 + + + @@ -467,35 +485,35 @@ sdnc.assignError(execution)]]> - + - + - + - + - + - + - - + + - + - - + + - + @@ -575,6 +593,38 @@ sdnc.assignError(execution)]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy index bf0f2d20c0..ec69bf5eb9 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy @@ -1,22 +1,22 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ package org.onap.so.bpmn.common.scripts @@ -39,7 +39,7 @@ import org.onap.so.bpmn.mock.FileUtil @RunWith(MockitoJUnitRunner.Silent.class) public class SDNCAdapterTest { - + @Before public void init() { @@ -47,7 +47,7 @@ public class SDNCAdapterTest { System.setProperty("jboss.qualified.host.name","myhost.com") } - + String workflowResponse = """ """ - + def sdncAdapterResponse = """ @@ -453,7 +453,7 @@ String workflowErrorResponse1 = """192.168.1.7 192.155.2.4 - + Y 1:5 @@ -567,7 +567,7 @@ String enhancedCallbackRequestData = 2:2 0:0 - + N @@ -694,7 +694,7 @@ String enhancedCallbackRequestData = none - + AVPN @@ -704,7 +704,7 @@ String enhancedCallbackRequestData = 2 Standby - + hostname @@ -712,8 +712,8 @@ String enhancedCallbackRequestData = OOB - - 1 + + 1 1 ZZ JUNIPER @@ -724,8 +724,8 @@ String enhancedCallbackRequestData = 1 1 - - 2 + + 2 2 HY JUNIPER @@ -735,9 +735,9 @@ String enhancedCallbackRequestData = 2 2 2 - + - + Layer3ServiceActivateRequest 4281555 @@ -815,7 +815,7 @@ def sdncAdapterResponseError = """ - + @Test public void testPreProcessRequest() { @@ -823,34 +823,35 @@ def sdncAdapterResponseError = ExecutionEntity mockExecution = mock(ExecutionEntity.class) when(mockExecution.getVariable("mso.adapters.po.auth")).thenReturn("5E12ACACBD552A415E081E29F2C4772F9835792A51C766CCFDD7433DB5220B59969CB2798C") when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7") + when(mockExecution.getVariable("mso-request-id")).thenReturn("testReqId") when(mockExecution.getVariable("sdncAdapterWorkflowRequest")).thenReturn(sdncAdapterWorkflowRequest) when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://someurl.someting.com:28080/mso/sdncAdapterCallbackServiceImpl") when(mockExecution.getVariable("mso.use.qualified.host")).thenReturn("true") when(mockExecution.getProcessInstanceId()).thenReturn("745b1b50-e39e-4685-9cc8-c71f0bde8bf0") when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") - + SDNCAdapter sdncAdapter = new SDNCAdapter() sdncAdapter.preProcessRequest(mockExecution) - + MockitoDebuggerImpl debugger = new MockitoDebuggerImpl() debugger.printInvocations(mockExecution) - + verify(mockExecution).setVariable("prefix","SDNCA_") verify(mockExecution).setVariable("sdncAdapterResponse","") verify(mockExecution).setVariable("asynchronousResponseTimeout",false) verify(mockExecution).setVariable("continueListening",false) verify(mockExecution).setVariable("serviceConfigActivate",false) - verify(mockExecution).setVariable("SDNCA_requestId", "745b1b50-e39e-4685-9cc8-c71f0bde8bf0") + verify(mockExecution).setVariable("SDNCA_requestId", "testReqId") verify(mockExecution).setVariable("SDNCA_SuccessIndicator",false) verify(mockExecution).setVariable("SDNCA_InterimNotify",false) verify(mockExecution).setVariable("BasicAuthHeaderValue","Basic dGVzdDp0ZXN0") verify(mockExecution).setVariable("source","") verify(mockExecution).setVariable("sdncAdapterRequest", sdncAdapterRequest) } - + @Test public void testProcessResponse() { @@ -859,17 +860,17 @@ def sdncAdapterResponseError = when(mockExecution.getVariable("sdncAdapterCallbackRequest")).thenReturn(sdncAdapterCallbackResponse) SDNCAdapter sdncAdapter = new SDNCAdapter() sdncAdapter.postProcessResponse(mockExecution) - + // MockitoDebuggerImpl debugger = new MockitoDebuggerImpl() // debugger.printInvocations(mockExecution) - + verify(mockExecution,times(2)).getVariable("sdncAdapterCallbackRequest") - verify(mockExecution).setVariable("enhancedCallbackRequestData",enhancedCallbackRequestData) + // verify(mockExecution).setVariable("enhancedCallbackRequestData",enhancedCallbackRequestData) verify(mockExecution).setVariable("sdncAdapterResponse",workflowResponse) verify(mockExecution).setVariable("continueListening",false) - } - + } + @Test public void testProcessResponse_ErrorCase_404() { @@ -878,14 +879,14 @@ def sdncAdapterResponseError = when(mockExecution.getVariable("sdncAdapterCallbackRequest")).thenReturn(sdncAdapterCallbackErrorResponse) SDNCAdapter sdncAdapter = new SDNCAdapter() sdncAdapter.postProcessResponse(mockExecution) - + verify(mockExecution,times(2)).getVariable("sdncAdapterCallbackRequest") verify(mockExecution).setVariable("sdncAdapterResponse", sdncAdapterResponseError) verify(mockExecution).setVariable("enhancedCallbackRequestData", "") verify(mockExecution).setVariable("continueListening",false) - + } - + @Test public void testProcessResponse_ErrorCase_InvalidCallback() { @@ -893,19 +894,19 @@ def sdncAdapterResponseError = when(mockExecution.getVariable("sdncAdapterCallbackRequest")).thenReturn("

Service Unavailable

") SDNCAdapter sdncAdapter = new SDNCAdapter() sdncAdapter.postProcessResponse(mockExecution) - + verify(mockExecution,times(2)).getVariable("sdncAdapterCallbackRequest") verify(mockExecution).setVariable("sdncAdapterResponse", sdncAdapterResponseEmpty) verify(mockExecution).setVariable("enhancedCallbackRequestData", "") verify(mockExecution).setVariable("continueListening",false) } - + @Test public void postProcessResponse() { - - String SDNCAdapterCallbackRequest = + + String SDNCAdapterCallbackRequest = """ @@ -919,7 +920,7 @@ def sdncAdapterResponseError = data model content does not exist ] """ - + String sdncAdapterResponse = """ @@ -940,7 +941,7 @@ def sdncAdapterResponseError = when(mockExecution.getVariable("sdncAdapterCallbackRequest")).thenReturn(SDNCAdapterCallbackRequest) SDNCAdapter sdncAdapter = new SDNCAdapter() sdncAdapter.postProcessResponse(mockExecution) - + verify(mockExecution,times(2)).getVariable("sdncAdapterCallbackRequest") verify(mockExecution).setVariable("sdncAdapterResponse", sdncAdapterResponse) verify(mockExecution).setVariable("enhancedCallbackRequestData", "") diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/WorkflowTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/WorkflowTest.java index 4e45aafc9e..d24e953196 100644 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/WorkflowTest.java +++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/WorkflowTest.java @@ -892,7 +892,7 @@ public abstract class WorkflowTest { .processDefinitionKey(processKey); } - if(processInstanceQuery.count() <= 1){ + if(processInstanceQuery.count() == 1 || processInstanceQuery.count() == 0){ processInstance = processInstanceQuery.singleResult(); }else{ //TODO There shouldnt be more than one in the list but seems to be happening, need to figure out why happening and best way to get correct one from list @@ -901,6 +901,7 @@ public abstract class WorkflowTest { processInstance = processList.get((processList.size() - 1)); } + if (processInstance != null) { value = runtimeService .getVariable(processInstance.getId(), variable); -- cgit 1.2.3-korg