summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>2019-12-20 09:42:36 +0000
committerGerrit Code Review <gerrit@onap.org>2019-12-20 09:42:36 +0000
commit8a3fb63de2bdf40bbf33119854d432693c2ff2e4 (patch)
tree70e529ae7db8a6a80b16a7e4115bb70ca6b4da18
parent44cb5d927a9730c28807557360bad0e61ef4b626 (diff)
parent6939ace38f276b40b7c07be18450604c5a469607 (diff)
Merge "Externalize AssignPnf Building Block and refactor existing code accordingly"
-rw-r--r--bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignPnfBB.bpmn137
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AssignPnfInputsCheckerDelegate.java40
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AssignPnfInputsCheckerDelegateTest.java52
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfInputCheckersTestUtils.java46
4 files changed, 275 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignPnfBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignPnfBB.bpmn
new file mode 100644
index 0000000000..f9c5d0cdb3
--- /dev/null
+++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignPnfBB.bpmn
@@ -0,0 +1,137 @@
+<?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:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_1a52v2f" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.5.0">
+ <bpmn:collaboration id="Collaboration_0go8wi3">
+ <bpmn:participant id="Participant_1dwc5st" name="SO&#10;Assign PNF" processRef="AssignPnfBB" />
+ <bpmn:participant id="Participant_0gycee4" name="AAI" />
+ <bpmn:messageFlow id="MessageFlow_0xh6bkn" sourceRef="CreatePnfEntryInAai" targetRef="Participant_0gycee4" />
+ <bpmn:messageFlow id="MessageFlow_0cnehf5" sourceRef="Participant_0gycee4" targetRef="CheckAaiForPnfCorrelationId" />
+ <bpmn:messageFlow id="MessageFlow_1e1pjve" sourceRef="CheckAaiForPnfCorrelationId" targetRef="Participant_0gycee4" />
+ </bpmn:collaboration>
+ <bpmn:process id="AssignPnfBB" name="AssignPnfBB" isExecutable="true">
+ <bpmn:startEvent id="AssignPnf_StartEvent">
+ <bpmn:outgoing>SequenceFlow_1fu9o4x</bpmn:outgoing>
+ </bpmn:startEvent>
+ <bpmn:serviceTask id="CheckAaiForPnfCorrelationId" name="Check AAI for pnf_correlation_id" camunda:delegateExpression="${CheckAaiForPnfCorrelationIdDelegate}">
+ <bpmn:incoming>SequenceFlow_02j05kk</bpmn:incoming>
+ <bpmn:outgoing>SequenceFlow_081rs5d</bpmn:outgoing>
+ </bpmn:serviceTask>
+ <bpmn:exclusiveGateway id="DoesAaiContainInfoAboutPnf" name="Does AAI contain info about pnf?">
+ <bpmn:incoming>SequenceFlow_081rs5d</bpmn:incoming>
+ <bpmn:outgoing>SequenceFlow_0fn5kgz</bpmn:outgoing>
+ <bpmn:outgoing>SequenceFlow_1ewfz8r</bpmn:outgoing>
+ </bpmn:exclusiveGateway>
+ <bpmn:serviceTask id="CreatePnfEntryInAai" name="Create Pnf entry in AAI" camunda:delegateExpression="${CreatePnfEntryInAaiDelegate}">
+ <bpmn:incoming>SequenceFlow_0fn5kgz</bpmn:incoming>
+ <bpmn:outgoing>SequenceFlow_0l6rtzy</bpmn:outgoing>
+ </bpmn:serviceTask>
+ <bpmn:endEvent id="AaiEntryExists" name="AAI entry exists">
+ <bpmn:incoming>SequenceFlow_1ewfz8r</bpmn:incoming>
+ <bpmn:incoming>SequenceFlow_0l6rtzy</bpmn:incoming>
+ </bpmn:endEvent>
+ <bpmn:sequenceFlow id="SequenceFlow_081rs5d" sourceRef="CheckAaiForPnfCorrelationId" targetRef="DoesAaiContainInfoAboutPnf" />
+ <bpmn:sequenceFlow id="SequenceFlow_0fn5kgz" name="No" sourceRef="DoesAaiContainInfoAboutPnf" targetRef="CreatePnfEntryInAai">
+ <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{!aaiContainsInfoAboutPnf}</bpmn:conditionExpression>
+ </bpmn:sequenceFlow>
+ <bpmn:sequenceFlow id="SequenceFlow_1ewfz8r" name="Yes&#10;&#10;" sourceRef="DoesAaiContainInfoAboutPnf" targetRef="AaiEntryExists">
+ <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{aaiContainsInfoAboutPnf}</bpmn:conditionExpression>
+ </bpmn:sequenceFlow>
+ <bpmn:sequenceFlow id="SequenceFlow_0l6rtzy" sourceRef="CreatePnfEntryInAai" targetRef="AaiEntryExists" />
+ <bpmn:serviceTask id="CheckInputs" name="Check Inputs" camunda:delegateExpression="${AssignPnfInputsCheckerDelegate}">
+ <bpmn:incoming>SequenceFlow_1fu9o4x</bpmn:incoming>
+ <bpmn:outgoing>SequenceFlow_02j05kk</bpmn:outgoing>
+ </bpmn:serviceTask>
+ <bpmn:sequenceFlow id="SequenceFlow_02j05kk" sourceRef="CheckInputs" targetRef="CheckAaiForPnfCorrelationId" />
+ <bpmn:sequenceFlow id="SequenceFlow_1fu9o4x" sourceRef="AssignPnf_StartEvent" targetRef="CheckInputs" />
+ <bpmn:textAnnotation id="TextAnnotation_184cxp4">
+ <bpmn:text>Inputs:
+ - pnfCorrelationId - String
+ - uuid - String</bpmn:text>
+ </bpmn:textAnnotation>
+ <bpmn:association id="Association_1le3nwi" sourceRef="AssignPnf_StartEvent" targetRef="TextAnnotation_184cxp4" />
+ </bpmn:process>
+ <bpmndi:BPMNDiagram id="BPMNDiagram_1">
+ <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_0go8wi3">
+ <bpmndi:BPMNShape id="Participant_1dwc5st_di" bpmnElement="Participant_1dwc5st" isHorizontal="true">
+ <dc:Bounds x="160" y="80" width="1100" height="390" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="Participant_0gycee4_di" bpmnElement="Participant_0gycee4" isHorizontal="true">
+ <dc:Bounds x="590" y="570" width="502" height="60" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="ServiceTask_1ix8822_di" bpmnElement="CreatePnfEntryInAai">
+ <dc:Bounds x="920" y="247" width="100" height="80" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="ExclusiveGateway_1l92fkt_di" bpmnElement="DoesAaiContainInfoAboutPnf" isMarkerVisible="true">
+ <dc:Bounds x="795" y="262" width="50" height="50" />
+ <bpmndi:BPMNLabel>
+ <dc:Bounds x="777" y="322" width="85" height="27" />
+ </bpmndi:BPMNLabel>
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="ServiceTask_0ebur3y_di" bpmnElement="CheckAaiForPnfCorrelationId">
+ <dc:Bounds x="640" y="247" width="100" height="80" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="StartEvent_1g3euow_di" bpmnElement="AssignPnf_StartEvent">
+ <dc:Bounds x="219" y="269" width="36" height="36" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="TextAnnotation_184cxp4_di" bpmnElement="TextAnnotation_184cxp4">
+ <dc:Bounds x="236" y="150" width="243" height="53" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNEdge id="SequenceFlow_081rs5d_di" bpmnElement="SequenceFlow_081rs5d">
+ <di:waypoint x="740" y="287" />
+ <di:waypoint x="795" y="287" />
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNEdge id="SequenceFlow_0fn5kgz_di" bpmnElement="SequenceFlow_0fn5kgz">
+ <di:waypoint x="845" y="287" />
+ <di:waypoint x="920" y="287" />
+ <bpmndi:BPMNLabel>
+ <dc:Bounds x="854" y="290" width="15" height="14" />
+ </bpmndi:BPMNLabel>
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNEdge id="MessageFlow_0xh6bkn_di" bpmnElement="MessageFlow_0xh6bkn">
+ <di:waypoint x="970" y="327" />
+ <di:waypoint x="970" y="570" />
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNEdge id="MessageFlow_0cnehf5_di" bpmnElement="MessageFlow_0cnehf5">
+ <di:waypoint x="710" y="570" />
+ <di:waypoint x="710" y="327" />
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNEdge id="MessageFlow_1e1pjve_di" bpmnElement="MessageFlow_1e1pjve">
+ <di:waypoint x="671" y="327" />
+ <di:waypoint x="671" y="570" />
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNEdge id="Association_1le3nwi_di" bpmnElement="Association_1le3nwi">
+ <di:waypoint x="237" y="269" />
+ <di:waypoint x="237" y="203" />
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNShape id="EndEvent_1wfgsdz_di" bpmnElement="AaiEntryExists">
+ <dc:Bounds x="1152" y="269" width="36" height="36" />
+ <bpmndi:BPMNLabel>
+ <dc:Bounds x="1133" y="312" width="77" height="14" />
+ </bpmndi:BPMNLabel>
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNEdge id="SequenceFlow_1ewfz8r_di" bpmnElement="SequenceFlow_1ewfz8r">
+ <di:waypoint x="820" y="262" />
+ <di:waypoint x="820" y="170" />
+ <di:waypoint x="1170" y="170" />
+ <di:waypoint x="1170" y="269" />
+ <bpmndi:BPMNLabel>
+ <dc:Bounds x="822" y="240" width="19" height="40" />
+ </bpmndi:BPMNLabel>
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNEdge id="SequenceFlow_0l6rtzy_di" bpmnElement="SequenceFlow_0l6rtzy">
+ <di:waypoint x="1020" y="287" />
+ <di:waypoint x="1152" y="287" />
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNShape id="ServiceTask_0tv92eb_di" bpmnElement="CheckInputs">
+ <dc:Bounds x="400" y="247" width="100" height="80" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNEdge id="SequenceFlow_02j05kk_di" bpmnElement="SequenceFlow_02j05kk">
+ <di:waypoint x="500" y="287" />
+ <di:waypoint x="640" y="287" />
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNEdge id="SequenceFlow_1fu9o4x_di" bpmnElement="SequenceFlow_1fu9o4x">
+ <di:waypoint x="255" y="287" />
+ <di:waypoint x="400" y="287" />
+ </bpmndi:BPMNEdge>
+ </bpmndi:BPMNPlane>
+ </bpmndi:BPMNDiagram>
+</bpmn:definitions>
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AssignPnfInputsCheckerDelegate.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AssignPnfInputsCheckerDelegate.java
new file mode 100644
index 0000000000..9176948288
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AssignPnfInputsCheckerDelegate.java
@@ -0,0 +1,40 @@
+package org.onap.so.bpmn.infrastructure.pnf.delegate;
+
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
+import com.google.common.base.Strings;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.engine.delegate.JavaDelegate;
+import org.onap.so.bpmn.common.scripts.ExceptionUtil;
+import org.springframework.stereotype.Component;
+
+@Component
+public class AssignPnfInputsCheckerDelegate implements JavaDelegate {
+
+ public static final String UUID_REGEX =
+ "(?i)^[0-9a-f]{8}-[0-9a-f]{4}-[1-5]{1}[0-9a-f]{3}-[89ab]{1}[0-9a-f]{3}-[0-9a-f]{12}$";
+
+ @Override
+ public void execute(DelegateExecution execution) {
+ validatePnfCorrelationId(execution);
+ validatePnfUuid(execution);
+ }
+
+ private void validatePnfCorrelationId(DelegateExecution execution) {
+ String pnfCorrelationId = (String) execution.getVariable(PNF_CORRELATION_ID);
+ if (Strings.isNullOrEmpty(pnfCorrelationId)) {
+ new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999,
+ "pnfCorrelationId variable not defined");
+ }
+ }
+
+ private void validatePnfUuid(DelegateExecution execution) {
+ String pnfUuid = (String) execution.getVariable(PNF_UUID);
+ if (Strings.isNullOrEmpty(pnfUuid)) {
+ new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "pnfUuid variable not defined");
+ }
+ if (!pnfUuid.matches(UUID_REGEX)) {
+ new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "pnfUuid is not a valid UUID");
+ }
+ }
+}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AssignPnfInputsCheckerDelegateTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AssignPnfInputsCheckerDelegateTest.java
new file mode 100644
index 0000000000..a562da490b
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AssignPnfInputsCheckerDelegateTest.java
@@ -0,0 +1,52 @@
+package org.onap.so.bpmn.infrastructure.pnf.delegate;
+
+import org.apache.commons.lang3.StringUtils;
+import org.camunda.bpm.engine.delegate.BpmnError;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.junit.Before;
+import org.junit.Test;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.PnfInputCheckersTestUtils.DelegateExecutionBuilder;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.PnfInputCheckersTestUtils.RESERVED_UUID;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.PnfInputCheckersTestUtils.VALID_UUID;
+
+public class AssignPnfInputsCheckerDelegateTest {
+
+ private DelegateExecutionBuilder delegateExecutionBuilder;
+ private AssignPnfInputsCheckerDelegate testedObject;
+ private DelegateExecution execution;
+
+ @Before
+ public void setUp() {
+ testedObject = new AssignPnfInputsCheckerDelegate();
+ delegateExecutionBuilder = new DelegateExecutionBuilder();
+ }
+
+ @Test
+ public void shouldThrowException_whenPnfCorrelationIdNotSet() {
+ execution = delegateExecutionBuilder.setPnfCorrelationId(null).setPnfUuid(VALID_UUID).build();
+ assertThatSutExecutionThrowsExceptionOfInstance(BpmnError.class);
+ }
+
+ @Test
+ public void shouldThrowException_whenPnfUuidIsNotSet() {
+ execution = delegateExecutionBuilder.setPnfUuid(null).build();
+ assertThatSutExecutionThrowsExceptionOfInstance(BpmnError.class);
+ }
+
+ @Test
+ public void shouldThrowException_whenPnfUuidIsEmptyString() {
+ execution = delegateExecutionBuilder.setPnfUuid(StringUtils.EMPTY).build();
+ assertThatSutExecutionThrowsExceptionOfInstance(BpmnError.class);
+ }
+
+ @Test
+ public void shouldThrowException_whenPnfUuidIsReservedUuid() {
+ execution = delegateExecutionBuilder.setPnfUuid(RESERVED_UUID).build();
+ assertThatSutExecutionThrowsExceptionOfInstance(BpmnError.class);
+ }
+
+ private void assertThatSutExecutionThrowsExceptionOfInstance(Class<?> type) {
+ assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(type);
+ }
+}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfInputCheckersTestUtils.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfInputCheckersTestUtils.java
new file mode 100644
index 0000000000..c1c7f06d4e
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfInputCheckersTestUtils.java
@@ -0,0 +1,46 @@
+package org.onap.so.bpmn.infrastructure.pnf.delegate;
+
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.*;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
+import java.util.UUID;
+
+
+public class PnfInputCheckersTestUtils {
+
+ static final String PNF_ENTRY_NOTIFICATION_TIMEOUT = "P1D";
+ static final String VALID_UUID = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString();
+ static final String RESERVED_UUID = new UUID(0, 0).toString();
+ private static final String DEFAULT_SERVICE_INSTANCE_ID = "da7d07d9-b71c-4128-809d-2ec01c807169";
+ private static final String DEFAULT_PNF_CORRELATION_ID = "testPnfCorrelationId";
+
+ static class DelegateExecutionBuilder {
+ private String pnfCorrelationId = DEFAULT_PNF_CORRELATION_ID;
+ private String pnfUuid = VALID_UUID;
+ private String serviceInstanceId = DEFAULT_SERVICE_INSTANCE_ID;
+
+ public DelegateExecutionBuilder setPnfCorrelationId(String pnfCorrelationId) {
+ this.pnfCorrelationId = pnfCorrelationId;
+ return this;
+ }
+
+ public DelegateExecutionBuilder setPnfUuid(String pnfUuid) {
+ this.pnfUuid = pnfUuid;
+ return this;
+ }
+
+ public DelegateExecutionBuilder setServiceInstanceId(String serviceInstanceId) {
+ this.serviceInstanceId = serviceInstanceId;
+ return this;
+ }
+
+ public DelegateExecution build() {
+ DelegateExecution execution = new DelegateExecutionFake();
+ execution.setVariable("testProcessKey", "testProcessKeyValue");
+ execution.setVariable(PNF_CORRELATION_ID, this.pnfCorrelationId);
+ execution.setVariable(PNF_UUID, this.pnfUuid);
+ execution.setVariable(SERVICE_INSTANCE_ID, this.serviceInstanceId);
+ return execution;
+ }
+ }
+}