From 258bc5da642cd2cd606a9c25b861e40560703974 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Tue, 21 Aug 2018 14:43:36 -0400 Subject: added unit test for class Adding unit tests for the infraactiverepositorycustomcontroller and fixing an issue found while adding the test Change-Id: Ic177f75c995ee789902dc9ad1b7df0e997b998c9 Issue-ID: SO-876 Signed-off-by: Benjamin, Max (mb388a) --- ...tiveRequestsRepositoryCustomControllerTest.java | 244 +++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/InfraActiveRequestsRepositoryCustomControllerTest.java (limited to 'adapters/mso-requests-db-adapter/src/test/java/org/onap') diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/InfraActiveRequestsRepositoryCustomControllerTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/InfraActiveRequestsRepositoryCustomControllerTest.java new file mode 100644 index 0000000000..58eb0085ad --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/InfraActiveRequestsRepositoryCustomControllerTest.java @@ -0,0 +1,244 @@ +package org.onap.so.adapters.requestsdb; + + +import org.junit.Before; +import org.junit.After; +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.data.controller.InstanceNameDuplicateCheckRequest; +import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.util.UriComponentsBuilder; + +import javax.ws.rs.core.MediaType; +import java.util.List; +import java.util.Map; +import java.util.HashMap; +import java.util.UUID; +import java.util.ArrayList; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = MSORequestDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +@Transactional +public class InfraActiveRequestsRepositoryCustomControllerTest { + + @LocalServerPort + private int port; + + private String createURLWithPort(String uri) { + return "http://localhost:" + port + uri; + } + + private InfraActiveRequests infraActiveRequests; + private InfraActiveRequests infraActiveRequestsResponse; + private HttpHeaders headers; + private TestRestTemplate restTemplate; + + private void verifyInfraActiveRequests() { + assertEquals(infraActiveRequests.getRequestId(), infraActiveRequestsResponse.getRequestId()); + assertEquals(infraActiveRequests.getServiceInstanceId(), infraActiveRequestsResponse.getServiceInstanceId()); + assertEquals(infraActiveRequests.getServiceInstanceName(), infraActiveRequestsResponse.getServiceInstanceName()); + assertEquals(infraActiveRequests.getVnfId(), infraActiveRequestsResponse.getVnfId()); + assertEquals(infraActiveRequests.getVnfName(), infraActiveRequestsResponse.getVnfName()); + assertEquals(infraActiveRequests.getVfModuleId(), infraActiveRequestsResponse.getVfModuleId()); + assertEquals(infraActiveRequests.getVfModuleName(), infraActiveRequestsResponse.getVfModuleName()); + assertEquals(infraActiveRequests.getVolumeGroupId(), infraActiveRequestsResponse.getVolumeGroupId()); + assertEquals(infraActiveRequests.getVolumeGroupName(), infraActiveRequestsResponse.getVolumeGroupName()); + assertEquals(infraActiveRequests.getNetworkId(), infraActiveRequestsResponse.getNetworkId()); + assertEquals(infraActiveRequests.getNetworkName(), infraActiveRequestsResponse.getNetworkName()); + assertEquals(infraActiveRequests.getConfigurationId(), infraActiveRequestsResponse.getConfigurationId()); + assertEquals(infraActiveRequests.getConfigurationName(), infraActiveRequestsResponse.getConfigurationName()); + assertEquals(infraActiveRequests.getAaiServiceId(), infraActiveRequestsResponse.getAaiServiceId()); + assertEquals(infraActiveRequests.getTenantId(), infraActiveRequestsResponse.getTenantId()); + assertEquals(infraActiveRequests.getRequestScope(), infraActiveRequestsResponse.getRequestScope()); + assertEquals(infraActiveRequests.getRequestorId(), infraActiveRequestsResponse.getRequestorId()); + assertEquals(infraActiveRequests.getSource(), infraActiveRequestsResponse.getSource()); + assertEquals(infraActiveRequests.getOperationalEnvId(), infraActiveRequestsResponse.getOperationalEnvId()); + assertEquals(infraActiveRequests.getOperationalEnvName(), infraActiveRequestsResponse.getOperationalEnvName()); + assertEquals(infraActiveRequests.getRequestStatus(), infraActiveRequestsResponse.getRequestStatus()); + assertEquals(infraActiveRequests.getAction(), infraActiveRequestsResponse.getAction()); + } + + @Before + public void setup() { + + headers = new HttpHeaders(); + restTemplate = new TestRestTemplate("test", "test"); + + headers.set("Accept", MediaType.APPLICATION_JSON); + headers.set("Content-Type", MediaType.APPLICATION_JSON); + + 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"); + + HttpEntity entity = new HttpEntity(infraActiveRequests, headers); + + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/infraActiveRequests")); + ResponseEntity response = restTemplate.exchange( + builder.toUriString(), + HttpMethod.POST, entity, String.class); + + assertEquals(201, response.getStatusCodeValue()); + } + + + @Test + public void getCloudOrchestrationFiltersFromInfraActiveTest() { + + Map requestMap = new HashMap<>(); + requestMap.put("operationalEnvironmentId", infraActiveRequests.getOperationalEnvId()); + requestMap.put("operationalEnvironmentName", infraActiveRequests.getOperationalEnvName()); + requestMap.put("resourceType", "operationalEnvironment"); + + HttpEntity> entity = new HttpEntity<>(requestMap, headers); + + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/infraActiveRequests") + "/getCloudOrchestrationFiltersFromInfraActive"); + + ResponseEntity> response = restTemplate.exchange( + builder.toUriString(), + HttpMethod.POST, entity, new ParameterizedTypeReference>() { + }); + + List iarr = response.getBody(); + assertEquals(200, response.getStatusCodeValue()); + + assertTrue(iarr.size() == 1); + infraActiveRequestsResponse = iarr.get(0); + + verifyInfraActiveRequests(); + + } + + @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); + + HttpEntity>> entityList = new HttpEntity(requestMap, headers); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/infraActiveRequests") + "/getOrchestrationFiltersFromInfraActive"); + + ResponseEntity> response = restTemplate.exchange( + builder.toUriString(), + HttpMethod.POST, entityList, new ParameterizedTypeReference>() { + }); + + List iarr = response.getBody(); + + assertEquals(200, response.getStatusCodeValue()); + + assertTrue(iarr.size() == 1); + infraActiveRequestsResponse = iarr.get(0); + + verifyInfraActiveRequests(); + } + + @Test + public void checkVnfIdStatusTest() { + + HttpEntity> entityList = new HttpEntity("", headers); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/infraActiveRequests" + "/checkVnfIdStatus/" + infraActiveRequests.getOperationalEnvId())); + + ResponseEntity response = restTemplate.exchange( + builder.toUriString(), + HttpMethod.GET, HttpEntity.EMPTY, InfraActiveRequests.class); + + infraActiveRequestsResponse = response.getBody(); + + assertEquals(200, response.getStatusCodeValue()); + + verifyInfraActiveRequests(); + } + + @Test + public void checkInstanceNameDuplicateTest() { + + InstanceNameDuplicateCheckRequest instanceNameDuplicateCheckRequest = new InstanceNameDuplicateCheckRequest((HashMap) null, + infraActiveRequests.getOperationalEnvName(), + infraActiveRequests.getRequestScope()); + + HttpEntity entityList = new HttpEntity(instanceNameDuplicateCheckRequest, headers); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/infraActiveRequests") + "/checkInstanceNameDuplicate"); + + ResponseEntity response = restTemplate.exchange( + builder.toUriString(), + HttpMethod.POST, entityList, new ParameterizedTypeReference() { + }); + + infraActiveRequestsResponse = response.getBody(); + + assertEquals(200, response.getStatusCodeValue()); + + verifyInfraActiveRequests(); + } + + @Test + public void checkInstanceNameDuplicateViaTest() { + + Map requestMap = new HashMap<>(); + requestMap.put("operationalEnvironmentId", infraActiveRequests.getOperationalEnvId()); + + InstanceNameDuplicateCheckRequest instanceNameDuplicateCheckRequest = new InstanceNameDuplicateCheckRequest((HashMap) requestMap, + null, + infraActiveRequests.getRequestScope()); + + HttpEntity entityList = new HttpEntity(instanceNameDuplicateCheckRequest, headers); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/infraActiveRequests") + "/checkInstanceNameDuplicate"); + + ResponseEntity response = restTemplate.exchange( + builder.toUriString(), + HttpMethod.POST, entityList, new ParameterizedTypeReference() { + }); + + infraActiveRequestsResponse = response.getBody(); + + assertEquals(200, response.getStatusCodeValue()); + + verifyInfraActiveRequests(); + } +} \ No newline at end of file -- cgit 1.2.3-korg