diff options
author | Lukasz Muszkieta <lukasz.muszkieta@nokia.com> | 2020-05-14 17:33:22 +0200 |
---|---|---|
committer | Lukasz Muszkieta <lukasz.muszkieta@nokia.com> | 2020-05-19 12:59:46 +0200 |
commit | 7d36092d69706b3f94e4f5b53aa3554487099dd0 (patch) | |
tree | 184daf66b1c948b20bd116059c2af4f573604828 /bpmn/so-bpmn-tasks/src/test/java/org/onap | |
parent | 959d27a96f24cf74dfa3764df64b65a1ba9b9cbb (diff) |
possibility to use inventoried PNF instance in new service instance
Issue-ID: SO-2937
Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
Change-Id: I5b34234d453bbd5ff1fef3c41f5cd50b23f66db1
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test/java/org/onap')
-rw-r--r-- | bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java | 66 |
1 files changed, 63 insertions, 3 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 215af9a19a..15c4b48d66 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 @@ -20,6 +20,7 @@ package org.onap.so.client.orchestration; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.argThat; @@ -27,13 +28,17 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.util.Optional; +import joptsimple.internal.Strings; 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.aaiclient.client.aai.AAIObjectType; +import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; import org.onap.so.bpmn.common.InjectionHelper; import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; @@ -46,6 +51,8 @@ import org.onap.so.db.catalog.beans.OrchestrationStatus; @RunWith(MockitoJUnitRunner.Silent.class) public class AAIPnfResourcesTest extends TestDataSetup { + private static final String PNF_NAME = "pnfTest"; + private Pnf pnf; private ServiceInstance serviceInstance; @@ -59,7 +66,7 @@ public class AAIPnfResourcesTest extends TestDataSetup { protected AAIResourcesClient aaiResourcesClientMock; @InjectMocks - AAIPnfResources aaiPnfResources = new AAIPnfResources(); + AAIPnfResources testedObject = new AAIPnfResources(); @Before public void setUp() { @@ -78,7 +85,7 @@ public class AAIPnfResourcesTest extends TestDataSetup { doReturn(aaiResourcesClientMock).when(aaiResourcesClientMock).createIfNotExists(any(AAIResourceUri.class), eq(Optional.of(pnfYang))); - aaiPnfResources.createPnfAndConnectServiceInstance(pnf, serviceInstance); + testedObject.createPnfAndConnectServiceInstance(pnf, serviceInstance); assertEquals(OrchestrationStatus.INVENTORIED, pnf.getOrchestrationStatus()); verify(aaiResourcesClientMock, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); @@ -89,7 +96,7 @@ public class AAIPnfResourcesTest extends TestDataSetup { org.onap.aai.domain.yang.Pnf pnfYang = new org.onap.aai.domain.yang.Pnf(); doReturn(pnfYang).when(aaiObjectMapperMock).mapPnf(pnf); - aaiPnfResources.updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE); + testedObject.updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE); assertEquals(OrchestrationStatus.ACTIVE, pnf.getOrchestrationStatus()); verify(aaiObjectMapperMock, times(1)) @@ -97,4 +104,57 @@ public class AAIPnfResourcesTest extends TestDataSetup { verify(aaiResourcesClientMock, times(1)).update(any(AAIResourceUri.class), eq(pnfYang)); } + @Test + public void existingPnfInAaiWithInventoriedStatusCanBeUsed() throws Exception { + // given + 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); + } + + @Test + public void existingPnfInAaiWithNullStatusCanBeUsed() throws Exception { + // given + org.onap.aai.domain.yang.Pnf pnfFromAai = createPnf(null); + 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); + } + + @Test + public void existingPnfInAaiWithEmptyStatusCanBeUsed() throws Exception { + // given + 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); + } + + @Test + public void existingPnfInAaiCanNotBeUsed() { + // given + 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); + } catch (Exception e) { + // then + assertThat(e.getMessage()).isEqualTo(String.format( + "pnf with name %s already exists with orchestration status Active, only status Inventoried allows to use existing pnf", + PNF_NAME)); + } + } + + private org.onap.aai.domain.yang.Pnf createPnf(String orchestrationStatus) { + org.onap.aai.domain.yang.Pnf pnfFromAai = new org.onap.aai.domain.yang.Pnf(); + pnfFromAai.setPnfName(PNF_NAME); + pnfFromAai.setOrchestrationStatus(orchestrationStatus); + return pnfFromAai; + } } |