summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src/test
diff options
context:
space:
mode:
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>2020-08-04 08:12:42 +0000
committerGerrit Code Review <gerrit@onap.org>2020-08-04 08:12:42 +0000
commit039a298c38ecf33d164be72eca725ec3861bb884 (patch)
tree7f5f924a442cd04a823a0f6e9630b3b008154738 /bpmn/so-bpmn-tasks/src/test
parent4e81b212f66800fffbb06a1f6c55b5733a98c122 (diff)
parentd7ef9a5b2f6f1a7e807a100f7e69fc373dc5e71a (diff)
Merge "Ensure that model related parameters are set when re-using Inventoried PNF instance"
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test')
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java69
1 files changed, 64 insertions, 5 deletions
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java
index 59cd53edd5..b8be045f97 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java
@@ -48,13 +48,18 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
import org.onap.aaiclient.client.aai.AAIResourcesClient;
import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
+import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoPnf;
import org.onap.so.client.aai.mapper.AAIObjectMapper;
import org.onap.so.db.catalog.beans.OrchestrationStatus;
@RunWith(MockitoJUnitRunner.Silent.class)
public class AAIPnfResourcesTest extends TestDataSetup {
+ public static final String TEST_VERSION = "testVersion";
private static final String PNF_NAME = "pnfTest";
+ public static final String TEST_CUSTOMIZATION_UUID = "testCustomizationUuid";
+ public static final String TEST_INVARIANT_UUID = "testInvariantUuid";
+ public static final String TEST_ROLE = "testRole";
private Pnf pnf;
private ServiceInstance serviceInstance;
@@ -110,42 +115,87 @@ public class AAIPnfResourcesTest extends TestDataSetup {
@Test
public void existingPnfInAaiWithInventoriedStatusCanBeUsed() throws Exception {
// given
+ Pnf pnfTest = createPnfWithDefaultName();
org.onap.aai.domain.yang.Pnf pnfFromAai = createPnf(OrchestrationStatus.INVENTORIED.toString());
when(injectionHelperMock.getAaiClient().get(org.onap.aai.domain.yang.Pnf.class,
AAIUriFactory.createResourceUri(AAIObjectType.PNF, PNF_NAME))).thenReturn(Optional.of(pnfFromAai));
// when
- testedObject.checkIfPnfExistsInAaiAndCanBeUsed(PNF_NAME);
+ testedObject.checkIfPnfExistsInAaiAndCanBeUsed(pnfTest);
+ verify(aaiResourcesClientMock, times(1)).update(any(), any());
}
@Test
public void existingPnfInAaiWithNullStatusCanBeUsed() throws Exception {
// given
+ Pnf pnfTest = createPnfWithDefaultName();
org.onap.aai.domain.yang.Pnf pnfFromAai = createPnf(null);
+ pnfTest.setRole("test");
when(injectionHelperMock.getAaiClient().get(org.onap.aai.domain.yang.Pnf.class,
AAIUriFactory.createResourceUri(AAIObjectType.PNF, PNF_NAME))).thenReturn(Optional.of(pnfFromAai));
// when
- testedObject.checkIfPnfExistsInAaiAndCanBeUsed(PNF_NAME);
+ testedObject.checkIfPnfExistsInAaiAndCanBeUsed(pnfTest);
+ verify(aaiResourcesClientMock, times(1)).update(any(), eq(pnfFromAai));
+ }
+
+ @Test
+ public void existingPnfInAaiIsUpdated() throws Exception {
+ // given
+ org.onap.aai.domain.yang.Pnf pnfFromAai = createPnf(null);
+ Pnf pnfTest = getPnfWithTestValues();
+ when(injectionHelperMock.getAaiClient().get(org.onap.aai.domain.yang.Pnf.class,
+ AAIUriFactory.createResourceUri(AAIObjectType.PNF, PNF_NAME))).thenReturn(Optional.of(pnfFromAai));
+ // when
+ testedObject.checkIfPnfExistsInAaiAndCanBeUsed(pnfTest);
+ verify(aaiResourcesClientMock, times(1)).update(any(), eq(pnfFromAai));
+ verifyPnfFromAai(pnfFromAai);
+ }
+
+ private void verifyPnfFromAai(org.onap.aai.domain.yang.Pnf pnf) {
+ assertEquals(OrchestrationStatus.INVENTORIED.toString(), pnf.getOrchestrationStatus());
+ assertEquals(TEST_ROLE, pnf.getNfRole());
+ assertEquals(TEST_CUSTOMIZATION_UUID, pnf.getModelCustomizationId());
+ assertEquals(TEST_INVARIANT_UUID, pnf.getModelInvariantId());
+ assertEquals(TEST_VERSION, pnf.getModelVersionId());
+ }
+
+ private Pnf getPnfWithTestValues() {
+ Pnf pnfTest = createPnfWithDefaultName();
+ ModelInfoPnf modelInfoPnf = getModelInfoPnf();
+ pnfTest.setModelInfoPnf(modelInfoPnf);
+ pnfTest.setOrchestrationStatus(OrchestrationStatus.INVENTORIED);
+ pnfTest.setRole(TEST_ROLE);
+ return pnfTest;
+ }
+
+ private ModelInfoPnf getModelInfoPnf() {
+ ModelInfoPnf modelInfoPnf = new ModelInfoPnf();
+ modelInfoPnf.setModelCustomizationUuid(TEST_CUSTOMIZATION_UUID);
+ modelInfoPnf.setModelInvariantUuid(TEST_INVARIANT_UUID);
+ modelInfoPnf.setModelUuid(TEST_VERSION);
+ return modelInfoPnf;
}
@Test
public void existingPnfInAaiWithEmptyStatusCanBeUsed() throws Exception {
// given
+ Pnf pnfTest = createPnfWithDefaultName();
org.onap.aai.domain.yang.Pnf pnfFromAai = createPnf(Strings.EMPTY);
when(injectionHelperMock.getAaiClient().get(org.onap.aai.domain.yang.Pnf.class,
AAIUriFactory.createResourceUri(AAIObjectType.PNF, PNF_NAME))).thenReturn(Optional.of(pnfFromAai));
// when
- testedObject.checkIfPnfExistsInAaiAndCanBeUsed(PNF_NAME);
+ testedObject.checkIfPnfExistsInAaiAndCanBeUsed(pnfTest);
}
@Test
public void existingPnfInAaiCanNotBeUsed() {
// given
+ Pnf pnfTest = createPnfWithDefaultName();
org.onap.aai.domain.yang.Pnf pnfFromAai = createPnf(OrchestrationStatus.ACTIVE.toString());
when(injectionHelperMock.getAaiClient().get(org.onap.aai.domain.yang.Pnf.class,
AAIUriFactory.createResourceUri(AAIObjectType.PNF, PNF_NAME))).thenReturn(Optional.of(pnfFromAai));
// when
try {
- testedObject.checkIfPnfExistsInAaiAndCanBeUsed(PNF_NAME);
+ testedObject.checkIfPnfExistsInAaiAndCanBeUsed(pnfTest);
} catch (Exception e) {
// then
assertThat(e.getMessage()).isEqualTo(String.format(
@@ -153,6 +203,7 @@ public class AAIPnfResourcesTest extends TestDataSetup {
+ "if status is not set or set as Inventoried",
PNF_NAME));
}
+ verify(aaiResourcesClientMock, times(0)).update(any(), any());
}
@Test
@@ -161,19 +212,21 @@ public class AAIPnfResourcesTest extends TestDataSetup {
final String relatedTo = "service-instance";
final String serviceInstanceId = "service-instance-id";
final String path = "src/test/resources/__files/BuildingBlocks/aaiPnf.json";
+ Pnf pnfTest = createPnfWithDefaultName();
org.onap.aai.domain.yang.Pnf pnfFromAai =
new ObjectMapper().readValue(new File(path), org.onap.aai.domain.yang.Pnf.class);
when(injectionHelperMock.getAaiClient().get(org.onap.aai.domain.yang.Pnf.class,
AAIUriFactory.createResourceUri(AAIObjectType.PNF, PNF_NAME))).thenReturn(Optional.of(pnfFromAai));
// when
try {
- testedObject.checkIfPnfExistsInAaiAndCanBeUsed(PNF_NAME);
+ testedObject.checkIfPnfExistsInAaiAndCanBeUsed(pnfTest);
} catch (Exception e) {
// then
assertThat(e.getMessage()).isEqualTo(String.format(
"Pnf with name %s exist with orchestration status %s and is related to %s service with certain service-instance-id: %s",
PNF_NAME, OrchestrationStatus.ACTIVE, relatedTo, serviceInstanceId));
}
+ verify(aaiResourcesClientMock, times(0)).update(any(), any());
}
private org.onap.aai.domain.yang.Pnf createPnf(String orchestrationStatus) {
@@ -182,4 +235,10 @@ public class AAIPnfResourcesTest extends TestDataSetup {
pnfFromAai.setOrchestrationStatus(orchestrationStatus);
return pnfFromAai;
}
+
+ private Pnf createPnfWithDefaultName() {
+ Pnf pnfTest = new Pnf();
+ pnfTest.setPnfName(PNF_NAME);
+ return pnfTest;
+ }
}