summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common')
-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
3 files changed, 138 insertions, 0 deletions
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;
+ }
+ }
+}