Validate inputs for pnf association 33/75733/6
authorJoanna Jeremicz <joanna.jeremicz@nokia.com>
Thu, 10 Jan 2019 08:22:46 +0000 (09:22 +0100)
committerJoanna Jeremicz <joanna.jeremicz@nokia.com>
Mon, 18 Feb 2019 13:23:17 +0000 (14:23 +0100)
Issue-ID: SO-1274
Change-Id: I3fdb66ef4bd259bef46c6f092d7d142b6cb5d9dc
Signed-off-by: Joanna Jeremicz <joanna.jeremicz@nokia.com>
bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java
bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputs.java
bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java
bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateVcpeResCustService_simplified.bpmn

index 1407cb9..c5caea5 100644 (file)
@@ -33,4 +33,5 @@ public class ExecutionVariableNames {
     public final static String DMAAP_MESSAGE = "dmaapMessage";
     public final static String TIMEOUT_FOR_NOTIFICATION = "timeoutForPnfEntryNotification";
     public final static String PNF_UUID = "pnfUuid";
+    public final static String SERVICE_INSTANCE_ID = "serviceInstanceId";
 }
index c1ddf2e..a975339 100644 (file)
@@ -24,6 +24,7 @@ package org.onap.so.bpmn.infrastructure.pnf.delegate;
 
 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SERVICE_INSTANCE_ID;
 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION;
 
 import com.google.common.base.Strings;
@@ -53,6 +54,7 @@ public class PnfCheckInputs implements JavaDelegate {
         validateCorrelationId(execution);
         validatePnfUuid(execution);
         validateTimeout(execution);
+        validateServiceInstanceId(execution);
     }
 
     private void validateCorrelationId(DelegateExecution execution) {
@@ -83,4 +85,11 @@ public class PnfCheckInputs implements JavaDelegate {
             execution.setVariable(TIMEOUT_FOR_NOTIFICATION, defaultTimeout);
         }
     }
+
+    private void validateServiceInstanceId(DelegateExecution execution) {
+        String serviceInstanceId = (String) execution.getVariable(SERVICE_INSTANCE_ID);
+        if (Strings.isNullOrEmpty(serviceInstanceId)) {
+            new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "serviceInstanceId variable not defined");
+        }
+    }
 }
index 1888831..1637b1a 100644 (file)
@@ -24,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SERVICE_INSTANCE_ID;
 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION;
 
 import java.util.UUID;
