diff options
Diffstat (limited to 'adapters/mso-requests-db-adapter/src/test/java')
7 files changed, 67 insertions, 29 deletions
diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestdb/rest/RequestProcessingDataRequestDbQueryTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestdb/rest/RequestProcessingDataRequestDbQueryTest.java index c1e620ba74..34643a428d 100644 --- a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestdb/rest/RequestProcessingDataRequestDbQueryTest.java +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestdb/rest/RequestProcessingDataRequestDbQueryTest.java @@ -34,7 +34,7 @@ import org.onap.so.adapters.requestsdb.application.MSORequestDBApplication; import org.onap.so.db.request.beans.RequestProcessingData; import org.onap.so.db.request.client.RequestsDbClient; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsSchedulerTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsSchedulerTest.java index f05a301caa..1c7effd00a 100644 --- a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsSchedulerTest.java +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsSchedulerTest.java @@ -63,7 +63,7 @@ public class ArchiveInfraRequestsSchedulerTest { @Test @Transactional - public void testArchiveInfraRequests() { + public void testArchiveInfraRequests() throws Exception { String requestId1 = "requestId1"; String requestId2 = "requestId2"; @@ -78,32 +78,15 @@ public class ArchiveInfraRequestsSchedulerTest { List<InfraActiveRequests> requests = new ArrayList<>(); requests.add(iar1); requests.add(iar2); - iarRepo.save(requests); + iarRepo.saveAll(requests); scheduler.archiveInfraRequests(requests); assertEquals(2, archivedRepo.count()); - assertEquals(requestId1, archivedRepo.findOne(requestId1).getRequestId()); - assertEquals(requestId2, archivedRepo.findOne(requestId2).getRequestId()); + assertEquals(requestId1, archivedRepo.findById(requestId1) + .orElseThrow( () -> new Exception("Request Not Found")).getRequestId()); + assertEquals(requestId2, archivedRepo.findById(requestId2). + orElseThrow( () -> new Exception("Request Not Found")).getRequestId()); } - @Test - @Ignore - public void testInfraRequestsScheduledTask() { - Date currentDate= new Date(); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(currentDate); - calendar.add(Calendar.DATE, -archivedPeriod); - Date archivingDate = calendar.getTime(); - - List<InfraActiveRequests> requests = iarRepo.findByEndTimeLessThan(archivingDate, new PageRequest(0, 100)); - List<InfraActiveRequests> requests2 = iarRepo.findByStartTimeLessThanAndEndTime(archivingDate, null, new PageRequest(0, 100)); - - int total = requests.size() + requests2.size(); - - scheduler.infraRequestsScheduledTask(); - - assertTrue(archivedRepo.count() >= total); - assertTrue(iarRepo.count() < total); - } } 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 58fd517c91..8fda355abb 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 @@ -29,7 +29,7 @@ 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.beans.factory.annotation.Value; -import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.core.ParameterizedTypeReference; @@ -96,6 +96,7 @@ public class InfraActiveRequestsRepositoryCustomControllerTest { assertEquals(infraActiveRequests.getOperationalEnvName(), infraActiveRequestsResponse.getOperationalEnvName()); assertEquals(infraActiveRequests.getRequestStatus(), infraActiveRequestsResponse.getRequestStatus()); assertEquals(infraActiveRequests.getAction(), infraActiveRequestsResponse.getAction()); + assertEquals(infraActiveRequests.getRequestUrl(), infraActiveRequestsResponse.getRequestUrl()); } @Before @@ -132,6 +133,7 @@ public class InfraActiveRequestsRepositoryCustomControllerTest { infraActiveRequests.setOperationalEnvName(UUID.randomUUID().toString()); infraActiveRequests.setRequestStatus("IN_PROGRESS"); infraActiveRequests.setAction("create"); + infraActiveRequests.setRequestUrl("http://localhost:8080/onap/so/infra/serviceInstantiation/v7/serviceInstances"); HttpEntity<String> entity = new HttpEntity(infraActiveRequests, headers); @@ -267,4 +269,45 @@ public class InfraActiveRequestsRepositoryCustomControllerTest { verifyInfraActiveRequests(); } + + @Test + public void checkInstanceNameDuplicateTestNotFound() { + + String instanceNameDuplicateCheckRequest = "{\r\n\t \"instanceName\":\"TestNotFoundInstanceName\",\r\n\t \"requestScope\":\"testasdfasdfasdf\"\r\n}"; + + HttpEntity<InstanceNameDuplicateCheckRequest> entityList = new HttpEntity(instanceNameDuplicateCheckRequest, headers); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/infraActiveRequests") + "/checkInstanceNameDuplicate"); + + ResponseEntity<InfraActiveRequests> response = restTemplate.exchange( + builder.toUriString(), + HttpMethod.POST, entityList, new ParameterizedTypeReference<InfraActiveRequests>() { + }); + + assertEquals(200, response.getStatusCodeValue()); + assertEquals(null, response.getBody()); + } + + @Test + public void checkInstanceNameDuplicateViaTestNotFound() { + + Map<String, String> requestMap = new HashMap<>(); + requestMap.put("operationalEnvironmentId", "NotFoundOperationalEnvId"); + + InstanceNameDuplicateCheckRequest instanceNameDuplicateCheckRequest = new InstanceNameDuplicateCheckRequest((HashMap<String, String>) requestMap, + null, + infraActiveRequests.getRequestScope()); + + HttpEntity<InstanceNameDuplicateCheckRequest> entityList = new HttpEntity(instanceNameDuplicateCheckRequest, headers); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/infraActiveRequests") + "/checkInstanceNameDuplicate"); + + ResponseEntity<InfraActiveRequests> response = restTemplate.exchange( + builder.toUriString(), + HttpMethod.POST, entityList, new ParameterizedTypeReference<InfraActiveRequests>() { + }); + + infraActiveRequestsResponse = response.getBody(); + + assertEquals(200, response.getStatusCodeValue()); + assertEquals(null, response.getBody()); + } } diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java index fc12120166..32eb40aed8 100644 --- a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java @@ -31,7 +31,7 @@ import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.adapters.requestsdb.application.MSORequestDBApplication; import org.onap.so.adapters.requestsdb.application.TestAppender; import org.onap.so.logger.MsoLogger; -import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpEntity; diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java index 6504fdaaa5..103e216229 100644 --- a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java @@ -50,7 +50,7 @@ import org.onap.so.logger.MsoLogger; import org.onap.so.requestsdb.RequestsDbConstant; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Bean; import org.springframework.test.context.ActiveProfiles; @@ -109,6 +109,7 @@ public class MSORequestDBImplTest { testRequest.setVfModuleId("c7d527b1-7a91-49fd-b97d-1c8c0f4a7992"); testRequest.setVfModuleModelName("vSAMP10aDEV::base::module-0"); testRequest.setVnfId("b92f60c8-8de3-46c1-8dc1-e4390ac2b005"); + testRequest.setRequestUrl("http://localhost:8080/onap/so/infra/serviceInstantiation/v7/serviceInstances"); return testRequest; } diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/application/EmbeddedMariaDbConfig.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/application/EmbeddedMariaDbConfig.java index cd07f6757f..c1848e3aad 100644 --- a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/application/EmbeddedMariaDbConfig.java +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/application/EmbeddedMariaDbConfig.java @@ -25,7 +25,7 @@ import ch.vorburger.mariadb4j.springframework.MariaDB4jSpringService; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; +import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; import org.springframework.context.annotation.Bean; 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 7c037e4885..efb5932e51 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 @@ -30,7 +30,7 @@ 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.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; @@ -88,6 +88,7 @@ public class RequestsDbClientTest { infraActiveRequests.setRequestStatus("IN_PROGRESS"); infraActiveRequests.setAction("create"); infraActiveRequests.setRequestAction("someaction"); + infraActiveRequests.setRequestUrl("http://localhost:8080/onap/so/infra/serviceInstantiation/v7/serviceInstances"); requestsDbClient.save(infraActiveRequests); } @@ -174,7 +175,17 @@ public class RequestsDbClientTest { assertNull(requestsDbClient.getInfraActiveRequestbyRequestId(UUID.randomUUID().toString())); } + @Test + public void getInfraActiveRequestbyRequestIdWhereRequestUrlNullTest(){ + // requestUrl setup to null and save + infraActiveRequests.setRequestUrl(null); + requestsDbClient.save(infraActiveRequests); + InfraActiveRequests infraActiveRequestsResponse = requestsDbClient.getInfraActiveRequestbyRequestId(infraActiveRequests.getRequestId()); + verifyInfraActiveRequests(infraActiveRequestsResponse); + assertNull(infraActiveRequestsResponse.getRequestUrl()); + } + @Test public void getOneByServiceIdAndOperationIdTest(){ OperationStatus operationStatus = new OperationStatus(); |