From 67b21f3bbf54828093fd27634d4d090111c04502 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Wed, 12 Sep 2018 16:15:54 -0400 Subject: Improve test coverage for requestdbclient RequestsDbClient Junits and some fixes for RequestsDbClient Change-Id: Icc2185030220d7bf973be5a23a51b6b5e313a360 Issue-ID: SO-1033 Signed-off-by: Benjamin, Max (mb388a) --- .../client/RequestDbClientPortChanger.java | 21 +++ .../requestsdb/client/RequestsDbClientTest.java | 169 +++++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestDbClientPortChanger.java create mode 100644 adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java (limited to 'adapters/mso-requests-db-adapter/src/test') diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestDbClientPortChanger.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestDbClientPortChanger.java new file mode 100644 index 0000000000..c0d9955aea --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestDbClientPortChanger.java @@ -0,0 +1,21 @@ +package org.onap.so.adapters.requestsdb.client; + + +import org.onap.so.db.request.client.RequestsDbClient; +import org.springframework.stereotype.Component; +import java.net.URI; +@Component +public class RequestDbClientPortChanger extends RequestsDbClient { + private int port; + + public void setPort(int port) { + this.port = port; + } + + @Override + public URI getUri(String uri) { + uri = uri.replace("8081", String.valueOf(port)); + return URI.create(uri); + } +} + diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java new file mode 100644 index 0000000000..e614588407 --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java @@ -0,0 +1,169 @@ +package org.onap.so.adapters.requestsdb.client; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.adapters.requestsdb.application.MSORequestDBApplication; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.beans.OperationStatus; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import java.util.List; +import java.util.UUID; +import java.util.Map; +import java.util.HashMap; +import java.util.ArrayList; + +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = MSORequestDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class RequestsDbClientTest { + + @Autowired + private RequestDbClientPortChanger requestsDbClient; + + private InfraActiveRequests infraActiveRequests; + + @LocalServerPort + private int port; + + @Before + public void setup() { + requestsDbClient.setPort(port); + + infraActiveRequests = new InfraActiveRequests(); + infraActiveRequests.setRequestId(UUID.randomUUID().toString()); + infraActiveRequests.setOperationalEnvId(UUID.randomUUID().toString()); + infraActiveRequests.setServiceInstanceId(UUID.randomUUID().toString()); + infraActiveRequests.setServiceInstanceName("serviceInstanceNameTest"); + infraActiveRequests.setVnfId(UUID.randomUUID().toString()); + infraActiveRequests.setVnfName("vnfInstanceNameTest"); + infraActiveRequests.setVfModuleId(UUID.randomUUID().toString()); + infraActiveRequests.setVfModuleName("vfModuleInstanceNameTest"); + infraActiveRequests.setVolumeGroupId(UUID.randomUUID().toString()); + infraActiveRequests.setVolumeGroupName("volumeGroupInstanceNameTest"); + infraActiveRequests.setNetworkId(UUID.randomUUID().toString()); + infraActiveRequests.setNetworkName("networkInstanceNameTest"); + infraActiveRequests.setConfigurationId(UUID.randomUUID().toString()); + infraActiveRequests.setConfigurationName("configurationInstanceNameTest"); + infraActiveRequests.setAicCloudRegion("1"); + infraActiveRequests.setTenantId(UUID.randomUUID().toString()); + infraActiveRequests.setRequestScope("operationalEnvironment"); + infraActiveRequests.setRequestorId(UUID.randomUUID().toString()); + infraActiveRequests.setSource("sourceTest"); + infraActiveRequests.setOperationalEnvName(UUID.randomUUID().toString()); + infraActiveRequests.setRequestStatus("IN_PROGRESS"); + infraActiveRequests.setAction("create"); + infraActiveRequests.setRequestAction("someaction"); + requestsDbClient.save(infraActiveRequests); + } + + private void verifyOperationStatus(OperationStatus request,OperationStatus response){ + assertThat(request, sameBeanAs(response).ignoring("operateAt").ignoring("finishedAt")); + } + + private void verifyInfraActiveRequests(InfraActiveRequests infraActiveRequestsResponse) { + assertThat(infraActiveRequestsResponse, sameBeanAs(infraActiveRequests).ignoring("modifyTime").ignoring("log")); + } + + @Test + public void getCloudOrchestrationFiltersFromInfraActiveTest() { + Map requestMap = new HashMap<>(); + requestMap.put("operationalEnvironmentId", infraActiveRequests.getOperationalEnvId()); + requestMap.put("operationalEnvironmentName", infraActiveRequests.getOperationalEnvName()); + requestMap.put("resourceType", "operationalEnvironment"); + + List iarr = requestsDbClient.getCloudOrchestrationFiltersFromInfraActive(requestMap); + + assertEquals(1, iarr.size()); + InfraActiveRequests infraActiveRequestsResponse = iarr.get(0); + verifyInfraActiveRequests(infraActiveRequestsResponse); + } + + + @Test + public void checkVnfIdStatusTest() { + InfraActiveRequests infraActiveRequestsResponse = requestsDbClient.checkVnfIdStatus(infraActiveRequests.getOperationalEnvId()); + verifyInfraActiveRequests(infraActiveRequestsResponse); + assertNull(requestsDbClient.checkVnfIdStatus(UUID.randomUUID().toString())); + } + + @Test + public void checkInstanceNameDuplicateTest() { + InfraActiveRequests infraActiveRequestsResponse = requestsDbClient.checkInstanceNameDuplicate(null,infraActiveRequests.getOperationalEnvName(),infraActiveRequests.getRequestScope()); + + verifyInfraActiveRequests(infraActiveRequestsResponse); + } + + @Test + public void checkInstanceNameDuplicateViaTest() { + Map requestMap = new HashMap<>(); + requestMap.put("operationalEnvironmentId", infraActiveRequests.getOperationalEnvId()); + + InfraActiveRequests infraActiveRequestsResponse = requestsDbClient.checkInstanceNameDuplicate((HashMap)requestMap,null,infraActiveRequests.getRequestScope()); + + verifyInfraActiveRequests(infraActiveRequestsResponse); + } + + @Test + public void getOrchestrationFiltersFromInfraActiveTest() { + Map> requestMap = new HashMap<>(); + List values = new ArrayList<>(); + values.add("EQUALS"); + values.add(infraActiveRequests.getServiceInstanceId()); + requestMap.put("serviceInstanceId", values); + + values = new ArrayList<>(); + values.add("EQUALS"); + values.add(infraActiveRequests.getServiceInstanceName()); + requestMap.put("serviceInstanceName", values); + + List iaar = requestsDbClient.getOrchestrationFiltersFromInfraActive(requestMap); + + assertEquals(1, iaar.size()); + InfraActiveRequests infraActiveRequestsResponse = iaar.get(0); + + verifyInfraActiveRequests(infraActiveRequestsResponse); + values = new ArrayList<>(); + values.add("EQUALS"); + values.add(UUID.randomUUID().toString()); + requestMap.put("serviceInstanceName", values); + requestsDbClient.getOrchestrationFiltersFromInfraActive(requestMap); + } + + @Test + public void getInfraActiveRequestbyRequestIdTest(){ + InfraActiveRequests infraActiveRequestsResponse = requestsDbClient.getInfraActiveRequestbyRequestId(infraActiveRequests.getRequestId()); + verifyInfraActiveRequests(infraActiveRequestsResponse); + assertNull(requestsDbClient.getInfraActiveRequestbyRequestId(UUID.randomUUID().toString())); + } + + @Test + public void getOneByServiceIdAndOperationIdTest(){ + OperationStatus operationStatus = new OperationStatus(); + operationStatus.setProgress("IN_PROGRESS"); + operationStatus.setResult("FAILED"); + operationStatus.setServiceId(UUID.randomUUID().toString()); + operationStatus.setOperationContent("operation-content"); + operationStatus.setOperation("operation"); + operationStatus.setOperationId(UUID.randomUUID().toString()); + operationStatus.setReason("reason-test"); + operationStatus.setUserId(UUID.randomUUID().toString()); + operationStatus.setServiceName("test-service"); + requestsDbClient.save(operationStatus); + + OperationStatus operationStatusResponse = requestsDbClient.getOneByServiceIdAndOperationId(operationStatus.getServiceId(),operationStatus.getOperationId()); + + verifyOperationStatus(operationStatus,operationStatusResponse); + + assertNull(requestsDbClient.getOneByServiceIdAndOperationId(UUID.randomUUID().toString(),operationStatus.getOperationId())); + } +} \ No newline at end of file -- cgit 1.2.3-korg