diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test/java')
3 files changed, 128 insertions, 1 deletions
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksIT.java index e7a8b35db8..8328e0e08b 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksIT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksIT.java @@ -19,11 +19,17 @@ */ package org.onap.so.bpmn.infrastructure.appc.tasks; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Optional; import java.util.UUID; @@ -39,6 +45,8 @@ import org.springframework.beans.factory.annotation.Autowired; public class AppcRunTasksIT extends BaseIntegrationTest { + private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/"; + @Autowired private AppcRunTasks appcRunTasks; @@ -56,8 +64,51 @@ public class AppcRunTasksIT extends BaseIntegrationTest { } @Test - public void preProcessActivityTest() throws Exception { + public void preProcessActivityWithVserversTest() throws Exception { + final String aaiVnfJson = + new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiGenericVnfWithVservers.json"))); + wireMockServer.stubFor( + get(urlEqualTo("/aai/v15/network/generic-vnfs/generic-vnf/testVnfId1?depth=all")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody(aaiVnfJson).withStatus(200))); + + final String aaiVserverJson = + new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiVserverFullQueryResponse.json"))); + wireMockServer.stubFor(get(urlEqualTo( + "/aai/v15/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/mtn23a/tenants/tenant/e6beab145f6b49098277ac163ac1b4f3/vservers/vserver/48bd7f11-408f-417c-b834-b41c1b98f7d7")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(aaiVserverJson) + .withStatus(200))); + wireMockServer.stubFor(get(urlEqualTo( + "/aai/v15/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/mtn23a/tenants/tenant/e6beab145f6b49098277ac163ac1b4f3/vservers/vserver/1b3f44e5-d96d-4aac-bd9a-310e8cfb0af5")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(aaiVserverJson) + .withStatus(200))); + wireMockServer.stubFor(get(urlEqualTo( + "/aai/v15/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/mtn23a/tenants/tenant/e6beab145f6b49098277ac163ac1b4f3/vservers/vserver/14551849-1e70-45cd-bc5d-a256d49548a2")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(aaiVserverJson) + .withStatus(200))); + + appcRunTasks.preProcessActivity(execution); + String vserverIdList = execution.getVariable("vserverIdList"); + String expectedVserverIdList = + "{\"vserverIds\":\"[\\\"1b3f44e5-d96d-4aac-bd9a-310e8cfb0af5\\\",\\\"14551849-1e70-45cd-bc5d-a256d49548a2\\\",\\\"48bd7f11-408f-417c-b834-b41c1b98f7d7\\\"]\"}"; + String vmIdList = execution.getVariable("vmIdList"); + String expectedVmIdList = + "{\"vmIds\":\"[\\\"http://VSERVER-link.com\\\",\\\"http://VSERVER-link.com\\\",\\\"http://VSERVER-link.com\\\"]\"}"; + + assertEquals(vserverIdList, expectedVserverIdList); + assertEquals(vmIdList, expectedVmIdList); + assertEquals(execution.getVariable("actionQuiesceTraffic"), Action.QuiesceTraffic); + assertEquals(execution.getVariable("rollbackQuiesceTraffic"), false); + } + + @Test + public void preProcessActivityNoVserversTest() throws Exception { + final String aaiVnfJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiGenericVnf.json"))); + wireMockServer.stubFor( + get(urlEqualTo("/aai/v15/network/generic-vnfs/generic-vnf/testVnfId1?depth=all")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody(aaiVnfJson).withStatus(200))); appcRunTasks.preProcessActivity(execution); + assertNull(execution.getVariable("vmIdList")); + assertNull(execution.getVariable("vServerIdList")); assertEquals(execution.getVariable("actionQuiesceTraffic"), Action.QuiesceTraffic); assertEquals(execution.getVariable("rollbackQuiesceTraffic"), false); } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksTest.java index cf673c5eb5..cc25689358 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksTest.java @@ -26,12 +26,17 @@ import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Optional; import org.junit.Test; import org.mockito.InjectMocks; +import org.onap.aai.domain.yang.Vserver; import org.onap.appc.client.lcm.model.Action; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; @@ -39,11 +44,16 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.exception.BBObjectNotFoundException; import org.onap.so.db.catalog.beans.ControllerSelectionReference; +import com.fasterxml.jackson.databind.ObjectMapper; public class AppcRunTasksTest extends BaseTaskTest { + private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/"; + @InjectMocks private AppcRunTasks appcRunTasks = new AppcRunTasks(); @@ -132,6 +142,32 @@ public class AppcRunTasksTest extends BaseTaskTest { assertEquals(true, execution.getVariable("rollbackVnfLock")); } + @Test + public void getVserversForAppcTest() throws Exception { + + GenericVnf genericVnf = getTestGenericVnf(); + + final String aaiVnfJson = + new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiGenericVnfWithVservers.json"))); + final String aaiVserverJson = + new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiVserverQueryResponse.json"))); + AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiVnfJson); + ObjectMapper mapper = new ObjectMapper(); + Vserver vserver = mapper.readValue(aaiVserverJson, Vserver.class); + doReturn(aaiResultWrapper).when(aaiVnfResources).queryVnfWrapperById(genericVnf); + doReturn(Optional.of(vserver)).when(aaiVnfResources).getVserver(any(AAIResourceUri.class)); + appcRunTasks.getVserversForAppc(execution, genericVnf); + String vserverIdList = execution.getVariable("vserverIdList"); + String expectedVserverIdList = + "{\"vserverIds\":\"[\\\"1b3f44e5-d96d-4aac-bd9a-310e8cfb0af5\\\",\\\"14551849-1e70-45cd-bc5d-a256d49548a2\\\",\\\"48bd7f11-408f-417c-b834-b41c1b98f7d7\\\"]\"}"; + String vmIdList = execution.getVariable("vmIdList"); + String expectedVmIdList = + "{\"vmIds\":\"[\\\"http://VSERVER-link.com\\\",\\\"http://VSERVER-link.com\\\",\\\"http://VSERVER-link.com\\\"]\"}"; + + assertEquals(vserverIdList, expectedVserverIdList); + assertEquals(vmIdList, expectedVmIdList); + } + private void mockReferenceResponse() { ControllerSelectionReference reference = new ControllerSelectionReference(); reference.setControllerName("TEST-CONTROLLER-NAME"); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java index 0d48a29ca9..3680eaac81 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java @@ -20,8 +20,10 @@ package org.onap.so.client.orchestration; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -31,6 +33,8 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.Optional; import org.junit.Before; import org.junit.Test; @@ -54,11 +58,14 @@ import org.onap.so.client.aai.entities.AAIResultWrapper; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.aai.mapper.AAIObjectMapper; +import org.onap.so.client.graphinventory.entities.uri.Depth; import org.onap.so.db.catalog.beans.OrchestrationStatus; @RunWith(MockitoJUnitRunner.Silent.class) public class AAIVnfResourcesTest extends TestDataSetup { + private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/"; + private GenericVnf genericVnf; private ServiceInstance serviceInstance; @@ -249,4 +256,37 @@ public class AAIVnfResourcesTest extends TestDataSetup { boolean nameInUse = aaiVnfResources.checkNameInUse("vnfName"); assertFalse(nameInUse); } + + @Test + public void queryVnfWrapperByIdTest() throws Exception { + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "vnfId").depth(Depth.ALL); + final String aaiResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiGenericVnf.json"))); + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId("vnfId"); + AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiResponse); + doReturn(aaiResultWrapper).when(MOCK_aaiResourcesClient).get(eq(uri)); + AAIResultWrapper actualResult = aaiVnfResources.queryVnfWrapperById(genericVnf); + assertEquals(actualResult, aaiResultWrapper); + + } + + @Test + public void getVserverTest() throws Exception { + final String content = + new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiVserverQueryResponse.json"))); + AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(content); + Optional<org.onap.aai.domain.yang.Vserver> oVserver = Optional.empty(); + AAIResourceUri vserverUri = AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, "ModelInvariantUUID", + "serviceModelVersionId", "abc", "abc"); + + doReturn(aaiResultWrapper).when(MOCK_aaiResourcesClient).get(isA(AAIResourceUri.class)); + oVserver = aaiVnfResources.getVserver(vserverUri); + + verify(MOCK_aaiResourcesClient, times(1)).get(any(AAIResourceUri.class)); + + if (oVserver.isPresent()) { + org.onap.aai.domain.yang.Vserver vserver = oVserver.get(); + assertThat(aaiResultWrapper.asBean(org.onap.aai.domain.yang.Vserver.class).get(), sameBeanAs(vserver)); + } + } } |