diff options
Diffstat (limited to 'bpmn')
3 files changed, 477 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/ControllerExecutionBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/ControllerExecutionBB.bpmn new file mode 100644 index 0000000000..32d3bce469 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/ControllerExecutionBB.bpmn @@ -0,0 +1,241 @@ +<?xml version="1.0" encoding="UTF-8"?> +<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1ahlzqg" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.14.0"> + <bpmn:process id="ControllerExecution" name="ControllerExecutionBB" isExecutable="true"> + <bpmn:startEvent id="StartEvent_1"> + <bpmn:outgoing>SequenceFlow_0gmfit3</bpmn:outgoing> + </bpmn:startEvent> + <bpmn:sequenceFlow id="SequenceFlow_0gmfit3" sourceRef="StartEvent_1" targetRef="ServiceTask_0inxg9l" /> + <bpmn:endEvent id="EndEvent_0lgvk82"> + <bpmn:incoming>SequenceFlow_1mkhog2</bpmn:incoming> + <bpmn:incoming>SequenceFlow_0no1qag</bpmn:incoming> + </bpmn:endEvent> + <bpmn:sequenceFlow id="SequenceFlow_1mkhog2" sourceRef="Task_1hs1mn0" targetRef="EndEvent_0lgvk82" /> + <bpmn:callActivity id="CallActivity_1gfzi2g" name="Abstract CDS (CDS Call) " calledElement="AbstractCDSProcessingBB"> + <bpmn:extensionElements> + <camunda:out source="WorkflowException" target="WorkflowException" /> + <camunda:out source="CDSStatus" target="CDSStatus" /> + <camunda:in source="executionObject" target="executionObject" /> + </bpmn:extensionElements> + <bpmn:incoming>SequenceFlow_05qembo</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_0cvsnuu</bpmn:outgoing> + </bpmn:callActivity> + <bpmn:serviceTask id="Task_1hs1mn0" name="Update AAI" camunda:expression="${AAIUpdateTasks.updateOrchestrationStatus(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution")),InjectExecution.execute(execution, execution.getVariable("scope")),InjectExecution.execute(execution, execution.getVariable("action")))}"> + <bpmn:incoming>SequenceFlow_07tqu82</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_1mkhog2</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="SequenceFlow_05qembo" sourceRef="Task_0bhf6tp" targetRef="CallActivity_1gfzi2g" /> + <bpmn:serviceTask id="Task_0bhf6tp" name="PreProcess Abstract CDS Processing" camunda:expression="${GenericCDSProcessing.buildPayloadBasedOnScopeAndAction(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution")))}"> + <bpmn:incoming>SequenceFlow_0vzx2yr</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_05qembo</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:exclusiveGateway id="ExclusiveGateway_13q340y" default="SequenceFlow_15gxql1"> + <bpmn:incoming>SequenceFlow_0cvsnuu</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_07tqu82</bpmn:outgoing> + <bpmn:outgoing>SequenceFlow_15gxql1</bpmn:outgoing> + </bpmn:exclusiveGateway> + <bpmn:sequenceFlow id="SequenceFlow_0cvsnuu" sourceRef="CallActivity_1gfzi2g" targetRef="ExclusiveGateway_13q340y" /> + <bpmn:sequenceFlow id="SequenceFlow_07tqu82" name="success" sourceRef="ExclusiveGateway_13q340y" targetRef="Task_1hs1mn0"> + <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{execution.getVariable("CDSStatus").equals("Success")}</bpmn:conditionExpression> + </bpmn:sequenceFlow> + <bpmn:endEvent id="EndEvent_0mnaj50"> + <bpmn:incoming>SequenceFlow_15gxql1</bpmn:incoming> + <bpmn:errorEventDefinition id="ErrorEventDefinition_1s1hqgm" errorRef="Error_0aovtfv" /> + </bpmn:endEvent> + <bpmn:sequenceFlow id="SequenceFlow_15gxql1" sourceRef="ExclusiveGateway_13q340y" targetRef="EndEvent_0mnaj50" /> + <bpmn:serviceTask id="ServiceTask_0inxg9l" name="Set Actor, Scope and Action Params" camunda:expression="${ControllerExecution.setControllerActorScopeAction(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution")))}"> + <bpmn:incoming>SequenceFlow_0gmfit3</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_05j6hg6</bpmn:outgoing> + <bpmn:outgoing>SequenceFlow_1lspfyy</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="SequenceFlow_05j6hg6" sourceRef="ServiceTask_0inxg9l" targetRef="ExclusiveGateway_0plxwkg" /> + <bpmn:exclusiveGateway id="ExclusiveGateway_0plxwkg" default="SequenceFlow_1t7hs4k"> + <bpmn:incoming>SequenceFlow_1lspfyy</bpmn:incoming> + <bpmn:incoming>SequenceFlow_05j6hg6</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_1t7hs4k</bpmn:outgoing> + <bpmn:outgoing>SequenceFlow_0vzx2yr</bpmn:outgoing> + </bpmn:exclusiveGateway> + <bpmn:sequenceFlow id="SequenceFlow_1lspfyy" sourceRef="ServiceTask_0inxg9l" targetRef="ExclusiveGateway_0plxwkg" /> + <bpmn:callActivity id="BBToExecute" name="BB to Execute " calledElement="${bbName}"> + <bpmn:extensionElements> + <camunda:out source="WorkflowException" target="WorkflowException" /> + <camunda:out source="WorkflowExceptionErrorMessage" target="WorkflowExceptionErrorMessage" /> + <camunda:in source="executionObject" target="executionObject" /> + <camunda:in source="mso-request-id" target="mso-request-id" /> + <camunda:in source="isRollback" target="isRollback" /> + <camunda:out source="StatusMessage" target="StatusMessage" /> + </bpmn:extensionElements> + <bpmn:incoming>SequenceFlow_0fv03vt</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_0no1qag</bpmn:outgoing> + <bpmn:outgoing>SequenceFlow_0op5irz</bpmn:outgoing> + </bpmn:callActivity> + <bpmn:sequenceFlow id="SequenceFlow_1t7hs4k" sourceRef="ExclusiveGateway_0plxwkg" targetRef="Task_1rc2j9" /> + <bpmn:sequenceFlow id="SequenceFlow_0no1qag" sourceRef="BBToExecute" targetRef="EndEvent_0lgvk82" /> + <bpmn:sequenceFlow id="SequenceFlow_0fv03vt" sourceRef="Task_1rc2j9" targetRef="BBToExecute" /> + <bpmn:serviceTask id="Task_1rc2j9" name="select BB " camunda:expression="${ControllerExecution.selectBB(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution")))}"> + <bpmn:incoming>SequenceFlow_1t7hs4k</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_0fv03vt</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:endEvent id="EndEvent_1lxwuh2"> + <bpmn:incoming>SequenceFlow_0op5irz</bpmn:incoming> + <bpmn:errorEventDefinition id="ErrorEventDefinition_0z001cu" errorRef="Error_0aovtfv" /> + </bpmn:endEvent> + <bpmn:sequenceFlow id="SequenceFlow_0op5irz" sourceRef="BBToExecute" targetRef="EndEvent_1lxwuh2" /> + <bpmn:sequenceFlow id="SequenceFlow_0vzx2yr" name="Actor= CDS" sourceRef="ExclusiveGateway_0plxwkg" targetRef="Task_0bhf6tp"> + <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${execution.getVariable("controller_actor") == "CDS"}</bpmn:conditionExpression> + </bpmn:sequenceFlow> + </bpmn:process> + <bpmn:error id="Error_0aovtfv" name="MSOWorkflowException" errorCode="MSOWorkflowException" /> + <bpmndi:BPMNDiagram id="BPMNDiagram_1"> + <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="ControllerExecution"> + <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"> + <dc:Bounds x="160" y="323" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="-17" y="279" width="90" height="20" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_0gmfit3_di" bpmnElement="SequenceFlow_0gmfit3"> + <di:waypoint x="196" y="341" /> + <di:waypoint x="259" y="341" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="32.5" y="236" width="90" height="20" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="EndEvent_0lgvk82_di" bpmnElement="EndEvent_0lgvk82"> + <dc:Bounds x="1129" y="323" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="1025" y="251" width="90" height="20" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_1mkhog2_di" bpmnElement="SequenceFlow_1mkhog2"> + <di:waypoint x="1079" y="462" /> + <di:waypoint x="1147" y="462" /> + <di:waypoint x="1147" y="359" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="918" y="357" width="90" height="20" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="CallActivity_1gfzi2g_di" bpmnElement="CallActivity_1gfzi2g"> + <dc:Bounds x="725" y="422" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="ServiceTask_0404s6a_di" bpmnElement="Task_1hs1mn0"> + <dc:Bounds x="979" y="422" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_05qembo_di" bpmnElement="SequenceFlow_05qembo"> + <di:waypoint x="672" y="462" /> + <di:waypoint x="725" y="462" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="503.5" y="357" width="90" height="20" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="ServiceTask_01mv1si_di" bpmnElement="Task_0bhf6tp"> + <dc:Bounds x="572" y="422" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="ExclusiveGateway_13q340y_di" bpmnElement="ExclusiveGateway_13q340y" isMarkerVisible="true"> + <dc:Bounds x="868" y="437" width="50" height="50" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="698" y="327" width="90" height="20" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_0cvsnuu_di" bpmnElement="SequenceFlow_0cvsnuu"> + <di:waypoint x="825" y="462" /> + <di:waypoint x="868" y="462" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="651.5" y="357" width="90" height="20" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_07tqu82_di" bpmnElement="SequenceFlow_07tqu82"> + <di:waypoint x="918" y="462" /> + <di:waypoint x="979" y="462" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="856" y="409" width="41" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="EndEvent_0mnaj50_di" bpmnElement="EndEvent_0mnaj50"> + <dc:Bounds x="875" y="565" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="698" y="531" width="90" height="20" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_15gxql1_di" bpmnElement="SequenceFlow_15gxql1"> + <di:waypoint x="893" y="487" /> + <di:waypoint x="893" y="565" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="713" y="436" width="90" height="20" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="ServiceTask_0inxg9l_di" bpmnElement="ServiceTask_0inxg9l"> + <dc:Bounds x="259" y="301" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_05j6hg6_di" bpmnElement="SequenceFlow_05j6hg6"> + <di:waypoint x="359" y="341" /> + <di:waypoint x="399" y="341" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="184" y="240" width="90" height="12" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="ExclusiveGateway_0plxwkg_di" bpmnElement="ExclusiveGateway_0plxwkg" isMarkerVisible="true"> + <dc:Bounds x="399" y="316" width="50" height="50" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="309" y="255" width="0" height="12" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_1lspfyy_di" bpmnElement="SequenceFlow_1lspfyy"> + <di:waypoint x="359" y="341" /> + <di:waypoint x="399" y="341" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="229" y="240" width="0" height="12" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="CallActivity_01dem38_di" bpmnElement="BBToExecute"> + <dc:Bounds x="824" y="168" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_1t7hs4k_di" bpmnElement="SequenceFlow_1t7hs4k"> + <di:waypoint x="424" y="316" /> + <di:waypoint x="424" y="208" /> + <di:waypoint x="572" y="208" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="271" y="89" width="83" height="36" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_0no1qag_di" bpmnElement="SequenceFlow_0no1qag"> + <di:waypoint x="924" y="208" /> + <di:waypoint x="1147" y="208" /> + <di:waypoint x="1147" y="323" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="840.5" y="107" width="90" height="12" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_0fv03vt_di" bpmnElement="SequenceFlow_0fv03vt"> + <di:waypoint x="672" y="208" /> + <di:waypoint x="824" y="208" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="598" y="107" width="0" height="12" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="ServiceTask_0qd9p4w_di" bpmnElement="Task_1rc2j9"> + <dc:Bounds x="572" y="168" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="EndEvent_1lxwuh2_di" bpmnElement="EndEvent_1lxwuh2"> + <dc:Bounds x="856" y="84" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="679" y="50" width="0" height="12" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_0op5irz_di" bpmnElement="SequenceFlow_0op5irz"> + <di:waypoint x="874" y="168" /> + <di:waypoint x="874" y="120" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="739" y="58" width="0" height="12" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_0vzx2yr_di" bpmnElement="SequenceFlow_0vzx2yr"> + <di:waypoint x="424" y="366" /> + <di:waypoint x="424" y="462" /> + <di:waypoint x="572" y="462" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="455" y="436" width="60" height="12" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + </bpmndi:BPMNPlane> + </bpmndi:BPMNDiagram> +</bpmn:definitions>
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecution.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecution.java new file mode 100644 index 0000000000..86d56005f6 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecution.java @@ -0,0 +1,109 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Tech Mahindra + * ================================================================================ + * 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.infrastructure.flowspecific.tasks; + +import java.util.Optional; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.db.catalog.beans.BBNameSelectionReference; +import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class ControllerExecution { + private static final Logger logger = LoggerFactory.getLogger(ControllerExecution.class); + private static final String CONTROLLER_ACTOR = "controllerActor"; + private static final String BUILDING_BLOCK = "buildingBlock"; + private static final String SCOPE = "scope"; + private static final String ACTION = "action"; + private static final String BBNAME = "bbName"; + @Autowired + private ExceptionBuilder exceptionUtil; + @Autowired + private CatalogDbClient catalogDbClient; + @Autowired + private ExtractPojosForBB extractPojosForBB; + + /** + * Setting Controller Actor, Scope and Action Variables in BuildingBlockExecution object + * + * @param execution - BuildingBlockExecution object + */ + public void setControllerActorScopeAction(BuildingBlockExecution execution) { + try { + GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); + String modleUuid = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid(); + VnfResourceCustomization vnfResourceCustomization = + catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(modleUuid); + + // Fetching Controller Actor at VNF level if null then Controller Actor is set as "APPC" + String controllerActor = Optional.ofNullable(vnfResourceCustomization.getControllerActor()).orElse("APPC"); + ExecuteBuildingBlock executeBuildingBlock = execution.getVariable(BUILDING_BLOCK); + BuildingBlock buildingBlock = executeBuildingBlock.getBuildingBlock(); + String scope = Optional.ofNullable(buildingBlock.getBpmnScope()).orElseThrow( + () -> new NullPointerException("BPMN Scope is NULL in the orchestration_flow_reference table ")); + String action = Optional.ofNullable(buildingBlock.getBpmnAction()).orElseThrow( + () -> new NullPointerException("BPMN Action is NULL in the orchestration_flow_reference table ")); + execution.setVariable(SCOPE, scope); + execution.setVariable(ACTION, action); + execution.setVariable(CONTROLLER_ACTOR, controllerActor); + logger.debug("Executing Controller Execution for ControllerActor: {}, Scope: {} , Action: {}", + controllerActor, scope, action); + + } catch (Exception ex) { + logger.error("An exception occurred while fetching Controller Actor,Scope and Action ", ex); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + /** + * Selecting bbName from BBNameSelectionReference and setting the value in a variable of BuildingBlockExecution + * + * @param execution - BuildingBlockExecution object + */ + public void selectBB(BuildingBlockExecution execution) { + try { + + String controllerActor = execution.getVariable(CONTROLLER_ACTOR); + String action = Optional.of((String) execution.getVariable(ACTION)).get(); + String scope = Optional.of((String) execution.getVariable(SCOPE)).get(); + BBNameSelectionReference bbNameSelectionReference = + catalogDbClient.getBBNameSelectionReference(controllerActor, scope, action); + String bbName = bbNameSelectionReference.getBbName(); + execution.setVariable(BBNAME, bbName); + logger.debug(" Executing {} BPMN", bbName); + } catch (Exception ex) { + logger.error("An exception occurred while getting bbname from catalogdb ", ex); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + + } + + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecutionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecutionTest.java new file mode 100644 index 0000000000..72a987c395 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecutionTest.java @@ -0,0 +1,127 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Tech Mahindra + * ================================================================================ + * 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.infrastructure.flowspecific.tasks; + + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.when; +import java.util.UUID; +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentMatchers; +import org.mockito.InjectMocks; +import org.onap.so.bpmn.BaseTaskTest; +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.BuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.db.catalog.beans.BBNameSelectionReference; +import org.onap.so.db.catalog.beans.VnfResourceCustomization; + + +public class ControllerExecutionTest extends BaseTaskTest { + + @InjectMocks + private ControllerExecution controllerExecution = new ControllerExecution(); + + private static final String TEST_SCOPE = "vfModule"; + private static final String TEST_BBNAME = "ConfigurationScaleOut"; + private static final String TEST_ACTION = "configScaleOut"; + private static final String TEST_CONTROLLER_ACTOR = "APPC"; + + private BuildingBlock buildingBlock = new BuildingBlock(); + VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization(); + private ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock(); + private GenericVnf genericVnf; + private ServiceInstance serviceInstance; + private RequestContext requestContext; + private String msoRequestId; + + + @Before + public void before() throws BBObjectNotFoundException { + + genericVnf = setGenericVnf(); + serviceInstance = setServiceInstance(); + msoRequestId = UUID.randomUUID().toString(); + requestContext = setRequestContext(); + requestContext.setMsoRequestId(msoRequestId); + gBBInput.setRequestContext(requestContext); + buildingBlock.setBpmnAction(TEST_ACTION); + buildingBlock.setBpmnScope(TEST_SCOPE); + executeBuildingBlock.setBuildingBlock(buildingBlock); + execution.setVariable("buildingBlock", executeBuildingBlock); + + doThrow(new BpmnError("BPMN Error")).when(exceptionUtil) + .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class)); + + when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID))) + .thenReturn(genericVnf); + when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) + .thenReturn(serviceInstance); + + + } + + @Test + public void testSetControllerActorScopeAction() throws Exception { + + + doReturn(vnfResourceCustomization).when(catalogDbClient).getVnfResourceCustomizationByModelCustomizationUUID( + genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid()); + controllerExecution.setControllerActorScopeAction(execution); + assertEquals(TEST_SCOPE, execution.getVariable("scope")); + assertEquals(TEST_ACTION, execution.getVariable("action")); + assertEquals(TEST_CONTROLLER_ACTOR, execution.getVariable("controllerActor")); + + } + + + @Test + public void testSelectBB() throws Exception { + // given + BBNameSelectionReference bbNameSelectionReference = new BBNameSelectionReference(); + bbNameSelectionReference.setBbName(TEST_BBNAME); + bbNameSelectionReference.setAction(TEST_ACTION); + bbNameSelectionReference.setControllerActor(TEST_CONTROLLER_ACTOR); + bbNameSelectionReference.setScope(TEST_SCOPE); + doReturn(bbNameSelectionReference).when(catalogDbClient).getBBNameSelectionReference(TEST_CONTROLLER_ACTOR, + TEST_SCOPE, TEST_ACTION); + execution.setVariable("controllerActor", TEST_CONTROLLER_ACTOR); + execution.setVariable("scope", TEST_SCOPE); + execution.setVariable("action", TEST_ACTION); + + // when + controllerExecution.selectBB(execution); + // verify + assertEquals(TEST_BBNAME, execution.getVariable("bbName")); + } + +} |