Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / java / org / onap / so / bpmn / infrastructure / pnf / delegate / PnfCheckInputsTest.java
index 9794a59..6c8716c 100644 (file)
 package org.onap.so.bpmn.infrastructure.pnf.delegate;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
-import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION;
-
+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 static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SERVICE_INSTANCE_ID;
+import java.util.UUID;
+import org.apache.commons.lang3.StringUtils;
 import org.camunda.bpm.engine.delegate.BpmnError;
 import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
+import org.junit.Before;
 import org.junit.Test;
 
 public class PnfCheckInputsTest {
 
-    private static final String DEFAULT_TIMEOUT = "P1D";
+    private static final String PNF_ENTRY_NOTIFICATION_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_PNF_CORRELATION_ID = "testPnfCorrelationId";
+
+    private DelegateExecutionBuilder delegateExecutionBuilder;
 
-    private DelegateExecution mockDelegateExecution() {
-        DelegateExecution delegateExecution = mock(DelegateExecution.class);
-        when(delegateExecution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue");
-        return delegateExecution;
+    @Before
+    public void setUp() {
+        delegateExecutionBuilder = new DelegateExecutionBuilder();
     }
 
     @Test
-    public void shouldThrowException_whenPnfIdNotSet() {
-        // given
-        PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
-        DelegateExecution delegateExecution = mockDelegateExecution();
-        // when, then
-        assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
+    public void shouldThrowException_whenPnfCorrelationIdNotSet() {
+        PnfCheckInputs testedObject = new PnfCheckInputs(PNF_ENTRY_NOTIFICATION_TIMEOUT);
+        DelegateExecution execution = delegateExecutionBuilder.setPnfCorrelationId(null).setPnfUuid(VALID_UUID).build();
+        assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
     }
 
     @Test
-    public void shouldThrowException_whenPnfIdIsEmptyString() throws Exception {
-        // given
-        PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
-        DelegateExecution delegateExecution = mockDelegateExecution();
-        when(delegateExecution.getVariable(CORRELATION_ID)).thenReturn("");
-        // when, then
-        assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
+    public void shouldThrowException_whenPnfEntryNotificationTimeoutIsNull() {
+        PnfCheckInputs testedObject = new PnfCheckInputs(null);
+        DelegateExecution execution = delegateExecutionBuilder.build();
+        assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
     }
 
-    private DelegateExecution mockDelegateExecutionWithCorrelationId() {
-        DelegateExecution delegateExecution = mockDelegateExecution();
-        when(delegateExecution.getVariable(CORRELATION_ID)).thenReturn("testCorrelationId");
-        return delegateExecution;
+    @Test
+    public void shouldThrowException_whenPnfEntryNotificationTimeoutIsEmpty() {
+        PnfCheckInputs testedObject = new PnfCheckInputs(StringUtils.EMPTY);
+        DelegateExecution execution = delegateExecutionBuilder.build();
+        assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
     }
 
     @Test
-    public void shouldThrowException_whenTimeoutIsNotSetAndDefaultIsNotDefined() {
-        // given
-        PnfCheckInputs testedObject = new PnfCheckInputs(null);
-        DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId();
-        // when, then
-        assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
+    public void shouldThrowException_whenPnfUuidIsNotSet() {
+        PnfCheckInputs testedObject = new PnfCheckInputs(PNF_ENTRY_NOTIFICATION_TIMEOUT);
+        DelegateExecution execution = delegateExecutionBuilder.setPnfUuid(null).build();
+        assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
     }
 
     @Test
-    public void shouldThrowException_whenTimeoutIsEmptyStringAndDefaultIsNotDefined() throws Exception {
-        // given
-        PnfCheckInputs testedObject = new PnfCheckInputs(null);
-        DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId();
-        when(delegateExecution.getVariable(TIMEOUT_FOR_NOTIFICATION)).thenReturn("");
-        // when, then
-        assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
+    public void shouldThrowException_whenPnfUuidIsEmptyString() {
+        PnfCheckInputs testedObject = new PnfCheckInputs(PNF_ENTRY_NOTIFICATION_TIMEOUT);
+        DelegateExecution execution = delegateExecutionBuilder.setPnfUuid(StringUtils.EMPTY).build();
+        assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
     }
 
     @Test
-    public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() {
-        // given
-        PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
-        DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId();
-        // when
-        testedObject.execute(delegateExecution);
-        // then
-        verify(delegateExecution).setVariable(eq(TIMEOUT_FOR_NOTIFICATION), eq(DEFAULT_TIMEOUT));
+    public void shouldThrowException_whenPnfUuidIsReservedUuid() {
+        PnfCheckInputs testedObject = new PnfCheckInputs(PNF_ENTRY_NOTIFICATION_TIMEOUT);
+        DelegateExecution execution = delegateExecutionBuilder.setPnfUuid(RESERVED_UUID).build();
+        assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
+    }
+
+    @Test
+    public void shouldThrowException_whenServiceInstanceIdIsNotSet() {
+        PnfCheckInputs testedObject = new PnfCheckInputs(PNF_ENTRY_NOTIFICATION_TIMEOUT);
+        DelegateExecution execution = delegateExecutionBuilder.setServiceInstanceId(null).build();
+        assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
+    }
+
+    private 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;
+        }
     }
-}
\ No newline at end of file
+}