diff options
author | Plummer, Brittany <brittany.plummer@att.com> | 2019-10-24 14:42:15 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@att.com> | 2019-10-24 14:42:16 -0400 |
commit | fd9cba6af0486e479ae5e953e880ae99aa3f2432 (patch) | |
tree | ec678706f78886324827f844c7dcb28aa0b6e8fa /adapters/mso-requests-db-adapter/src/test/java | |
parent | 86f62530f1813152efbcc3d61f85e1fa6c943e36 (diff) |
add new query for requestdb
Updated RequestDbClient to call new request mapping to query for
IN_PROGRESS volumeGroup and vfModule requests older than two minutes.
Issue-ID: SO-2490
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: Idd4c077a13c15dd6c22ef168d164f2df2aed4cff
Diffstat (limited to 'adapters/mso-requests-db-adapter/src/test/java')
2 files changed, 71 insertions, 10 deletions
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 index 4ed3285a70..896138f955 100644 --- 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 @@ -21,8 +21,13 @@ package org.onap.so.adapters.requestsdb; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import java.sql.Timestamp; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -33,6 +38,7 @@ import org.junit.Before; import org.junit.Test; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.data.controller.InstanceNameDuplicateCheckRequest; +import org.onap.so.serviceinstancebeans.ModelType; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.server.LocalServerPort; @@ -91,14 +97,6 @@ public class InfraActiveRequestsRepositoryCustomControllerTest extends RequestsA @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); - headers.set("Authorization", msoAdaptersAuth); - infraActiveRequests = new InfraActiveRequests(); infraActiveRequests.setRequestId(UUID.randomUUID().toString()); @@ -126,12 +124,22 @@ public class InfraActiveRequestsRepositoryCustomControllerTest extends RequestsA infraActiveRequests .setRequestUrl("http://localhost:8080/onap/so/infra/serviceInstantiation/v7/serviceInstances"); - HttpEntity<String> entity = new HttpEntity(infraActiveRequests, headers); + saveInfraActiveRequest(infraActiveRequests); + } + + public void saveInfraActiveRequest(InfraActiveRequests request) { + headers = new HttpHeaders(); + restTemplate = new TestRestTemplate("test", "test"); + + headers.set("Accept", MediaType.APPLICATION_JSON); + headers.set("Content-Type", MediaType.APPLICATION_JSON); + headers.set("Authorization", msoAdaptersAuth); + + HttpEntity<String> entity = new HttpEntity(request, headers); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/infraActiveRequests")); ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class); - assertEquals(201, response.getStatusCodeValue()); } @@ -297,4 +305,38 @@ public class InfraActiveRequestsRepositoryCustomControllerTest extends RequestsA assertEquals(200, response.getStatusCodeValue()); assertEquals(null, response.getBody()); } + + @Test + public void getInProgressVolumeGroupsAndVfModulesTest() { + boolean expectedReturned = false; + InfraActiveRequests request = new InfraActiveRequests(); + request.setRequestId(UUID.randomUUID().toString()); + request.setVfModuleId(UUID.randomUUID().toString()); + request.setRequestStatus("IN_PROGRESS"); + request.setRequestScope(ModelType.vfModule.toString()); + Instant startInstant = Instant.now().minus(3, ChronoUnit.MINUTES); + request.setStartTime(Timestamp.from(startInstant)); + request.setRequestAction("create"); + saveInfraActiveRequest(request); + + UriComponentsBuilder builder = UriComponentsBuilder + .fromHttpUrl(createURLWithPort("/infraActiveRequests/getInProgressVolumeGroupsAndVfModules")); + + HttpEntity<String> entity = new HttpEntity<String>(headers); + + ResponseEntity<List<InfraActiveRequests>> response = restTemplate.exchange(builder.toUriString(), + HttpMethod.GET, entity, new ParameterizedTypeReference<List<InfraActiveRequests>>() {}); + + List<InfraActiveRequests> responseList = response.getBody(); + + assertEquals(200, response.getStatusCodeValue()); + + for (InfraActiveRequests result : responseList) { + if (result.getRequestId().equals(request.getRequestId())) { + assertThat(request, sameBeanAs(result).ignoring("modifyTime")); + expectedReturned = true; + } + } + assertTrue(expectedReturned); + } } 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 index 49291b6863..67887378ef 100644 --- 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 @@ -27,6 +27,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import java.sql.Timestamp; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -41,6 +43,7 @@ import org.onap.so.db.request.beans.OperationStatus; import org.onap.so.db.request.beans.OperationalEnvDistributionStatus; import org.onap.so.db.request.beans.OperationalEnvServiceModelStatus; import org.onap.so.db.request.beans.RequestProcessingData; +import org.onap.so.serviceinstancebeans.ModelType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.server.LocalServerPort; @@ -314,4 +317,20 @@ public class RequestsDbClientTest extends RequestsAdapterBase { verifyInfraActiveRequests(infraActiveRequestsResponse.get(0)); } + + @Test + public void getInProgressVolumeGroupsAndVfModulesTest() { + InfraActiveRequests request = new InfraActiveRequests(); + request.setRequestId(UUID.randomUUID().toString()); + request.setVfModuleId(UUID.randomUUID().toString()); + request.setRequestStatus("IN_PROGRESS"); + request.setRequestScope(ModelType.vfModule.toString()); + Instant startInstant = Instant.now().minus(3, ChronoUnit.MINUTES); + request.setStartTime(Timestamp.from(startInstant)); + request.setRequestAction("create"); + requestsDbClient.save(request); + + List<InfraActiveRequests> infraActiveRequests = requestsDbClient.getInProgressVolumeGroupsAndVfModules(); + assertThat(request, sameBeanAs(infraActiveRequests.get(0)).ignoring("modifyTime")); + } } |