@@ -38,71 +39,100 @@ public class PnfCheckInputsTest {
     private static final String DEFAULT_TIMEOUT = "P1D";
     private static final String VALID_UUID = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString();
     private 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_CORRELATION_ID = "testCorrelationId";
 
-    private DelegateExecution delegateExecution;
+    private DelegateExecutionBuilder delegateExecutionBuilder;
 
     @Before
     public void setUp() {
-        delegateExecution = new DelegateExecutionFake();
-        delegateExecution.setVariable("testProcessKey", "testProcessKeyValue");
+        delegateExecutionBuilder = new DelegateExecutionBuilder();
     }
 
     @Test
     public void shouldThrowException_whenCorrelationIdNotSet() {
-        PnfCheckInputs testedObject = prepareExecutionForCorrelationId(null);
-        assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
+        PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
+        DelegateExecution execution = delegateExecutionBuilder.setCorrelationId(null).setPnfUuid(VALID_UUID).build();
+        assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
     }
 
     @Test
     public void shouldThrowException_whenTimeoutIsEmptyStringAndDefaultIsNotDefined() {
-        PnfCheckInputs testedObject = prepareExecutionForTimeout(null, "");
-        assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
+        PnfCheckInputs testedObject = new PnfCheckInputs(null);
+        DelegateExecution execution = delegateExecutionBuilder.setTimeoutForNotification("").build();
+        assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
     }
 
     @Test
     public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() {
-        PnfCheckInputs testedObject = prepareExecutionForTimeout(DEFAULT_TIMEOUT, null);
-        testedObject.execute(delegateExecution);
-        assertThat(delegateExecution.getVariable(TIMEOUT_FOR_NOTIFICATION)).isEqualTo(DEFAULT_TIMEOUT);
+        PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
+        DelegateExecution execution = delegateExecutionBuilder.setTimeoutForNotification(null).build();
+        testedObject.execute(execution);
+        assertThat(execution.getVariable(TIMEOUT_FOR_NOTIFICATION)).isEqualTo(DEFAULT_TIMEOUT);
     }
 
     @Test
     public void shouldThrowException_whenPnfUuidIsNotSet() {
-        PnfCheckInputs testedObject = prepareExecutionForUuid(null);
-        assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
+        PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
+        DelegateExecution execution = delegateExecutionBuilder.setPnfUuid(null).build();
+        assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
     }
 
     @Test
     public void shouldThrowException_whenPnfUuidIsEmptyString() {
-        PnfCheckInputs testedObject = prepareExecutionForUuid("");
-        assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
+        PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
+        DelegateExecution execution = delegateExecutionBuilder.setPnfUuid("").build();
+        assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
     }
 
     @Test
     public void shouldThrowException_whenPnfUuidIsReservedUuid() {
-        PnfCheckInputs testedObject = prepareExecutionForUuid(RESERVED_UUID);
-        assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
-    }
-
-    private PnfCheckInputs prepareExecutionForCorrelationId(String correlationId) {
         PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
-        delegateExecution.setVariable(CORRELATION_ID, correlationId);
-        delegateExecution.setVariable(PNF_UUID, VALID_UUID);
-        return testedObject;
+        DelegateExecution execution = delegateExecutionBuilder.setPnfUuid(RESERVED_UUID).build();
+        assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
     }
 
-    private PnfCheckInputs prepareExecutionForTimeout(String defaultTimeout, String timeout) {
-        PnfCheckInputs testedObject = new PnfCheckInputs(defaultTimeout);
-        delegateExecution.setVariable(CORRELATION_ID, "testCorrelationId");
-        delegateExecution.setVariable(PNF_UUID, VALID_UUID);
-        delegateExecution.setVariable(TIMEOUT_FOR_NOTIFICATION, timeout);
-        return testedObject;
+    @Test
+    public void shouldThrowException_whenServiceInstanceIdIsNotSet() {
+        PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
+        DelegateExecution execution = delegateExecutionBuilder.setServiceInstanceId(null).build();
+        assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
     }
 
-    private PnfCheckInputs prepareExecutionForUuid(String uuid) {
-        PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
-        delegateExecution.setVariable(CORRELATION_ID, "testCorrelationId");
-        delegateExecution.setVariable(PNF_UUID, uuid);
-        return testedObject;
+    private static class DelegateExecutionBuilder {
+        private String correlationId = DEFAULT_CORRELATION_ID;
+        private String pnfUuid = VALID_UUID;
+        private String serviceInstanceId = DEFAULT_SERVICE_INSTANCE_ID;
+        private String timeoutForNotification;
+
+        public DelegateExecutionBuilder setCorrelationId(String correlationId) {
+            this.correlationId = correlationId;
+            return this;
+        }
+
+        public DelegateExecutionBuilder setPnfUuid(String pnfUuid) {
+            this.pnfUuid = pnfUuid;
+            return this;
+        }
+
+        public DelegateExecutionBuilder setServiceInstanceId(String serviceInstanceId) {
+            this.serviceInstanceId = serviceInstanceId;
+            return this;
+        }
+
+        public DelegateExecutionBuilder setTimeoutForNotification(String timeoutForNotification) {
+            this.timeoutForNotification = timeoutForNotification;
+            return this;
+        }
+
+        public DelegateExecution build() {
+            DelegateExecution execution = new DelegateExecutionFake();
+            execution.setVariable("testProcessKey", "testProcessKeyValue");
+            execution.setVariable(CORRELATION_ID, this.correlationId);
+            execution.setVariable(PNF_UUID, this.pnfUuid);
+            execution.setVariable(SERVICE_INSTANCE_ID, this.serviceInstanceId);
+            execution.setVariable(TIMEOUT_FOR_NOTIFICATION, this.timeoutForNotification);
+            return execution;
+        }
     }
 }
index 3940dec..c8a5cf0 100644 (file)
@@ -362,6 +362,7 @@ CreateVcpeResCustService.processDecomposition(execution)</bpmn2:script>
         <camunda:in source="correlationId" target="correlationId" />
         <camunda:in businessKey="#{execution.processBusinessKey}" />
         <camunda:in source="pnfUuid" target="pnfUuid" />
+        <camunda:in source="serviceInstanceId" target="serviceInstanceId" />
       </bpmn2:extensionElements>
       <bpmn2:incoming>SequenceFlow_1yojilk</bpmn2:incoming>
       <bpmn2:outgoing>SequenceFlow_0clhseq</bpmn2:outgoing>