summaryrefslogtreecommitdiffstats
path: root/adapters
diff options
context:
space:
mode:
authorRob Daugherty <rd472p@att.com>2018-09-13 19:36:37 +0000
committerGerrit Code Review <gerrit@onap.org>2018-09-13 19:36:37 +0000
commit3e5b564f4c1e1f731f2e2502bbc2ce868f7cedec (patch)
tree37c0b50cdd4238e3a8b5c6631e59cc57a05d8532 /adapters
parent15fdcda8aef5b8b698cd0a3d86eeaec5937c7bc6 (diff)
parent67b21f3bbf54828093fd27634d4d090111c04502 (diff)
Merge "Improve test coverage for requestdbclient"
Diffstat (limited to 'adapters')
-rw-r--r--adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/MSORequestDBApplication.java4
-rw-r--r--adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestDbClientPortChanger.java21
-rw-r--r--adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java169
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/MSOVfcApplication.java3
4 files changed, 195 insertions, 2 deletions
diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/MSORequestDBApplication.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/MSORequestDBApplication.java
index 21582a1e5f..3c8d732286 100644
--- a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/MSORequestDBApplication.java
+++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/MSORequestDBApplication.java
@@ -32,6 +32,8 @@ import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;
import net.javacrumbs.shedlock.spring.ScheduledLockConfiguration;
import net.javacrumbs.shedlock.spring.ScheduledLockConfigurationBuilder;
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
+import org.springframework.web.client.RestTemplate;
/**
* @since Version 1.0
@@ -67,4 +69,6 @@ public class MSORequestDBApplication {
.withDefaultLockAtMostFor(Duration.ofMinutes(10))
.build();
}
+
+
}
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<String, String> requestMap = new HashMap<>();
+ requestMap.put("operationalEnvironmentId", infraActiveRequests.getOperationalEnvId());
+ requestMap.put("operationalEnvironmentName", infraActiveRequests.getOperationalEnvName());
+ requestMap.put("resourceType", "operationalEnvironment");
+
+ List<InfraActiveRequests> 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<String, String> requestMap = new HashMap<>();
+ requestMap.put("operationalEnvironmentId", infraActiveRequests.getOperationalEnvId());
+
+ InfraActiveRequests infraActiveRequestsResponse = requestsDbClient.checkInstanceNameDuplicate((HashMap<String, String>)requestMap,null,infraActiveRequests.getRequestScope());
+
+ verifyInfraActiveRequests(infraActiveRequestsResponse);
+ }
+
+ @Test
+ public void getOrchestrationFiltersFromInfraActiveTest() {
+ Map<String, List<String>> requestMap = new HashMap<>();
+ List<String> 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<InfraActiveRequests> 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
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/MSOVfcApplication.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/MSOVfcApplication.java
index 6ff6ec9379..62234f910d 100644
--- a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/MSOVfcApplication.java
+++ b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/MSOVfcApplication.java
@@ -20,7 +20,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.so.adapters.vfc;
+package org.onap.so.adapters.vfc;
import org.springframework.boot.SpringApplication;
@@ -34,5 +34,4 @@ public class MSOVfcApplication {
public static void main(String... args) {
SpringApplication.run(MSOVfcApplication.class, args);
}
-
}