aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/MSOCommonBPMN')
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/RequestDBUtil.groovy119
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java169
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/CDSRequestProvider.java76
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java79
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java73
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ExtractServiceFromUserParameters.java53
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java153
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PayloadConstants.java53
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PnfCDSRequestProvider.java78
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ServiceCDSRequestProvider.java89
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java121
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java106
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/PayloadGenerationException.java39
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtilsTest.java27
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java205
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java127
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/GeneratePayloadForCdsTest.java342
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/PnfCDSRequestProviderTest.java139
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ServiceCDSRequestProviderTest.java62
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java80
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VnfCDSRequestProviderTest.java104
21 files changed, 2229 insertions, 65 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/RequestDBUtil.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/RequestDBUtil.groovy
new file mode 100644
index 0000000000..ce474fa713
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/RequestDBUtil.groovy
@@ -0,0 +1,119 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2019, CMCC Technologies Co., Ltd.
+ #
+ # 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
+
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.onap.so.bpmn.core.UrnPropertiesReader
+import org.onap.so.db.request.beans.OperationStatus
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+import org.springframework.web.util.UriUtils
+
+class RequestDBUtil {
+ private static final Logger logger = LoggerFactory.getLogger( RequestDBUtil.class);
+ private ExceptionUtil exceptionUtil = new ExceptionUtil()
+
+ /**
+ * update operation status in requestDB
+ * @param execution
+ * @param operationStatus
+ */
+ void prepareUpdateOperationStatus(DelegateExecution execution, final OperationStatus operationStatus){
+ logger.debug("start prepareUpdateOperationStatus")
+ try{
+ def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
+ execution.setVariable("dbAdapterEndpoint", dbAdapterEndpoint)
+ logger.debug("DB Adapter Endpoint is: " + dbAdapterEndpoint)
+
+ String serviceId = operationStatus.getServiceId()
+ serviceId = UriUtils.encode(serviceId,"UTF-8")
+ String operationId = operationStatus.getOperationId()
+ String userId = operationStatus.getUserId()
+ String operationType = operationStatus.getOperation()
+ String result = operationStatus.getResult()
+ String progress = operationStatus.getProgress()
+ String operationContent = operationStatus.getOperationContent()
+ String reason = operationStatus.getReason()
+
+ String payload =
+ """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
+ xmlns:ns="http://org.onap.so/requestsdb">
+ <soapenv:Header/>
+ <soapenv:Body>
+ <ns:updateServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
+ <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
+ <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
+ <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
+ <userId>${MsoUtils.xmlEscape(userId)}</userId>
+ <result>${MsoUtils.xmlEscape(result)}</result>
+ <operationContent>${MsoUtils.xmlEscape(operationContent)}</operationContent>
+ <progress>${MsoUtils.xmlEscape(progress)}</progress>
+ <reason>${MsoUtils.xmlEscape(reason)}</reason>
+ </ns:updateServiceOperationStatus>
+ </soapenv:Body>
+ </soapenv:Envelope>
+ """
+ execution.setVariable("updateOperationStatus", payload)
+
+ }catch(any){
+ String exceptionMessage = "Prepare update ServiceOperationStatus failed. cause - " + any.getMessage()
+ logger.debug(exceptionMessage)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ logger.trace("finished update OperationStatus")
+ }
+
+
+ /**
+ * get operation status from requestDB by serviceId and operationId
+ * @param execution
+ * @param serviceId
+ * @param operationId
+ */
+ void getOperationStatus(DelegateExecution execution, String serviceId, String operationId) {
+ logger.trace("start getOperationStatus")
+ try {
+ def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
+ execution.setVariable("dbAdapterEndpoint", dbAdapterEndpoint)
+ logger.trace("DB Adapter Endpoint is: " + dbAdapterEndpoint)
+
+ serviceId = UriUtils.encode(serviceId,"UTF-8")
+ operationId = UriUtils.encode(operationId,"UTF-8")
+ String payload =
+ """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
+ xmlns:ns="http://org.onap.so/requestsdb">
+ <soapenv:Header/>
+ <soapenv:Body>
+ <ns:getServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
+ <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
+ <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
+ </ns:getServiceOperationStatus>
+ </soapenv:Body>
+ </soapenv:Envelope>
+ """
+ execution.setVariable("getOperationStatus", payload)
+
+ } catch(any){
+ String exceptionMessage = "Get ServiceOperationStatus failed. cause - " + any.getMessage()
+ logger.error(exceptionMessage)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java
index 424a4f3ecc..ebced8e933 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java
@@ -22,14 +22,18 @@
package org.onap.so.client.cds;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.google.protobuf.Struct;
+import com.google.protobuf.Struct.Builder;
+import com.google.protobuf.util.JsonFormat;
+import io.grpc.Status;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader;
import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.client.PreconditionFailedException;
import org.onap.so.client.RestPropertiesLoader;
import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
@@ -39,15 +43,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import com.google.protobuf.InvalidProtocolBufferException;
-import com.google.protobuf.Struct;
-import com.google.protobuf.Struct.Builder;
-import com.google.protobuf.util.JsonFormat;
-import io.grpc.Status;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
/**
* Util class to support Call to CDS client
- *
*/
@Component
public class AbstractCDSProcessingBBUtils {
@@ -60,11 +60,7 @@ public class AbstractCDSProcessingBBUtils {
private static final String RESPONSE_PAYLOAD = "CDSResponsePayload";
private static final String CDS_STATUS = "CDSStatus";
private static final String EXEC_INPUT = "executionServiceInput";
-
-
- /**
- * indicate exception thrown.
- */
+ private static final String EXECUTION_OBJECT = "executionObject";
private static final String EXCEPTION = "Exception";
@Autowired
@@ -76,34 +72,33 @@ public class AbstractCDSProcessingBBUtils {
* @param execution DelegateExecution object
*/
public void constructExecutionServiceInputObject(DelegateExecution execution) {
- logger.trace("Start AbstractCDSProcessingBBUtils.preProcessRequest ");
+ logger.trace("Start AbstractCDSProcessingBBUtils.preProcessRequest for DelegateExecution object.");
try {
AbstractCDSPropertiesBean executionObject =
- (AbstractCDSPropertiesBean) execution.getVariable("executionObject");
-
- String payload = executionObject.getRequestObject();
-
- CommonHeader commonHeader = CommonHeader.newBuilder().setOriginatorId(executionObject.getOriginatorId())
- .setRequestId(executionObject.getRequestId()).setSubRequestId(executionObject.getSubRequestId())
- .build();
- ActionIdentifiers actionIdentifiers =
- ActionIdentifiers.newBuilder().setBlueprintName(executionObject.getBlueprintName())
- .setBlueprintVersion(executionObject.getBlueprintVersion())
- .setActionName(executionObject.getActionName()).setMode(executionObject.getMode()).build();
-
- Builder struct = Struct.newBuilder();
- try {
- JsonFormat.parser().merge(payload, struct);
- } catch (InvalidProtocolBufferException e) {
- logger.error("Failed to parse received message. blueprint({}:{}) for action({}). {}",
- executionObject.getBlueprintVersion(), executionObject.getBlueprintName(),
- executionObject.getActionName(), e);
- }
+ (AbstractCDSPropertiesBean) execution.getVariable(EXECUTION_OBJECT);
+
+ ExecutionServiceInput executionServiceInput = prepareExecutionServiceInput(executionObject);
+
+ execution.setVariable(EXEC_INPUT, executionServiceInput);
+
+ } catch (Exception ex) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
+ }
+ }
- ExecutionServiceInput executionServiceInput =
- ExecutionServiceInput.newBuilder().setCommonHeader(commonHeader)
- .setActionIdentifiers(actionIdentifiers).setPayload(struct.build()).build();
+ /**
+ * Extracting data from execution object and building the ExecutionServiceInput Object
+ *
+ * @param execution BuildingBlockExecution object
+ */
+ public void constructExecutionServiceInputObject(BuildingBlockExecution execution) {
+ logger.trace("Start AbstractCDSProcessingBBUtils.preProcessRequest for BuildingBlockExecution object.");
+
+ try {
+ AbstractCDSPropertiesBean executionObject = execution.getVariable(EXECUTION_OBJECT);
+
+ ExecutionServiceInput executionServiceInput = prepareExecutionServiceInput(executionObject);
execution.setVariable(EXEC_INPUT, executionServiceInput);
@@ -119,50 +114,98 @@ public class AbstractCDSProcessingBBUtils {
*/
public void sendRequestToCDSClient(DelegateExecution execution) {
- logger.trace("Start AbstractCDSProcessingBBUtils.sendRequestToCDSClient ");
+ logger.trace("Start AbstractCDSProcessingBBUtils.sendRequestToCDSClient for DelegateExecution object.");
try {
- CDSProperties props = RestPropertiesLoader.getInstance().getNewImpl(CDSProperties.class);
- if (props == null) {
- throw new PreconditionFailedException(
- "No RestProperty.CDSProperties implementation found on classpath, can't create client.");
- }
-
ExecutionServiceInput executionServiceInput = (ExecutionServiceInput) execution.getVariable(EXEC_INPUT);
+ CDSResponse cdsResponse = getCdsResponse(executionServiceInput);
+ execution.setVariable(CDS_STATUS, cdsResponse.status);
- CDSResponse cdsResponse = new CDSResponse();
-
- try (CDSProcessingClient cdsClient = new CDSProcessingClient(new ResponseHandler(cdsResponse))) {
- CountDownLatch countDownLatch = cdsClient.sendRequest(executionServiceInput);
- countDownLatch.await(props.getTimeout(), TimeUnit.SECONDS);
- } catch (InterruptedException ex) {
- logger.error("Caught exception in sendRequestToCDSClient in AbstractCDSProcessingBBUtils : ", ex);
- Thread.currentThread().interrupt();
+ if (cdsResponse.payload != null) {
+ String payload = JsonFormat.printer().print(cdsResponse.payload);
+ execution.setVariable(RESPONSE_PAYLOAD, payload);
}
- String cdsResponseStatus = cdsResponse.status;
+ } catch (Exception ex) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
+ }
+ }
- /**
- * throw CDS failed exception.
- */
- if (!cdsResponseStatus.equals(SUCCESS)) {
- throw new BadResponseException("CDS call failed with status: " + cdsResponse.status
- + " and errorMessage: " + cdsResponse.errorMessage);
- }
+ /**
+ * get the executionServiceInput object from execution and send a request to CDS Client and wait for TIMEOUT period
+ *
+ * @param execution BuildingBlockExecution object
+ */
+ public void sendRequestToCDSClient(BuildingBlockExecution execution) {
- execution.setVariable(CDS_STATUS, cdsResponseStatus);
+ logger.trace("Start AbstractCDSProcessingBBUtils.sendRequestToCDSClient for BuildingBlockExecution object.");
+ try {
+ ExecutionServiceInput executionServiceInput = execution.getVariable(EXEC_INPUT);
+ CDSResponse cdsResponse = getCdsResponse(executionServiceInput);
+ execution.setVariable(CDS_STATUS, cdsResponse.status);
if (cdsResponse.payload != null) {
String payload = JsonFormat.printer().print(cdsResponse.payload);
execution.setVariable(RESPONSE_PAYLOAD, payload);
}
-
-
} catch (Exception ex) {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
}
}
+ private CDSResponse getCdsResponse(ExecutionServiceInput executionServiceInput) throws BadResponseException {
+ CDSProperties props = RestPropertiesLoader.getInstance().getNewImpl(CDSProperties.class);
+ if (props == null) {
+ throw new PreconditionFailedException(
+ "No RestProperty.CDSProperties implementation found on classpath, can't create client.");
+ }
+
+ CDSResponse cdsResponse = new CDSResponse();
+
+ try (CDSProcessingClient cdsClient = new CDSProcessingClient(new ResponseHandler(cdsResponse))) {
+ CountDownLatch countDownLatch = cdsClient.sendRequest(executionServiceInput);
+ countDownLatch.await(props.getTimeout(), TimeUnit.SECONDS);
+ } catch (InterruptedException ex) {
+ logger.error("Caught exception in sendRequestToCDSClient in AbstractCDSProcessingBBUtils : ", ex);
+ Thread.currentThread().interrupt();
+ }
+
+ String cdsResponseStatus = cdsResponse.status;
+
+ /**
+ * throw CDS failed exception.
+ */
+ if (!cdsResponseStatus.equals(SUCCESS)) {
+ throw new BadResponseException("CDS call failed with status: " + cdsResponse.status + " and errorMessage: "
+ + cdsResponse.errorMessage);
+ }
+ return cdsResponse;
+ }
+
+ private ExecutionServiceInput prepareExecutionServiceInput(AbstractCDSPropertiesBean executionObject) {
+ String payload = executionObject.getRequestObject();
+
+ CommonHeader commonHeader = CommonHeader.newBuilder().setOriginatorId(executionObject.getOriginatorId())
+ .setRequestId(executionObject.getRequestId()).setSubRequestId(executionObject.getSubRequestId())
+ .build();
+ ActionIdentifiers actionIdentifiers =
+ ActionIdentifiers.newBuilder().setBlueprintName(executionObject.getBlueprintName())
+ .setBlueprintVersion(executionObject.getBlueprintVersion())
+ .setActionName(executionObject.getActionName()).setMode(executionObject.getMode()).build();
+
+ Builder struct = Struct.newBuilder();
+ try {
+ JsonFormat.parser().merge(payload, struct);
+ } catch (InvalidProtocolBufferException e) {
+ logger.error("Failed to parse received message. blueprint({}:{}) for action({}). {}",
+ executionObject.getBlueprintVersion(), executionObject.getBlueprintName(),
+ executionObject.getActionName(), e);
+ }
+
+ return ExecutionServiceInput.newBuilder().setCommonHeader(commonHeader).setActionIdentifiers(actionIdentifiers)
+ .setPayload(struct.build()).build();
+ }
+
private class ResponseHandler implements CDSProcessingListener {
private CDSResponse cdsResponse;
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/CDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/CDSRequestProvider.java
new file mode 100644
index 0000000000..e01de69b74
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/CDSRequestProvider.java
@@ -0,0 +1,76 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * 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.client.cds;
+
+import com.google.gson.JsonObject;
+import org.onap.so.client.exception.PayloadGenerationException;
+import java.util.Optional;
+import static org.onap.so.client.cds.PayloadConstants.REQUEST;
+import static org.onap.so.client.cds.PayloadConstants.SEPARATOR;
+
+public interface CDSRequestProvider {
+
+ /**
+ * Build entire payload for CDS.
+ *
+ * @param action - action could be assign/deploy/undeploy etc.
+ * @return "payload":{ "config-<action>-<scope>":{ // information about resolution key, property configuration and
+ * template prefix based on the scope and action}
+ * @throws PayloadGenerationException If fail to build the payload.
+ */
+ Optional<String> buildRequestPayload(String action) throws PayloadGenerationException;
+
+ /**
+ * Get the blueprint name for CDS payload
+ *
+ * @return blueprint name
+ */
+ String getBlueprintName();
+
+ /**
+ * Get the blueprint version for CDS payload
+ *
+ * @return blueprint version
+ */
+ String getBlueprintVersion();
+
+ /**
+ * Set the executionObject(BuildingBlockExecution or DelegateExecution for PNF)
+ *
+ * @param executionObject object could be BuildingBlockExecution or DelegateExecution.
+ */
+ <T> void setExecutionObject(T executionObject);
+
+
+ /**
+ * Build Request payload for CDS
+ *
+ * @param cdsPropertyObject - Json Object
+ * @param action - action could be assign/deploy/undeploy etc.
+ * @return Request Payload
+ */
+ default String buildRequestJsonObject(JsonObject cdsPropertyObject, String action) {
+ String requestBasedOnAction = action.concat(SEPARATOR).concat(REQUEST);
+ JsonObject requestObject = new JsonObject();
+ requestObject.add(requestBasedOnAction, cdsPropertyObject);
+ return requestObject.toString();
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java
new file mode 100644
index 0000000000..6f850fa898
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java
@@ -0,0 +1,79 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * 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.client.cds;
+
+import com.google.gson.JsonObject;
+import org.onap.so.client.cds.ExtractServiceFromUserParameters;
+import org.onap.so.client.exception.PayloadGenerationException;
+import org.onap.so.serviceinstancebeans.Service;
+import org.onap.so.serviceinstancebeans.VfModules;
+import org.onap.so.serviceinstancebeans.Vnfs;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class ConfigureInstanceParamsForVfModule {
+
+ @Autowired
+ private ExtractServiceFromUserParameters extractServiceFromUserParameters;
+
+ /**
+ * Read instance parameters for VF-Module and put into JsonObject.
+ *
+ * @param jsonObject- JsonObject which will hold the payload to send to CDS.
+ * @param userParamsFromRequest - User parameters for a vf-module
+ * @param vnfCustomizationUuid - Unique ID for vnf.
+ * @param vfModuleCustomizationUuid - Unique ID for vf-module.
+ * @throws PayloadGenerationException- If it doesn't able to populate instance parameters from SO payload.
+ */
+ public void populateInstanceParams(JsonObject jsonObject, List<Map<String, Object>> userParamsFromRequest,
+ String vnfCustomizationUuid, String vfModuleCustomizationUuid) throws PayloadGenerationException {
+ try {
+ Service service = extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest);
+
+ List<Map<String, String>> instanceParamsList =
+ getInstanceParams(service, vnfCustomizationUuid, vfModuleCustomizationUuid);
+
+ instanceParamsList.stream().flatMap(instanceParamsMap -> instanceParamsMap.entrySet().stream())
+ .forEachOrdered(entry -> jsonObject.addProperty(entry.getKey(), entry.getValue()));
+ } catch (Exception e) {
+ throw new PayloadGenerationException("Couldn't able to resolve instance parameters", e);
+ }
+ }
+
+ private List<Map<String, String>> getInstanceParams(Service service, String vnfCustomizationUuid,
+ String vfModuleCustomizationUuid) throws PayloadGenerationException {
+
+ Vnfs foundedVnf = service.getResources().getVnfs().stream()
+ .filter(vnfs -> vnfs.getModelInfo().getModelCustomizationId().equals(vnfCustomizationUuid)).findFirst()
+ .orElseThrow(() -> new PayloadGenerationException(String
+ .format("Can not find vnf for genericVnfModelCustomizationUuid: %s", vnfCustomizationUuid)));
+
+ VfModules vfModule = foundedVnf.getVfModules().stream().filter(
+ vfModules -> vfModules.getModelInfo().getModelCustomizationId().equals(vfModuleCustomizationUuid))
+ .findFirst().orElseThrow(() -> new PayloadGenerationException(String
+ .format("Can not find vnf for vfModuleCustomizationUuid: %s", vfModuleCustomizationUuid)));
+
+ return vfModule.getInstanceParams();
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java
new file mode 100644
index 0000000000..22c9a7bee4
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java
@@ -0,0 +1,73 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * 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.client.cds;
+
+import com.google.gson.JsonObject;
+import org.onap.so.client.exception.PayloadGenerationException;
+import org.onap.so.serviceinstancebeans.Service;
+import org.onap.so.serviceinstancebeans.Vnfs;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+@Component
+public class ConfigureInstanceParamsForVnf {
+
+ @Autowired
+ private ExtractServiceFromUserParameters extractServiceFromUserParameters;
+
+ /**
+ * Read instance parameters for VNF and put into JsonObject.
+ *
+ * @param jsonObject - JsonObject which will hold the payload to send to CDS.
+ * @param userParamsFromRequest - User parameters.
+ * @param modelCustomizationUuid - Unique ID for Vnf.
+ * @throws PayloadGenerationException if it doesn't able to populate instance parameters from SO payload.
+ */
+ public void populateInstanceParams(JsonObject jsonObject, List<Map<String, Object>> userParamsFromRequest,
+ String modelCustomizationUuid) throws PayloadGenerationException {
+ try {
+ Service service = extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest);
+ List<Map<String, String>> instanceParamsList = getInstanceParamForVnf(service, modelCustomizationUuid);
+
+ instanceParamsList.stream().flatMap(instanceParamsMap -> instanceParamsMap.entrySet().stream())
+ .forEachOrdered(entry -> jsonObject.addProperty(entry.getKey(), entry.getValue()));
+ } catch (Exception e) {
+ throw new PayloadGenerationException("Couldn't able to resolve instance parameters", e);
+ }
+ }
+
+ private List<Map<String, String>> getInstanceParamForVnf(Service service, String genericVnfModelCustomizationUuid)
+ throws PayloadGenerationException {
+ Optional<Vnfs> foundedVnf = service.getResources().getVnfs().stream()
+ .filter(vnfs -> vnfs.getModelInfo().getModelCustomizationId().equals(genericVnfModelCustomizationUuid))
+ .findFirst();
+
+ if (foundedVnf.isPresent()) {
+ return foundedVnf.get().getInstanceParams();
+ } else {
+ throw new PayloadGenerationException(String.format(
+ "Can not find vnf for genericVnfModelCustomizationUuid: %s", genericVnfModelCustomizationUuid));
+ }
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ExtractServiceFromUserParameters.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ExtractServiceFromUserParameters.java
new file mode 100644
index 0000000000..43fabd3253
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ExtractServiceFromUserParameters.java
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * 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.client.cds;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.onap.so.client.exception.PayloadGenerationException;
+import org.onap.so.serviceinstancebeans.Service;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class ExtractServiceFromUserParameters {
+
+ private static final String SERVICE_KEY = "service";
+
+ @Autowired
+ private ObjectMapper objectMapper;
+
+ public Service getServiceFromRequestUserParams(List<Map<String, Object>> userParams) throws Exception {
+ Map<String, Object> serviceMap = userParams.stream().filter(key -> key.containsKey(SERVICE_KEY)).findFirst()
+ .orElseThrow(() -> new Exception("Can not find service in userParams section in generalBuildingBlock"));
+ return getServiceObjectFromServiceMap(serviceMap);
+ }
+
+ private Service getServiceObjectFromServiceMap(Map<String, Object> serviceMap) throws PayloadGenerationException {
+ try {
+ String serviceFromJson = objectMapper.writeValueAsString(serviceMap.get(SERVICE_KEY));
+ return objectMapper.readValue(serviceFromJson, Service.class);
+ } catch (Exception e) {
+ throw new PayloadGenerationException("An exception occurred while converting json object to Service object",
+ e);
+ }
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java
new file mode 100644
index 0000000000..fb79880572
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java
@@ -0,0 +1,153 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * Modifications Copyright (c) 2020 Nordix
+ * ================================================================================
+ * 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.client.cds;
+
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
+import org.onap.so.client.exception.PayloadGenerationException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import java.util.UUID;
+
+@Component
+public class GeneratePayloadForCds {
+
+ private static final String ORIGINATOR_ID = "SO";
+ private static final String BUILDING_BLOCK = "buildingBlock";
+ private static final String DEFAULT_SYNC_MODE = "sync";
+ private static final String MSO_REQUEST_ID = "msoRequestId";
+
+ @Autowired
+ private VnfCDSRequestProvider vnfCDSRequestProvider;
+
+ @Autowired
+ private VfModuleCDSRequestProvider vfModuleCDSRequestProvider;
+
+ @Autowired
+ private ServiceCDSRequestProvider serviceCDSRequestProvider;
+
+ @Autowired
+ private ExtractPojosForBB extractPojosForBB;
+
+ @Autowired
+ private PnfCDSRequestProvider pnfCDSRequestProvider;
+
+ /**
+ * Build properties like (blueprint name, version, action etc..) along with the request payload for vnf, vf-module
+ * and service.
+ *
+ * @param execution - A building block execution object.
+ * @return AbstractCDSPropertiesBean - A POJO which contains CDS related information.
+ * @throws PayloadGenerationException - Throw an exception if it fails to build payload for CDS.
+ */
+ public AbstractCDSPropertiesBean buildCdsPropertiesBean(BuildingBlockExecution execution)
+ throws PayloadGenerationException {
+
+ ExecuteBuildingBlock executeBuildingBlock = execution.getVariable(BUILDING_BLOCK);
+ BuildingBlock buildingBlock = executeBuildingBlock.getBuildingBlock();
+ final String requestId = execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId();
+ final String scope = buildingBlock.getBpmnScope();
+ final String action = buildingBlock.getBpmnAction();
+
+
+ CDSRequestProvider requestProvider = getRequestProviderByScope(scope);
+ requestProvider.setExecutionObject(execution);
+
+ final String requestPayload = requestProvider.buildRequestPayload(action)
+ .orElseThrow(() -> new PayloadGenerationException("Failed to build payload for CDS"));
+
+ return prepareAndSetCdsPropertyBean(requestProvider, requestPayload, requestId, action, DEFAULT_SYNC_MODE);
+ }
+
+ /**
+ * Build properties like (blueprint name, version, action etc..) along with the request payload for pnf.
+ *
+ * @param execution - A building block execution object.
+ * @return AbstractCDSPropertiesBean - A POJO which contains CDS related information.
+ * @throws PayloadGenerationException - Throw an exception if it fails to build payload for CDS.
+ */
+ public AbstractCDSPropertiesBean buildCdsPropertiesBean(DelegateExecution execution)
+ throws PayloadGenerationException {
+
+ final String scope = String.valueOf(execution.getVariable(PayloadConstants.SCOPE));
+ final String action = String.valueOf(execution.getVariable(PayloadConstants.ACTION));
+ final String requestId = String.valueOf(execution.getVariable(MSO_REQUEST_ID));
+ final String mode = extractAndSetMode(execution);
+
+ CDSRequestProvider requestProvider = getRequestProviderByScope(scope);
+ requestProvider.setExecutionObject(execution);
+
+ final String requestPayload = requestProvider.buildRequestPayload(action)
+ .orElseThrow(() -> new PayloadGenerationException("Failed to build payload for CDS"));
+
+ return prepareAndSetCdsPropertyBean(requestProvider, requestPayload, requestId, action, mode);
+ }
+
+ private AbstractCDSPropertiesBean prepareAndSetCdsPropertyBean(CDSRequestProvider requestProvider,
+ String requestPayload, String requestId, String action, String mode) {
+ final AbstractCDSPropertiesBean cdsPropertiesBean = new AbstractCDSPropertiesBean();
+ cdsPropertiesBean.setRequestObject(requestPayload);
+ cdsPropertiesBean.setBlueprintName(requestProvider.getBlueprintName());
+ cdsPropertiesBean.setBlueprintVersion(requestProvider.getBlueprintVersion());
+ cdsPropertiesBean.setRequestId(requestId);
+ cdsPropertiesBean.setOriginatorId(ORIGINATOR_ID);
+ cdsPropertiesBean.setSubRequestId(UUID.randomUUID().toString());
+ cdsPropertiesBean.setActionName(action);
+ cdsPropertiesBean.setMode(mode);
+ return cdsPropertiesBean;
+ }
+
+ private String extractAndSetMode(DelegateExecution execution) {
+ String mode = DEFAULT_SYNC_MODE;
+ Object obj = execution.getVariable(PayloadConstants.MODE);
+ if (obj != null && !String.valueOf(obj).isEmpty()) {
+ mode = String.valueOf(obj);
+ }
+ return mode;
+ }
+
+ private CDSRequestProvider getRequestProviderByScope(String scope) throws PayloadGenerationException {
+ CDSRequestProvider requestProvider;
+ switch (scope) {
+ case PayloadConstants.VNF_SCOPE:
+ requestProvider = vnfCDSRequestProvider;
+ break;
+ case PayloadConstants.VF_MODULE_SCOPE:
+ requestProvider = vfModuleCDSRequestProvider;
+ break;
+ case PayloadConstants.SERVICE_SCOPE:
+ requestProvider = serviceCDSRequestProvider;
+ break;
+ case PayloadConstants.PNF_SCOPE:
+ requestProvider = pnfCDSRequestProvider;
+ break;
+ default:
+ throw new PayloadGenerationException("No scope defined with " + scope);
+ }
+ return requestProvider;
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PayloadConstants.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PayloadConstants.java
new file mode 100644
index 0000000000..808d427d65
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PayloadConstants.java
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * Modifications Copyright (C) 2020 Nordix
+ * ================================================================================
+ * 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.client.cds;
+
+public final class PayloadConstants {
+
+ private PayloadConstants() {
+
+ }
+
+ public static final String REQUEST = "request";
+ public static final String PROPERTIES = "properties";
+ public static final String SCOPE = "scope";
+ public static final String ACTION = "action";
+ public static final String MODE = "mode";
+ public static final String SEPARATOR = "-";
+ public static final String PNF_SCOPE = "pnf";
+ public static final String VNF_SCOPE = "vnf";
+ public static final String VF_MODULE_SCOPE = "vfModule";
+ public static final String SERVICE_SCOPE = "service";
+ public static final String RESOLUTION_KEY = "resolution-key";
+ public static final String CDS_ACTOR = "cds";
+
+ public static final String PRC_BLUEPRINT_NAME = "PRC_blueprintName";
+ public static final String PRC_BLUEPRINT_VERSION = "PRC_blueprintVersion";
+ public static final String PRC_CUSTOMIZATION_UUID = "PRC_customizationUuid";
+ public static final String PRC_TARGET_SOFTWARE_VERSION = "targetSoftwareVersion";
+
+ public final static String PNF_CORRELATION_ID = "pnfCorrelationId";
+ public final static String PNF_UUID = "pnfUuid";
+ public final static String SERVICE_INSTANCE_ID = "serviceInstanceId";
+ public final static String MODEL_UUID = "modelUuid";
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PnfCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PnfCDSRequestProvider.java
new file mode 100644
index 0000000000..86bca755ed
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PnfCDSRequestProvider.java
@@ -0,0 +1,78 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.client.cds;
+
+import com.google.gson.JsonObject;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+import java.util.Optional;
+import static org.onap.so.client.cds.PayloadConstants.*;
+
+@Component
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+public class PnfCDSRequestProvider implements CDSRequestProvider {
+ private String blueprintName;
+ private String blueprintVersion;
+ private DelegateExecution execution;
+
+ @Override
+ public String getBlueprintName() {
+ return blueprintName;
+ }
+
+ @Override
+ public String getBlueprintVersion() {
+ return blueprintVersion;
+ }
+
+ @Override
+ public <T> void setExecutionObject(T executionObject) {
+ execution = (DelegateExecution) executionObject;
+ }
+
+ @Override
+ public Optional<String> buildRequestPayload(String action) {
+
+ final JsonObject pnfObject = new JsonObject();
+ final String resolutionKey = String.valueOf(execution.getVariable(PNF_CORRELATION_ID));
+ blueprintName = String.valueOf(execution.getVariable(PRC_BLUEPRINT_NAME));
+ blueprintVersion = String.valueOf(execution.getVariable(PRC_BLUEPRINT_VERSION));
+
+ extractAndSetExecutionVariable("service-instance-id", SERVICE_INSTANCE_ID, pnfObject);
+ extractAndSetExecutionVariable("service-model-uuid", MODEL_UUID, pnfObject);
+ extractAndSetExecutionVariable("pnf-id", PNF_UUID, pnfObject);
+ extractAndSetExecutionVariable("pnf-name", PNF_CORRELATION_ID, pnfObject);
+ extractAndSetExecutionVariable("pnf-customization-uuid", PRC_CUSTOMIZATION_UUID, pnfObject);
+ extractAndSetExecutionVariable("target-software-version", PRC_TARGET_SOFTWARE_VERSION, pnfObject);
+
+ final JsonObject cdsPropertyObject = new JsonObject();
+ cdsPropertyObject.addProperty(RESOLUTION_KEY, resolutionKey);
+ cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, pnfObject);
+
+ return Optional.of(buildRequestJsonObject(cdsPropertyObject, action));
+ }
+
+ private void extractAndSetExecutionVariable(String jsonProperty, String executionProperty, JsonObject pnfObject) {
+ if (execution.getVariable(executionProperty) != null) {
+ pnfObject.addProperty(jsonProperty, String.valueOf(execution.getVariable(executionProperty)));
+ }
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ServiceCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ServiceCDSRequestProvider.java
new file mode 100644
index 0000000000..12c841a2c6
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ServiceCDSRequestProvider.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Bell Canada
+ * ================================================================================
+ * 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.client.cds;
+
+import com.google.gson.JsonObject;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.exception.PayloadGenerationException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+import java.util.Optional;
+import static org.onap.so.client.cds.PayloadConstants.PROPERTIES;
+import static org.onap.so.client.cds.PayloadConstants.SEPARATOR;
+
+@Component
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+public class ServiceCDSRequestProvider implements CDSRequestProvider {
+
+ private static final String EMPTY_STRING = "";
+ private String resolutionKey;
+ private BuildingBlockExecution execution;
+
+ @Autowired
+ private ExtractPojosForBB extractPojosForBB;
+
+ @Override
+ public String getBlueprintName() {
+ return EMPTY_STRING;
+ }
+
+ @Override
+ public String getBlueprintVersion() {
+ return EMPTY_STRING;
+ }
+
+ @Override
+ public <T> void setExecutionObject(T executionObject) {
+ execution = (BuildingBlockExecution) executionObject;
+ }
+
+ @Override
+ public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException {
+ JsonObject cdsPropertyObject = new JsonObject();
+ JsonObject serviceObject = new JsonObject();
+ try {
+ ServiceInstance serviceInstance =
+ extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
+
+ resolutionKey = serviceInstance.getServiceInstanceName();
+
+ // TODO Need to figure out how to populate blueprint name and version for service.
+
+ serviceObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId());
+ serviceObject.addProperty("service-model-uuid",
+ serviceInstance.getModelInfoServiceInstance().getModelUuid());
+
+ } catch (Exception e) {
+ throw new PayloadGenerationException("Failed to buildPropertyObjectForService", e);
+ }
+
+ cdsPropertyObject.addProperty("resolution-key", resolutionKey);
+ cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, serviceObject);
+
+ return Optional.of(buildRequestJsonObject(cdsPropertyObject, action));
+ }
+
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java
new file mode 100644
index 0000000000..bba8925f21
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java
@@ -0,0 +1,121 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * 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.client.cds;
+
+import com.google.gson.JsonObject;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
+import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.exception.PayloadGenerationException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import static org.onap.so.client.cds.PayloadConstants.PROPERTIES;
+import static org.onap.so.client.cds.PayloadConstants.SEPARATOR;
+
+@Component
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+public class VfModuleCDSRequestProvider implements CDSRequestProvider {
+ private String blueprintName;
+ private String blueprintVersion;
+ private BuildingBlockExecution execution;
+
+ @Autowired
+ private ExtractPojosForBB extractPojosForBB;
+
+ @Autowired
+ private ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule;
+
+ @Override
+ public String getBlueprintName() {
+ return blueprintName;
+ }
+
+ @Override
+ public String getBlueprintVersion() {
+ return blueprintVersion;
+ }
+
+ @Override
+ public <T> void setExecutionObject(T executionObject) {
+ execution = (BuildingBlockExecution) executionObject;
+ }
+
+ @Override
+ public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException {
+ JsonObject cdsPropertyObject = new JsonObject();
+ JsonObject vfModuleObject = new JsonObject();
+ String vfModuleName;
+
+ try {
+ ServiceInstance serviceInstance =
+ extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
+ GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
+
+ final String modelCustomizationUuidForVnf = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid();
+
+ blueprintName = genericVnf.getBlueprintName();
+ blueprintVersion = genericVnf.getBlueprintVersion();
+
+ VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
+ vfModuleName = vfModule.getVfModuleName();
+
+ final String modelCustomizationUuidForVfModule =
+ vfModule.getModelInfoVfModule().getModelCustomizationUUID();
+
+ vfModuleObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId());
+ vfModuleObject.addProperty("service-model-uuid",
+ serviceInstance.getModelInfoServiceInstance().getModelUuid());
+ vfModuleObject.addProperty("vnf-id", genericVnf.getVnfId());
+ vfModuleObject.addProperty("vnf-name", genericVnf.getVnfName());
+ vfModuleObject.addProperty("vf-module-id", vfModule.getVfModuleId());
+ vfModuleObject.addProperty("vf-module-name", vfModule.getVfModuleName());
+ vfModuleObject.addProperty("vf-module-customization-uuid",
+ vfModule.getModelInfoVfModule().getModelCustomizationUUID());
+
+ final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock();
+ List<Map<String, Object>> userParamsFromRequest =
+ buildingBlock.getRequestContext().getRequestParameters().getUserParams();
+
+ configureInstanceParamsForVfModule.populateInstanceParams(vfModuleObject, userParamsFromRequest,
+ modelCustomizationUuidForVnf, modelCustomizationUuidForVfModule);
+ } catch (Exception e) {
+ throw new PayloadGenerationException("Failed to buildPropertyObject for VF-Module", e);
+ }
+
+ // Not sure for resolutionKey should be same as vfModule name.
+ cdsPropertyObject.addProperty("resolution-key", vfModuleName);
+ cdsPropertyObject.addProperty("template-prefix", vfModuleName + action);
+ cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, vfModuleObject);
+
+ return Optional.of(buildRequestJsonObject(cdsPropertyObject, action));
+ }
+
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java
new file mode 100644
index 0000000000..d33976d229
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java
@@ -0,0 +1,106 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * 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.client.cds;
+
+import com.google.gson.JsonObject;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.exception.PayloadGenerationException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import static org.onap.so.client.cds.PayloadConstants.PROPERTIES;
+import static org.onap.so.client.cds.PayloadConstants.SEPARATOR;
+
+@Component
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+public class VnfCDSRequestProvider implements CDSRequestProvider {
+ private String blueprintName;
+ private String blueprintVersion;
+ private BuildingBlockExecution execution;
+
+ @Autowired
+ private ExtractPojosForBB extractPojosForBB;
+
+ @Autowired
+ private ConfigureInstanceParamsForVnf configureInstanceParamsForVnf;
+
+ @Override
+ public String getBlueprintName() {
+ return blueprintName;
+ }
+
+ @Override
+ public String getBlueprintVersion() {
+ return blueprintVersion;
+ }
+
+ @Override
+ public <T> void setExecutionObject(T executionObject) {
+ execution = (BuildingBlockExecution) executionObject;
+ }
+
+ @Override
+ public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException {
+ JsonObject cdsPropertyObject = new JsonObject();
+ JsonObject vnfObject = new JsonObject();
+ String resolutionKey;
+ try {
+ ServiceInstance serviceInstance =
+ extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
+ GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
+
+ final String modelCustomizationUuid = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid();
+
+ resolutionKey = genericVnf.getVnfName();
+ blueprintName = genericVnf.getBlueprintName();
+ blueprintVersion = genericVnf.getBlueprintVersion();
+
+ vnfObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId());
+ vnfObject.addProperty("service-model-uuid", serviceInstance.getModelInfoServiceInstance().getModelUuid());
+ vnfObject.addProperty("vnf-id", genericVnf.getVnfId());
+ vnfObject.addProperty("vnf-name", genericVnf.getVnfName());
+ vnfObject.addProperty("vnf-customization-uuid", modelCustomizationUuid);
+
+ final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock();
+ List<Map<String, Object>> userParamsFromRequest =
+ buildingBlock.getRequestContext().getRequestParameters().getUserParams();
+
+ configureInstanceParamsForVnf.populateInstanceParams(vnfObject, userParamsFromRequest,
+ modelCustomizationUuid);
+ } catch (Exception e) {
+ throw new PayloadGenerationException("Failed to buildPropertyObjectForVnf", e);
+ }
+
+ cdsPropertyObject.addProperty("resolution-key", resolutionKey);
+ cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, vnfObject);
+
+ return Optional.of(buildRequestJsonObject(cdsPropertyObject, action));
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/PayloadGenerationException.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/PayloadGenerationException.java
new file mode 100644
index 0000000000..3c148a17a5
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/PayloadGenerationException.java
@@ -0,0 +1,39 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * 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.client.exception;
+
+public class PayloadGenerationException extends Exception {
+
+ /**
+ * @param message The message to dump
+ */
+ public PayloadGenerationException(final String message) {
+ super(message);
+ }
+
+ /**
+ * @param message The message to dump.
+ * @param cause The throwable cause object.
+ */
+ public PayloadGenerationException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtilsTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtilsTest.java
index f558932d33..10844ec652 100644
--- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtilsTest.java
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtilsTest.java
@@ -34,6 +34,7 @@ import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
import org.onap.so.client.exception.ExceptionBuilder;
@@ -69,7 +70,7 @@ public class AbstractCDSProcessingBBUtilsTest {
}
@Test
- public void preProcessRequestTest() throws Exception {
+ public void preProcessRequestDETest() throws Exception {
DelegateExecution execution = mock(DelegateExecution.class);
when(execution.getVariable("executionObject")).thenReturn(abstractCDSPropertiesBean);
@@ -80,7 +81,7 @@ public class AbstractCDSProcessingBBUtilsTest {
}
@Test
- public void sendRequestToCDSClientTest() {
+ public void sendRequestToCDSClientDETest() {
DelegateExecution execution = mock(DelegateExecution.class);
when(execution.getVariable("executionServiceInput")).thenReturn(abstractCDSPropertiesBean);
@@ -90,4 +91,26 @@ public class AbstractCDSProcessingBBUtilsTest {
}
+ @Test
+ public void preProcessRequestBBTest() throws Exception {
+
+ BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
+ when(execution.getVariable("executionObject")).thenReturn(abstractCDSPropertiesBean);
+
+ abstractCDSProcessingBBUtils.constructExecutionServiceInputObject(execution);
+ verify(exceptionUtil, times(0)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), anyInt(),
+ any(Exception.class));
+ }
+
+ @Test
+ public void sendRequestToCDSClientBBTest() {
+
+ BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
+ when(execution.getVariable("executionServiceInput")).thenReturn(abstractCDSPropertiesBean);
+ abstractCDSProcessingBBUtils.sendRequestToCDSClient(execution);
+ verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), anyInt(),
+ any(Exception.class));
+
+ }
+
}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java
new file mode 100644
index 0000000000..9c3ce60400
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java
@@ -0,0 +1,205 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.cds;
+
+import com.google.gson.JsonParser;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.common.DelegateExecutionImpl;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
+import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
+import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters;
+import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf;
+import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.serviceinstancebeans.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@RunWith(MockitoJUnitRunner.Silent.class)
+public abstract class AbstractVnfCDSRequestProviderTest {
+
+ protected static final String GENERIC_VNF_ID = "vnfId_configVnfTest1";
+ protected static final String VF_MODULE_ID = "vf-module-id-1";
+ protected static final String VF_MODULE_NAME = "vf-module-name-1";
+ protected static final String VF_MODULE_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce1";
+ protected static final String GENERIC_VNF_NAME = "vnf-name-1";
+ protected static final String SERVICE_INSTANCE_ID = "serviceInst_configTest";
+ protected static final String SERVICE_MODEL_UUID = "b45b5780-e5dd-11e9-81b4-2a2ae2dbcce4";
+ protected static final String SERVICE_INSTANCE_NAME = "test-service-instance";
+ protected static final String VNF_MODEL_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4";
+ protected static final String GENERAL_BLOCK_EXECUTION_MAP_KEY = "gBBInput";
+ protected static final String VNF_SCOPE = "vnf";
+ protected static final String SERVICE_SCOPE = "service";
+ protected static final String SERVICE_ACTION = "create";
+ protected static final String VF_SCOPE = "vfModule";
+ protected static final String ASSIGN_ACTION = "configAssign";
+ protected static final String DEPLOY_ACTION = "configDeploy";
+ protected static final String MSO_REQUEST_ID = "1234";
+ protected static final String BUILDING_BLOCK = "buildingBlock";
+ protected static final String PUBLIC_NET_ID = "public-net-id";
+ protected static final String CLOUD_REGION = "acl-cloud-region";
+
+ @Mock
+ protected ExtractPojosForBB extractPojosForBB;
+
+ protected BuildingBlockExecution buildingBlockExecution;
+
+ protected ExecuteBuildingBlock executeBuildingBlock;
+
+
+ @Before
+ public void setUp() {
+ buildingBlockExecution = createBuildingBlockExecution();
+ executeBuildingBlock = new ExecuteBuildingBlock();
+ }
+
+ protected BuildingBlockExecution createBuildingBlockExecution() {
+ DelegateExecution execution = new DelegateExecutionFake();
+ execution.setVariable(GENERAL_BLOCK_EXECUTION_MAP_KEY, createGeneralBuildingBlock());
+ return new DelegateExecutionImpl(execution);
+ }
+
+ protected GeneralBuildingBlock createGeneralBuildingBlock() {
+ GeneralBuildingBlock generalBuildingBlock = new GeneralBuildingBlock();
+ RequestContext requestContext = new RequestContext();
+ RequestParameters requestParameters = new RequestParameters();
+ requestParameters.setUserParams(createRequestUserParams());
+ requestContext.setRequestParameters(requestParameters);
+ requestContext.setMsoRequestId(MSO_REQUEST_ID);
+ generalBuildingBlock.setRequestContext(requestContext);
+ return generalBuildingBlock;
+ }
+
+ protected ServiceInstance createServiceInstance() {
+ ServiceInstance serviceInstance = new ServiceInstance();
+ serviceInstance.setServiceInstanceName(SERVICE_INSTANCE_NAME);
+ serviceInstance.setServiceInstanceId(SERVICE_INSTANCE_ID);
+ ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance();
+ modelInfoServiceInstance.setModelUuid(SERVICE_MODEL_UUID);
+ serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance);
+ return serviceInstance;
+ }
+
+ protected GenericVnf createGenericVnf() {
+ GenericVnf genericVnf = new GenericVnf();
+ genericVnf.setVnfId(GENERIC_VNF_ID);
+ genericVnf.setVnfName(GENERIC_VNF_NAME);
+ genericVnf.setBlueprintName("test");
+ genericVnf.setBlueprintVersion("1.0.0");
+ ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
+ modelInfoGenericVnf.setModelCustomizationUuid(VNF_MODEL_CUSTOMIZATION_UUID);
+ genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
+ return genericVnf;
+ }
+
+ protected VfModule createVfModule() {
+ VfModule vfModule = new VfModule();
+ vfModule.setVfModuleId(VF_MODULE_ID);
+ vfModule.setVfModuleName(VF_MODULE_NAME);
+ ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule();
+ modelInfoVfModule.setModelCustomizationUUID(VF_MODULE_CUSTOMIZATION_UUID);
+ vfModule.setModelInfoVfModule(modelInfoVfModule);
+ return vfModule;
+ }
+
+ protected List<Map<String, Object>> createRequestUserParams() {
+ List<Map<String, Object>> userParams = new ArrayList<>();
+ Map<String, Object> userParamMap = new HashMap<>();
+ userParamMap.put("service", getUserParams());
+ userParams.add(userParamMap);
+ return userParams;
+ }
+
+ protected Service getUserParams() {
+ Service service = new Service();
+ Resources resources = new Resources();
+ resources.setVnfs(createVnfList());
+ service.setResources(resources);
+ return service;
+ }
+
+ protected List<Vnfs> createVnfList() {
+ List<Map<String, String>> instanceParamsListSearchedVnf = new ArrayList<>();
+ Map<String, String> instanceParam = new HashMap<>();
+ instanceParam.put("public_net_id", PUBLIC_NET_ID);
+ instanceParam.put("acl-cloud-region", CLOUD_REGION);
+ instanceParamsListSearchedVnf.add(instanceParam);
+ Vnfs searchedVnf = createVnf(instanceParamsListSearchedVnf);
+ List<Vnfs> vnfList = new ArrayList<>();
+ vnfList.add(searchedVnf);
+ return vnfList;
+ }
+
+ protected Vnfs createVnf(List<Map<String, String>> instanceParamsList) {
+ Vnfs vnf = new Vnfs();
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelCustomizationId(VNF_MODEL_CUSTOMIZATION_UUID);
+ vnf.setModelInfo(modelInfo);
+ vnf.setInstanceParams(instanceParamsList);
+
+ // Set instance parameters and modelinfo for vf-module
+ VfModules vfModule = new VfModules();
+ ModelInfo modelInfoForVfModule = new ModelInfo();
+ modelInfoForVfModule.setModelCustomizationId(VF_MODULE_CUSTOMIZATION_UUID);
+ vfModule.setModelInfo(modelInfoForVfModule);
+
+ List<Map<String, String>> instanceParamsListSearchedVfModule = new ArrayList<>();
+ Map<String, String> instanceParams = new HashMap<>();
+ instanceParams.put("public-net-vf-module-id", PUBLIC_NET_ID);
+ instanceParams.put("aci-cloud-region-vf-module", CLOUD_REGION);
+
+ instanceParamsListSearchedVfModule.add(instanceParams);
+ vfModule.setInstanceParams(instanceParamsListSearchedVfModule);
+
+ List<VfModules> vfModules = new ArrayList<>();
+ vfModules.add(vfModule);
+
+ vnf.setVfModules(vfModules);
+
+ return vnf;
+ }
+
+ protected boolean verfiyJsonFromString(String payload) {
+ JsonParser parser = new JsonParser();
+ return parser.parse(payload).isJsonObject();
+ }
+
+ protected void setScopeAndAction(String scope, String action) {
+ BuildingBlock buildingBlock = new BuildingBlock();
+ buildingBlock.setBpmnScope(scope);
+ buildingBlock.setBpmnAction(action);
+ executeBuildingBlock.setBuildingBlock(buildingBlock);
+ buildingBlockExecution.setVariable(BUILDING_BLOCK, executeBuildingBlock);
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java
new file mode 100644
index 0000000000..9baf5dc5bf
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java
@@ -0,0 +1,127 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * 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.client.cds;
+
+import com.google.gson.JsonObject;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.serviceinstancebeans.ModelInfo;
+import org.onap.so.serviceinstancebeans.Resources;
+import org.onap.so.serviceinstancebeans.Service;
+import org.onap.so.serviceinstancebeans.VfModules;
+import org.onap.so.serviceinstancebeans.Vnfs;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.Mockito.doReturn;
+
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class ConfigureInstanceParamsForVfModuleTest {
+
+ @InjectMocks
+ private ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule;
+
+ @Mock
+ private ExtractServiceFromUserParameters extractServiceFromUserParameters;
+
+ private static final String TEST_VNF_MODEL_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4";
+ private static final String TEST_VF_MODULE_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce2";
+ private static final String TEST_INSTANCE_PARAM_VALUE_1 = "vf-module-1-value";
+ private static final String TEST_INSTANCE_PARAM_VALUE_2 = "vf-module-2-value";
+ private static final String TEST_INSTANCE_PARAM_KEY_1 = "instance-param-1";
+ private static final String TEST_INSTANCE_PARAM_KEY_2 = "instance-param-2";
+
+ @Test
+ public void testInstanceParamsForVfModule() throws Exception {
+ // given
+ List<Map<String, Object>> userParamsFromRequest = createRequestParameters();
+ JsonObject jsonObject = new JsonObject();
+ doReturn(getUserParams()).when(extractServiceFromUserParameters).getServiceFromRequestUserParams(anyList());
+
+ // when
+ configureInstanceParamsForVfModule.populateInstanceParams(jsonObject, userParamsFromRequest,
+ TEST_VNF_MODEL_CUSTOMIZATION_UUID, TEST_VF_MODULE_CUSTOMIZATION_UUID);
+
+ // verify
+ assertEquals(TEST_INSTANCE_PARAM_VALUE_1, jsonObject.get(TEST_INSTANCE_PARAM_KEY_1).getAsString());
+ assertEquals(TEST_INSTANCE_PARAM_VALUE_2, jsonObject.get(TEST_INSTANCE_PARAM_KEY_2).getAsString());
+ }
+
+ private List<Map<String, Object>> createRequestParameters() {
+ List<Map<String, Object>> userParams = new ArrayList<>();
+ Map<String, Object> userParamMap = new HashMap<>();
+ userParamMap.put("service", getUserParams());
+ userParams.add(userParamMap);
+ return userParams;
+ }
+
+ private Service getUserParams() {
+ Service service = new Service();
+ Resources resources = new Resources();
+ resources.setVnfs(createVnfs());
+ service.setResources(resources);
+ return service;
+ }
+
+ private List<Vnfs> createVnfs() {
+ Vnfs searchedVnf = createVnf();
+ List<Vnfs> vnfList = new ArrayList<>();
+ vnfList.add(searchedVnf);
+ return vnfList;
+ }
+
+ private Vnfs createVnf() {
+ Vnfs vnf = new Vnfs();
+ ModelInfo modelInfoForVnf = new ModelInfo();
+ modelInfoForVnf.setModelCustomizationId(TEST_VNF_MODEL_CUSTOMIZATION_UUID);
+ vnf.setModelInfo(modelInfoForVnf);
+
+ VfModules vfModule = new VfModules();
+
+ ModelInfo modelInfoForVfModule = new ModelInfo();
+ modelInfoForVfModule.setModelCustomizationId(TEST_VF_MODULE_CUSTOMIZATION_UUID);
+
+ vfModule.setModelInfo(modelInfoForVfModule);
+
+ // Set instance parameters.
+ List<Map<String, String>> instanceParamsListSearchedVfModule = new ArrayList<>();
+ Map<String, String> instanceParams = new HashMap<>();
+ instanceParams.put("instance-param-1", TEST_INSTANCE_PARAM_VALUE_1);
+ instanceParams.put("instance-param-2", TEST_INSTANCE_PARAM_VALUE_2);
+
+ instanceParamsListSearchedVfModule.add(instanceParams);
+ vfModule.setInstanceParams(instanceParamsListSearchedVfModule);
+
+ List<VfModules> vfModules = new ArrayList<>();
+ vfModules.add(vfModule);
+
+ vnf.setVfModules(vfModules);
+
+ return vnf;
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/GeneratePayloadForCdsTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/GeneratePayloadForCdsTest.java
new file mode 100644
index 0000000000..24962a0c14
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/GeneratePayloadForCdsTest.java
@@ -0,0 +1,342 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada.
+ * ================================================================================
+ * 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.client.cds;
+
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.common.DelegateExecutionImpl;
+import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
+import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters;
+import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
+import org.onap.so.client.exception.PayloadGenerationException;
+import org.onap.so.serviceinstancebeans.*;
+import java.util.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.ThrowableAssert.catchThrowable;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class GeneratePayloadForCdsTest {
+ private static final String VF_MODULE_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce1";
+ private static final String VNF_MODEL_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4";
+ private static final String GENERAL_BLOCK_EXECUTION_MAP_KEY = "gBBInput";
+ private static final String VNF_SCOPE = "vnf";
+ private static final String SERVICE_SCOPE = "service";
+ private static final String SERVICE_ACTION = "create";
+ private static final String VF_SCOPE = "vfModule";
+ private static final String ASSIGN_ACTION = "configAssign";
+ private static final String DEPLOY_ACTION = "configDeploy";
+ private static final String DOWNLOAD_ACTION = "downloadNeSw";
+ private static final String MSO_REQUEST_ID = "1234";
+ private static final String BUILDING_BLOCK = "buildingBlock";
+ private static final String PUBLIC_NET_ID = "public-net-id";
+ private static final String CLOUD_REGION = "acl-cloud-region";
+ private static final String TEST_MODEL_UUID = "6bc0b04d-1873-4721-b53d-6615225b2a28";
+ private static final String TEST_SERVICE_INSTANCE_ID = "test_service_id";
+ private static final String TEST_PROCESS_KEY = "processKey1";
+ private static final String TEST_PNF_RESOURCE_INSTANCE_NAME = "PNF_demo_resource";
+ private static final String TEST_PNF_CORRELATION_ID = "PNFDemo";
+ private static final String TEST_PNF_RESOURCE_CUSTOMIZATION_UUID = "9acb3a83-8a52-412c-9a45-901764938144";
+ private static final String TEST_MSO_REQUEST_ID = "ff874603-4222-11e7-9252-005056850d2e";
+ private static final String TEST_PNF_UUID = "5df8b6de-2083-11e7-93ae-92361f002671";
+ private static final String TEST_SOFTWARE_VERSION = "demo-sw-ver2.0.0";
+ private static final String PNF_CORRELATION_ID = "pnfCorrelationId";
+ private static final String PNF_UUID = "pnfUuid";
+ private static final String SERVICE_INSTANCE_ID = "serviceInstanceId";
+ private static final String MODEL_UUID = "modelUuid";
+ private static final String PRC_CUSTOMIZATION_UUID = "PRC_customizationUuid";
+ private static final String PRC_INSTANCE_NAME = "PRC_instanceName";
+ private static final String PRC_TARGET_SOFTWARE_VERSION = "targetSoftwareVersion";
+ private static final String SCOPE = "scope";
+ private static final String ACTION = "action";
+ private static final String PROCESS_KEY = "testProcessKey";
+ private static final String PRC_BLUEPRINT_NAME = "PRC_blueprintName";
+ private static final String PRC_BLUEPRINT_VERSION = "PRC_blueprintVersion";
+ private static final String TEST_PNF_RESOURCE_BLUEPRINT_NAME = "blueprintOnap";
+ private static final String TEST_PNF_RESOURCE_BLUEPRINT_VERSION = "1.0.1";
+
+ private BuildingBlockExecution buildingBlockExecution;
+ private ExecuteBuildingBlock executeBuildingBlock;
+
+ @InjectMocks
+ private GeneratePayloadForCds configurePayloadForCds;
+
+ @Mock
+ private VnfCDSRequestProvider vnfCDSRequestProvider;
+
+ @Mock
+ private VfModuleCDSRequestProvider vfModuleCDSRequestProvider;
+
+ @Mock
+ private ServiceCDSRequestProvider serviceCDSRequestProvider;
+
+ @Mock
+ private PnfCDSRequestProvider pnfCDSRequestProvider;
+
+
+ @Before
+ public void setup() {
+ buildingBlockExecution = createBuildingBlockExecution();
+ executeBuildingBlock = new ExecuteBuildingBlock();
+ }
+
+ @Test
+ public void testBuildCdsPropertiesBeanAssignVnf() throws Exception {
+ // given
+ final String assignPayload =
+ "{\"configAssign-request\":{\"resolution-key\":\"vnf-name-1\",\"configAssign-properties\":{\"service-instance-id\":\"serviceInst_configTest\",\"service-model-uuid\":\"b45b5780-e5dd-11e9-81b4-2a2ae2dbcce4\",\"vnf-id\":\"vnfId_configVnfTest1\",\"vnf-name\":\"vnf-name-1\",\"vnf-customization-uuid\":\"23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4\",\"acl-cloud-region\":\"acl-cloud-region\",\"public_net_id\":\"public-net-id\"}}}";
+ setScopeAndAction(VNF_SCOPE, ASSIGN_ACTION);
+ doReturn(Optional.of(assignPayload)).when(vnfCDSRequestProvider).buildRequestPayload(ASSIGN_ACTION);
+
+ // when
+ AbstractCDSPropertiesBean propertyBean = configurePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution);
+
+ // verify
+ assertNotNull(propertyBean);
+ String payload = propertyBean.getRequestObject();
+ assertThat(assignPayload.equals(payload));
+ assertThat(propertyBean.getRequestId().equals(MSO_REQUEST_ID));
+ assertThat(propertyBean.getOriginatorId().equals("SO"));
+ assertNotNull(propertyBean.getSubRequestId());
+ assertThat(propertyBean.getActionName().equals(ASSIGN_ACTION));
+ assertThat(propertyBean.getMode().equalsIgnoreCase("sync"));
+ }
+
+ @Test
+ public void testBuildCdsPropertiesBeanDeployVnf() throws Exception {
+ // given
+ final String deployPayload =
+ "{\"configDeploy-request\":{\"resolution-key\":\"vnf-name-1\",\"configDeploy-properties\":{\"service-instance-id\":\"serviceInst_configTest\",\"service-model-uuid\":\"b45b5780-e5dd-11e9-81b4-2a2ae2dbcce4\",\"vnf-id\":\"vnfId_configVnfTest1\",\"vnf-name\":\"vnf-name-1\",\"vnf-customization-uuid\":\"23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4\",\"acl-cloud-region\":\"acl-cloud-region\",\"public_net_id\":\"public-net-id\"}}}";
+ setScopeAndAction(VNF_SCOPE, DEPLOY_ACTION);
+ doReturn(Optional.of(deployPayload)).when(vnfCDSRequestProvider).buildRequestPayload(DEPLOY_ACTION);
+
+ // when
+ AbstractCDSPropertiesBean propertyBean = configurePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution);
+
+ // verify
+ assertNotNull(propertyBean);
+ String payload = propertyBean.getRequestObject();
+ assertThat(deployPayload.equals(payload));
+ assertThat(propertyBean.getRequestId().equals(MSO_REQUEST_ID));
+ assertThat(propertyBean.getOriginatorId().equals("SO"));
+ assertNotNull(propertyBean.getSubRequestId());
+ assertThat(propertyBean.getActionName().equals(DEPLOY_ACTION));
+ assertThat(propertyBean.getMode().equalsIgnoreCase("sync"));
+ }
+
+ @Test
+ public void testBuildCdsPropertiesBeanCreateService() throws Exception {
+ // given
+ final String servicePayload =
+ "{\"create-request\":{\"resolution-key\":\"test-service-instance\",\"create-properties\":{\"service-instance-id\":\"serviceInst_configTest\",\"service-model-uuid\":\"b45b5780-e5dd-11e9-81b4-2a2ae2dbcce4\"}}}";
+ setScopeAndAction(SERVICE_SCOPE, SERVICE_ACTION);
+ doReturn(Optional.of(servicePayload)).when(serviceCDSRequestProvider).buildRequestPayload(SERVICE_ACTION);
+
+ // when
+ AbstractCDSPropertiesBean propertyBean = configurePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution);
+
+ // verify
+ assertNotNull(propertyBean);
+ String payload = propertyBean.getRequestObject();
+ assertThat(servicePayload.equals(payload));
+ assertThat(propertyBean.getRequestId().equals(MSO_REQUEST_ID));
+ assertThat(propertyBean.getOriginatorId().equals("SO"));
+ assertNotNull(propertyBean.getSubRequestId());
+ assertThat(propertyBean.getActionName().equals(SERVICE_ACTION));
+ assertThat(propertyBean.getMode().equalsIgnoreCase("sync"));
+ }
+
+ @Test
+ public void testBuildCdsPropertiesBeanConfigDeployVfModule() throws Exception {
+ // given
+ final String deployVfModulePayload =
+ "{\"configDeploy-request\":{\"resolution-key\":\"vf-module-name-1\",\"template-prefix\":\"vf-module-name-1configDeploy\",\"configDeploy-properties\":{\"service-instance-id\":\"serviceInst_configTest\",\"service-model-uuid\":\"b45b5780-e5dd-11e9-81b4-2a2ae2dbcce4\",\"vnf-id\":\"vnfId_configVnfTest1\",\"vnf-name\":\"vnf-name-1\",\"vf-module-id\":\"vf-module-id-1\",\"vf-module-name\":\"vf-module-name-1\",\"vf-module-customization-uuid\":\"23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce1\",\"aci-cloud-region-vf-module\":\"acl-cloud-region\",\"public-net-vf-module-id\":\"public-net-id\"}}}";
+ setScopeAndAction(VF_SCOPE, DEPLOY_ACTION);
+ doReturn(Optional.of(deployVfModulePayload)).when(vfModuleCDSRequestProvider)
+ .buildRequestPayload(DEPLOY_ACTION);
+
+ // when
+ AbstractCDSPropertiesBean propertyBean = configurePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution);
+
+ // verify
+ assertNotNull(propertyBean);
+ String payload = propertyBean.getRequestObject();
+ assertThat(deployVfModulePayload.equals(payload));
+ assertThat(propertyBean.getRequestId().equals(MSO_REQUEST_ID));
+ assertThat(propertyBean.getOriginatorId().equals("SO"));
+ assertNotNull(propertyBean.getSubRequestId());
+ assertThat(propertyBean.getActionName().equals(DEPLOY_ACTION));
+ assertThat(propertyBean.getMode().equalsIgnoreCase("sync"));
+ }
+
+ @Test
+ public void testBuildCdsPropertiesBeanDownloadPnf() throws Exception {
+ // given
+ final String downloadPayload =
+ "{\"downloadNeSw-request\":{\"resolution-key\":\"PNFDemo\",\"downloadNeSw-properties\":{\"service-instance-id\":\"test_service_id\",\"service-model-uuid\":\"6bc0b04d-1873-4721-b53d-6615225b2a28\",\"pnf-id\":\"5df8b6de-2083-11e7-93ae-92361f002671\",\"pnf-name\":\"PNFDemo\",\"pnf-customization-uuid\":\"9acb3a83-8a52-412c-9a45-901764938144\",\"target-software-version\":\"demo-sw-ver2.0.0\"}}}";
+ DelegateExecution execution = prepareDelegateExecutionObj(PayloadConstants.PNF_SCOPE, DOWNLOAD_ACTION);
+ doReturn(Optional.of(downloadPayload)).when(pnfCDSRequestProvider).buildRequestPayload(DOWNLOAD_ACTION);
+ doReturn(TEST_PNF_RESOURCE_BLUEPRINT_NAME).when(pnfCDSRequestProvider).getBlueprintName();
+ doReturn(TEST_PNF_RESOURCE_BLUEPRINT_VERSION).when(pnfCDSRequestProvider).getBlueprintVersion();
+
+ // when
+ AbstractCDSPropertiesBean propertyBean = configurePayloadForCds.buildCdsPropertiesBean(execution);
+
+ // verify
+ assertNotNull(propertyBean);
+ String payload = propertyBean.getRequestObject();
+ assertThat(downloadPayload.equals(payload));
+ assertThat(propertyBean.getRequestId().equals(MSO_REQUEST_ID));
+ assertThat(propertyBean.getOriginatorId().equals("SO"));
+ assertNotNull(propertyBean.getSubRequestId());
+ assertThat(propertyBean.getActionName().equals(DOWNLOAD_ACTION));
+ assertThat(propertyBean.getMode().equalsIgnoreCase("async"));
+ assertThat(propertyBean.getBlueprintName().equalsIgnoreCase(TEST_PNF_RESOURCE_BLUEPRINT_NAME));
+ assertThat(propertyBean.getBlueprintVersion().equalsIgnoreCase(TEST_PNF_RESOURCE_BLUEPRINT_VERSION));
+ }
+
+ @Test
+ public void testFailureWhenServiceInstanceIsNotPresent() throws Exception {
+ // given
+ setScopeAndAction(VNF_SCOPE, ASSIGN_ACTION);
+ doThrow(PayloadGenerationException.class).when(serviceCDSRequestProvider).buildRequestPayload(ASSIGN_ACTION);
+
+ // when
+ final Throwable throwable =
+ catchThrowable(() -> configurePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution));
+
+ // verify
+ assertThat(throwable).isInstanceOf(PayloadGenerationException.class)
+ .hasMessage("Failed to build payload for CDS");
+ }
+
+ private BuildingBlockExecution createBuildingBlockExecution() {
+ DelegateExecution execution = new DelegateExecutionFake();
+ execution.setVariable(GENERAL_BLOCK_EXECUTION_MAP_KEY, createGeneralBuildingBlock());
+ return new DelegateExecutionImpl(execution);
+ }
+
+ private GeneralBuildingBlock createGeneralBuildingBlock() {
+ GeneralBuildingBlock generalBuildingBlock = new GeneralBuildingBlock();
+ RequestContext requestContext = new RequestContext();
+ RequestParameters requestParameters = new RequestParameters();
+ requestParameters.setUserParams(createRequestUserParams());
+ requestContext.setRequestParameters(requestParameters);
+ requestContext.setMsoRequestId(MSO_REQUEST_ID);
+ generalBuildingBlock.setRequestContext(requestContext);
+ return generalBuildingBlock;
+ }
+
+ private List<Map<String, Object>> createRequestUserParams() {
+ List<Map<String, Object>> userParams = new ArrayList<>();
+ Map<String, Object> userParamMap = new HashMap<>();
+ userParamMap.put("service", getUserParams());
+ userParams.add(userParamMap);
+ return userParams;
+ }
+
+ private Service getUserParams() {
+ Service service = new Service();
+ Resources resources = new Resources();
+ resources.setVnfs(createVnfList());
+ service.setResources(resources);
+ return service;
+ }
+
+ private List<Vnfs> createVnfList() {
+ List<Map<String, String>> instanceParamsListSearchedVnf = new ArrayList<>();
+ Map<String, String> instanceParam = new HashMap<>();
+ instanceParam.put("public_net_id", PUBLIC_NET_ID);
+ instanceParam.put("acl-cloud-region", CLOUD_REGION);
+ instanceParamsListSearchedVnf.add(instanceParam);
+ Vnfs searchedVnf = createVnf(instanceParamsListSearchedVnf);
+ List<Vnfs> vnfList = new ArrayList<>();
+ vnfList.add(searchedVnf);
+ return vnfList;
+ }
+
+ private Vnfs createVnf(List<Map<String, String>> instanceParamsList) {
+ Vnfs vnf = new Vnfs();
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelCustomizationId(VNF_MODEL_CUSTOMIZATION_UUID);
+ vnf.setModelInfo(modelInfo);
+ vnf.setInstanceParams(instanceParamsList);
+
+ // Set instance parameters and modelinfo for vf-module
+ VfModules vfModule = new VfModules();
+ ModelInfo modelInfoForVfModule = new ModelInfo();
+ modelInfoForVfModule.setModelCustomizationId(VF_MODULE_CUSTOMIZATION_UUID);
+ vfModule.setModelInfo(modelInfoForVfModule);
+
+ List<Map<String, String>> instanceParamsListSearchedVfModule = new ArrayList<>();
+ Map<String, String> instanceParams = new HashMap<>();
+ instanceParams.put("public-net-vf-module-id", PUBLIC_NET_ID);
+ instanceParams.put("aci-cloud-region-vf-module", CLOUD_REGION);
+
+ instanceParamsListSearchedVfModule.add(instanceParams);
+ vfModule.setInstanceParams(instanceParamsListSearchedVfModule);
+
+ List<VfModules> vfModules = new ArrayList<>();
+ vfModules.add(vfModule);
+
+ vnf.setVfModules(vfModules);
+
+ return vnf;
+ }
+
+ private void setScopeAndAction(String scope, String action) {
+ BuildingBlock buildingBlock = new BuildingBlock();
+ buildingBlock.setBpmnScope(scope);
+ buildingBlock.setBpmnAction(action);
+ executeBuildingBlock.setBuildingBlock(buildingBlock);
+ buildingBlockExecution.setVariable(BUILDING_BLOCK, executeBuildingBlock);
+ }
+
+ private DelegateExecution prepareDelegateExecutionObj(String scope, String action) {
+ DelegateExecution execution = new DelegateExecutionFake();
+ execution.setVariable(PROCESS_KEY, TEST_PROCESS_KEY);
+ execution.setVariable(PNF_CORRELATION_ID, TEST_PNF_CORRELATION_ID);
+ execution.setVariable(MODEL_UUID, TEST_MODEL_UUID);
+ execution.setVariable(SERVICE_INSTANCE_ID, TEST_SERVICE_INSTANCE_ID);
+ execution.setVariable(MSO_REQUEST_ID, TEST_MSO_REQUEST_ID);
+ execution.setVariable(PNF_UUID, TEST_PNF_UUID);
+ execution.setVariable(PRC_INSTANCE_NAME, TEST_PNF_RESOURCE_INSTANCE_NAME);
+ execution.setVariable(PRC_CUSTOMIZATION_UUID, TEST_PNF_RESOURCE_CUSTOMIZATION_UUID);
+ execution.setVariable(PRC_TARGET_SOFTWARE_VERSION, TEST_SOFTWARE_VERSION);
+ execution.setVariable(PRC_BLUEPRINT_NAME, TEST_PNF_RESOURCE_BLUEPRINT_NAME);
+ execution.setVariable(PRC_BLUEPRINT_VERSION, TEST_PNF_RESOURCE_BLUEPRINT_VERSION);
+ execution.setVariable(SCOPE, scope);
+ execution.setVariable(ACTION, action);
+ execution.setVariable("mode", "async");
+ return execution;
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/PnfCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/PnfCDSRequestProviderTest.java
new file mode 100644
index 0000000000..e5cbc9a369
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/PnfCDSRequestProviderTest.java
@@ -0,0 +1,139 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.cds;
+
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.JsonParser;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.junit.MockitoJUnitRunner;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class PnfCDSRequestProviderTest {
+
+ @InjectMocks
+ private PnfCDSRequestProvider pnfCDSRequestProvider;
+
+ private static final String DOWNLOAD_ACTION = "downloadNeSw";
+ private static final String ACTIVATE_ACTION = "activateNeSw";
+ private static final String TEST_MODEL_UUID = "6bc0b04d-1873-4721-b53d-6615225b2a28";
+ private static final String TEST_SERVICE_INSTANCE_ID = "test_service_id";
+ private static final String TEST_PROCESS_KEY = "processKey1";
+ private static final String TEST_PNF_RESOURCE_INSTANCE_NAME = "PNF_demo_resource";
+ private static final String TEST_PNF_CORRELATION_ID = "PNFDemo";
+ private static final String TEST_PNF_RESOURCE_CUSTOMIZATION_UUID = "9acb3a83-8a52-412c-9a45-901764938144";
+ private static final String TEST_MSO_REQUEST_ID = "ff874603-4222-11e7-9252-005056850d2e";
+ private static final String TEST_PNF_UUID = "5df8b6de-2083-11e7-93ae-92361f002671";
+ private static final String TEST_SOFTWARE_VERSION = "demo-sw-ver2.0.0";
+ private static final String PNF_CORRELATION_ID = "pnfCorrelationId";
+ private static final String PNF_UUID = "pnfUuid";
+ private static final String SERVICE_INSTANCE_ID = "serviceInstanceId";
+ private static final String MSO_REQUEST_ID = "msoRequestId";
+ private static final String MODEL_UUID = "modelUuid";
+ private static final String PRC_CUSTOMIZATION_UUID = "PRC_customizationUuid";
+ private static final String PRC_INSTANCE_NAME = "PRC_instanceName";
+ private static final String PRC_TARGET_SOFTWARE_VERSION = "targetSoftwareVersion";
+ private static final String SCOPE = "scope";
+ private static final String ACTION = "action";
+ private static final String PROCESS_KEY = "testProcessKey";
+ private static final String PRC_BLUEPRINT_NAME = "PRC_blueprintName";
+ private static final String PRC_BLUEPRINT_VERSION = "PRC_blueprintVersion";
+ private static final String TEST_PNF_RESOURCE_BLUEPRINT_NAME = "blueprintOnap";
+ private static final String TEST_PNF_RESOURCE_BLUEPRINT_VERSION = "1.0.1";
+
+ @Test
+ public void testBuildRequestPayloadDownloadActionPnf() {
+ try {
+ runTest(DOWNLOAD_ACTION);
+ } catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testBuildRequestPayloadActivateActionPnf() {
+ try {
+ runTest(ACTIVATE_ACTION);
+ } catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
+ private void runTest(String action) throws Exception {
+ // given
+ DelegateExecution execution = prepareDelegateExecutionObj(PayloadConstants.PNF_SCOPE, action);
+
+ // when
+ pnfCDSRequestProvider.setExecutionObject(execution);
+ String payload = pnfCDSRequestProvider.buildRequestPayload(action).get();
+ System.out.println(payload);
+
+ // verify
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode payloadJson = mapper.readTree(payload);
+ JsonNode requestNode = payloadJson.findValue(action + "-request");
+ JsonNode propertiesNode = payloadJson.findValue(action + "-properties");
+
+ assertNotNull(payload);
+ assertTrue(verfiyJsonFromString(payload));
+ assertThat(requestNode.get("resolution-key").asText()).isEqualTo(TEST_PNF_CORRELATION_ID);
+ assertThat(propertiesNode.get("service-instance-id").asText()).isEqualTo(TEST_SERVICE_INSTANCE_ID);
+ assertThat(propertiesNode.get("service-model-uuid").asText()).isEqualTo(TEST_MODEL_UUID);
+ assertThat(propertiesNode.get("pnf-id").asText()).isEqualTo(TEST_PNF_UUID);
+ assertThat(propertiesNode.get("pnf-customization-uuid").asText())
+ .isEqualTo(TEST_PNF_RESOURCE_CUSTOMIZATION_UUID);
+ assertThat(propertiesNode.get("target-software-version").asText()).isEqualTo(TEST_SOFTWARE_VERSION);
+ assertThat(pnfCDSRequestProvider.getBlueprintName().equals(TEST_PNF_RESOURCE_BLUEPRINT_NAME));
+ assertThat(pnfCDSRequestProvider.getBlueprintVersion().equals(TEST_PNF_RESOURCE_BLUEPRINT_VERSION));
+ }
+
+ private DelegateExecution prepareDelegateExecutionObj(String scope, String action) {
+ DelegateExecution execution = new DelegateExecutionFake();
+ execution.setVariable(PROCESS_KEY, TEST_PROCESS_KEY);
+ execution.setVariable(PNF_CORRELATION_ID, TEST_PNF_CORRELATION_ID);
+ execution.setVariable(MODEL_UUID, TEST_MODEL_UUID);
+ execution.setVariable(SERVICE_INSTANCE_ID, TEST_SERVICE_INSTANCE_ID);
+ execution.setVariable(MSO_REQUEST_ID, TEST_MSO_REQUEST_ID);
+ execution.setVariable(PNF_UUID, TEST_PNF_UUID);
+ execution.setVariable(PRC_INSTANCE_NAME, TEST_PNF_RESOURCE_INSTANCE_NAME);
+ execution.setVariable(PRC_CUSTOMIZATION_UUID, TEST_PNF_RESOURCE_CUSTOMIZATION_UUID);
+ execution.setVariable(PRC_TARGET_SOFTWARE_VERSION, TEST_SOFTWARE_VERSION);
+ execution.setVariable(SCOPE, scope);
+ execution.setVariable(ACTION, action);
+ execution.setVariable(PRC_BLUEPRINT_NAME, TEST_PNF_RESOURCE_BLUEPRINT_NAME);
+ execution.setVariable(PRC_BLUEPRINT_VERSION, TEST_PNF_RESOURCE_BLUEPRINT_VERSION);
+ return execution;
+ }
+
+ private boolean verfiyJsonFromString(String payload) {
+ JsonParser parser = new JsonParser();
+ return parser.parse(payload).isJsonObject();
+ }
+
+}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ServiceCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ServiceCDSRequestProviderTest.java
new file mode 100644
index 0000000000..70ce3a1eed
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ServiceCDSRequestProviderTest.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.cds;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.*;
+
+public class ServiceCDSRequestProviderTest extends AbstractVnfCDSRequestProviderTest {
+
+ @InjectMocks
+ private ServiceCDSRequestProvider serviceCDSRequestProvider;
+
+ @Test
+ public void testRequestPayloadForCreateService() throws Exception {
+ // given
+ setScopeAndAction(SERVICE_SCOPE, SERVICE_ACTION);
+ ServiceInstance instance = createServiceInstance();
+ doReturn(instance).when(extractPojosForBB).extractByKey(buildingBlockExecution,
+ ResourceKey.SERVICE_INSTANCE_ID);
+
+ // when
+ serviceCDSRequestProvider.setExecutionObject(buildingBlockExecution);
+ String payload = serviceCDSRequestProvider.buildRequestPayload(SERVICE_ACTION).get();
+
+ // verify
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode payloadJson = mapper.readTree(payload);
+ JsonNode requestNode = payloadJson.findValue("create-request");
+ JsonNode propertiesNode = payloadJson.findValue("create-properties");
+
+ assertNotNull(payload);
+ assertTrue(verfiyJsonFromString(payload));
+ assertThat(requestNode.get("resolution-key").asText()).isEqualTo(SERVICE_INSTANCE_NAME);
+ assertThat(propertiesNode.get("service-instance-id").asText()).isEqualTo(SERVICE_INSTANCE_ID);
+ assertThat(propertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID);
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java
new file mode 100644
index 0000000000..2ca09d9ab3
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.cds;
+
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.*;
+
+public class VfModuleCDSRequestProviderTest extends AbstractVnfCDSRequestProviderTest {
+
+ @InjectMocks
+ private VfModuleCDSRequestProvider vfModuleCDSRequestProvider;
+
+ @Mock
+ protected ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule;
+
+ @Test
+ public void testRequestPayloadForConfigDeployVfModule() throws Exception {
+ // given
+ setScopeAndAction(VF_SCOPE, DEPLOY_ACTION);
+ ServiceInstance serviceInstance = createServiceInstance();
+
+ doReturn(serviceInstance).when(extractPojosForBB).extractByKey(buildingBlockExecution,
+ ResourceKey.SERVICE_INSTANCE_ID);
+ doReturn(createGenericVnf()).when(extractPojosForBB).extractByKey(buildingBlockExecution,
+ ResourceKey.GENERIC_VNF_ID);
+ doReturn(createVfModule()).when(extractPojosForBB).extractByKey(buildingBlockExecution,
+ ResourceKey.VF_MODULE_ID);
+ doNothing().when(configureInstanceParamsForVfModule).populateInstanceParams(any(), any(), anyString(),
+ anyString());
+
+ // when
+ vfModuleCDSRequestProvider.setExecutionObject(buildingBlockExecution);
+ String payload = vfModuleCDSRequestProvider.buildRequestPayload(DEPLOY_ACTION).get();
+
+ // verify
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode payloadJson = mapper.readTree(payload);
+ JsonNode requestNode = payloadJson.findValue("configDeploy-request");
+ JsonNode propertiesNode = payloadJson.findValue("configDeploy-properties");
+
+ assertNotNull(payload);
+ assertTrue(verfiyJsonFromString(payload));
+ assertThat(requestNode.get("resolution-key").asText()).isEqualTo(VF_MODULE_NAME);
+ assertThat(propertiesNode.get("service-instance-id").asText()).isEqualTo(SERVICE_INSTANCE_ID);
+ assertThat(propertiesNode.get("vf-module-id").asText()).isEqualTo(VF_MODULE_ID);
+ assertThat(propertiesNode.get("vf-module-name").asText()).isEqualTo(VF_MODULE_NAME);
+ assertThat(propertiesNode.get("vf-module-customization-uuid").asText()).isEqualTo(VF_MODULE_CUSTOMIZATION_UUID);
+ assertThat(propertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID);
+ assertThat(propertiesNode.get("vnf-id").asText()).isEqualTo(GENERIC_VNF_ID);
+ }
+
+
+}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VnfCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VnfCDSRequestProviderTest.java
new file mode 100644
index 0000000000..7aafd900d4
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VnfCDSRequestProviderTest.java
@@ -0,0 +1,104 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.cds;
+
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.*;
+
+public class VnfCDSRequestProviderTest extends AbstractVnfCDSRequestProviderTest {
+
+ @InjectMocks
+ private VnfCDSRequestProvider vnfCDSRequestProvider;
+
+ @Mock
+ protected ConfigureInstanceParamsForVnf configureInstanceParamsForVnf;
+
+ @Test
+ public void testBuildRequestPayloadAssignActionVnf() throws Exception {
+ // given
+ setScopeAndAction(VNF_SCOPE, ASSIGN_ACTION);
+ ServiceInstance instance = createServiceInstance();
+
+ doReturn(instance).when(extractPojosForBB).extractByKey(buildingBlockExecution,
+ ResourceKey.SERVICE_INSTANCE_ID);
+ doReturn(createGenericVnf()).when(extractPojosForBB).extractByKey(buildingBlockExecution,
+ ResourceKey.GENERIC_VNF_ID);
+ doNothing().when(configureInstanceParamsForVnf).populateInstanceParams(any(), any(), anyString());
+
+ // when
+ vnfCDSRequestProvider.setExecutionObject(buildingBlockExecution);
+ String payload = vnfCDSRequestProvider.buildRequestPayload(ASSIGN_ACTION).get();
+
+ // verify
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode payloadJson = mapper.readTree(payload);
+ JsonNode requestNode = payloadJson.findValue("configAssign-request");
+ JsonNode propertiesNode = payloadJson.findValue("configAssign-properties");
+
+ assertNotNull(payload);
+ assertTrue(verfiyJsonFromString(payload));
+ assertThat(requestNode.get("resolution-key").asText()).isEqualTo(GENERIC_VNF_NAME);
+ assertThat(propertiesNode.get("service-instance-id").asText()).isEqualTo(SERVICE_INSTANCE_ID);
+ assertThat(propertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID);
+ assertThat(propertiesNode.get("vnf-id").asText()).isEqualTo(GENERIC_VNF_ID);
+ assertThat(propertiesNode.get("vnf-customization-uuid").asText()).isEqualTo(VNF_MODEL_CUSTOMIZATION_UUID);
+ }
+
+ @Test
+ public void testBuildRequestPayloadDeployActionVnf() throws Exception {
+ // given
+ setScopeAndAction(VNF_SCOPE, DEPLOY_ACTION);
+ ServiceInstance instance = createServiceInstance();
+
+ doReturn(instance).when(extractPojosForBB).extractByKey(buildingBlockExecution,
+ ResourceKey.SERVICE_INSTANCE_ID);
+ doReturn(createGenericVnf()).when(extractPojosForBB).extractByKey(buildingBlockExecution,
+ ResourceKey.GENERIC_VNF_ID);
+ doNothing().when(configureInstanceParamsForVnf).populateInstanceParams(any(), any(), any());
+
+ // when
+ vnfCDSRequestProvider.setExecutionObject(buildingBlockExecution);
+ String payload = vnfCDSRequestProvider.buildRequestPayload(DEPLOY_ACTION).get();
+
+ // verify
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode payloadJson = mapper.readTree(payload);
+ JsonNode requestNode = payloadJson.findValue("configDeploy-request");
+ JsonNode propertiesNode = payloadJson.findValue("configDeploy-properties");
+
+ assertNotNull(payload);
+ assertTrue(verfiyJsonFromString(payload));
+ assertThat(requestNode.get("resolution-key").asText()).isEqualTo(GENERIC_VNF_NAME);
+ assertThat(propertiesNode.get("service-instance-id").asText()).isEqualTo(SERVICE_INSTANCE_ID);
+ assertThat(propertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID);
+ assertThat(propertiesNode.get("vnf-id").asText()).isEqualTo(GENERIC_VNF_ID);
+ assertThat(propertiesNode.get("vnf-customization-uuid").asText()).isEqualTo(VNF_MODEL_CUSTOMIZATION_UUID);
+ }
+}