aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common/src/test/java/org
diff options
context:
space:
mode:
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>2020-01-10 15:49:34 +0000
committerGerrit Code Review <gerrit@onap.org>2020-01-10 15:49:34 +0000
commitbb219dc0894bb60eaeb242f51b9a382228031081 (patch)
treebd2165853f7adecc727532ab88fbc2f3ed3cab6f /bpmn/so-bpmn-infrastructure-common/src/test/java/org
parent9d77758d706d13c1c2ea46ada1837d757adbf9ba (diff)
parent5ec955ce08cd3101eed327bbb6d1ceb3903f5bfc (diff)
Merge "Align AssignPnfBB with Service Macro Create -move and align logic of BB delegates with tests -remove unnecessary classes -add tests cases for Pnfs in ExtractPojosForBBTests"
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src/test/java/org')
-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
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationIdTest.java129
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAaiTest.java50
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfTasksUtils.java17
5 files changed, 196 insertions, 98 deletions
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
deleted file mode 100644
index a562da490b..0000000000
--- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AssignPnfInputsCheckerDelegateTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-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
deleted file mode 100644
index c1c7f06d4e..0000000000
--- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfInputCheckersTestUtils.java
+++ /dev/null
@@ -1,46 +0,0 @@
-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;
- }
- }
-}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationIdTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationIdTest.java
new file mode 100644
index 0000000000..3fa9fbf3b5
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationIdTest.java
@@ -0,0 +1,129 @@
+package org.onap.so.bpmn.infrastructure.pnf.tasks;
+
+import org.camunda.bpm.engine.delegate.BpmnError;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.runners.Enclosed;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl;
+import org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementThrowingException;
+import org.onap.so.bpmn.infrastructure.pnf.management.PnfManagement;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.exception.ExceptionBuilder;
+import java.io.IOException;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.anyInt;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.doThrow;
+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.AAI_CONTAINS_INFO_ABOUT_PNF;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl.ID_WITHOUT_ENTRY;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl.ID_WITH_ENTRY;
+import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.PNF_UUID;
+import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.preparePnf;
+
+@RunWith(Enclosed.class)
+public class CheckAaiForPnfCorrelationIdTest {
+
+ @RunWith(MockitoJUnitRunner.class)
+ public static class ConnectionOkTests {
+
+ @Mock
+ private ExtractPojosForBB extractPojosForBB;
+ @Mock
+ private ExceptionBuilder exceptionUtil;
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @InjectMocks
+ private CheckAaiForPnfCorrelationId task = new CheckAaiForPnfCorrelationId();
+ private PnfManagement pnfManagementTest = new PnfManagementTestImpl();
+
+ @Before
+ public void setUp() {
+ task.setPnfManagement(pnfManagementTest);
+ }
+
+ @Test
+ public void shouldThrowExceptionWhenPnfCorrelationIdIsNotSet() throws Exception {
+ // given
+ when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF))).thenReturn(preparePnf(null, PNF_UUID));
+ BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
+ doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(eq(execution),
+ anyInt(), anyString());
+ // when, then
+ expectedException.expect(BpmnError.class);
+ task.execute(execution);
+ verify(exceptionUtil).buildAndThrowWorkflowException(eq(execution), anyInt(), anyString());
+ }
+
+ @Test
+ public void shouldSetCorrectVariablesWhenAaiDoesNotContainInfoAboutPnf() throws Exception {
+ // given
+ when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF)))
+ .thenReturn(preparePnf(ID_WITHOUT_ENTRY, PNF_UUID));
+ BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
+ // when
+ task.execute(execution);
+ // then
+ verify(execution).setVariable(AAI_CONTAINS_INFO_ABOUT_PNF, false);
+ }
+
+ @Test
+ public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithoutIp() throws Exception {
+ // given
+ when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF)))
+ .thenReturn(preparePnf(ID_WITH_ENTRY, PNF_UUID));
+ BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
+ // when
+ task.execute(execution);
+ // then
+ verify(execution).setVariable(AAI_CONTAINS_INFO_ABOUT_PNF, true);
+ }
+ }
+
+ @RunWith(MockitoJUnitRunner.class)
+ public static class NoConnectionTests {
+
+ @Mock
+ private ExtractPojosForBB extractPojosForBB;
+ @Mock
+ private ExceptionBuilder exceptionUtil;
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @InjectMocks
+ private CheckAaiForPnfCorrelationId task = new CheckAaiForPnfCorrelationId();
+ private PnfManagement pnfManagementTest = new PnfManagementThrowingException();
+
+ @Before
+ public void setUp() throws Exception {
+ task.setPnfManagement(pnfManagementTest);
+ when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF)))
+ .thenReturn(preparePnf(PNF_CORRELATION_ID, PNF_UUID));
+ }
+
+ @Test
+ public void shouldThrowExceptionWhenIoExceptionOnConnectionToAai() {
+ // given
+ BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
+ doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(eq(execution),
+ anyInt(), any(IOException.class));
+ // when, then
+ expectedException.expect(BpmnError.class);
+ task.execute(execution);
+ verify(exceptionUtil).buildAndThrowWorkflowException(eq(execution), anyInt(), any(IOException.class));
+ }
+ }
+}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAaiTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAaiTest.java
new file mode 100644
index 0000000000..ed8dd82efb
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAaiTest.java
@@ -0,0 +1,50 @@
+package org.onap.so.bpmn.infrastructure.pnf.tasks;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.aai.domain.yang.Pnf;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.PNF_CORRELATION_ID;
+import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.PNF_UUID;
+import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.preparePnf;
+
+@RunWith(MockitoJUnitRunner.class)
+public class CreatePnfEntryInAaiTest {
+
+ @Mock
+ private ExtractPojosForBB extractPojosForBB;
+ @InjectMocks
+ private CreatePnfEntryInAai task = new CreatePnfEntryInAai();
+ private PnfManagementTestImpl pnfManagementTest = new PnfManagementTestImpl();
+
+ @Before
+ public void setUp() throws Exception {
+ task.setPnfManagement(pnfManagementTest);
+ when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF)))
+ .thenReturn(preparePnf(PNF_CORRELATION_ID, PNF_UUID));
+ }
+
+ @Test
+ public void shouldSetPnfIdAndPnfName() throws Exception {
+ // when
+ task.execute(mock(BuildingBlockExecution.class));
+ // then
+ Pnf createdEntry = pnfManagementTest.getCreated().get(PNF_CORRELATION_ID);
+ assertThat(createdEntry.getPnfId()).isEqualTo(PNF_UUID);
+ assertThat(createdEntry.getPnfName()).isEqualTo(PNF_CORRELATION_ID);
+ assertThat(createdEntry.isInMaint()).isNull();
+ }
+
+}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfTasksUtils.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfTasksUtils.java
new file mode 100644
index 0000000000..49fe96c3d9
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfTasksUtils.java
@@ -0,0 +1,17 @@
+package org.onap.so.bpmn.infrastructure.pnf.tasks;
+
+import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
+import java.util.UUID;
+
+public class PnfTasksUtils {
+ static final String PNF_UUID = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString();
+ static final String PNF_CORRELATION_ID = "testPnfCorrelationId";
+
+ public static Pnf preparePnf(String pnfName, String pnfUuid) {
+ Pnf pnf = new Pnf();
+ pnf.setPnfName(pnfName);
+ pnf.setPnfId(pnfUuid);
+ return pnf;
+ }
+
+}