aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/test/java/org
diff options
context:
space:
mode:
authorAbhishek Shekhar <abhishek.shekhar1@amdocs.com>2018-03-28 13:27:18 +0530
committerAbhishek Shekhar <abhishek.shekhar1@amdocs.com>2018-03-28 13:27:18 +0530
commitcf0790e8a1f804a10761bec64914da7fabb2ca63 (patch)
treeedcc170d43f5fce0b7a603413235e12f23e6e576 /mso-api-handlers/mso-api-handler-infra/src/test/java/org
parent9903fb12ab6b3081e8c1b680ae4088d638503776 (diff)
UT Coverage for API Handler
1. NetworkRequestHandler 2. VolumeInfoHandler Change-Id: I2b04effcdc9cd8e5ff0af5a73c2fcbfba580f645 Issue-ID: SO-369 Signed-off-by: Abhishek Shekhar <abhishek.shekhar1@amdocs.com>
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/test/java/org')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/NetworkRequestHandlerTest.java131
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VolumeInfoHandlerTest.java83
2 files changed, 206 insertions, 8 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/NetworkRequestHandlerTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/NetworkRequestHandlerTest.java
index 3c35fed516..b182192257 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/NetworkRequestHandlerTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/NetworkRequestHandlerTest.java
@@ -22,6 +22,9 @@ package org.openecomp.mso.apihandlerinfra;
import static org.junit.Assert.assertTrue;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.lang.reflect.Field;
import java.net.URI;
import java.sql.Timestamp;
@@ -34,20 +37,38 @@ import javax.ws.rs.core.UriInfo;
import mockit.Mock;
import mockit.MockUp;
+import org.apache.http.HttpResponse;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.entity.BasicHttpEntity;
+import org.apache.http.message.BasicHttpResponse;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
+import org.openecomp.mso.apihandler.common.CamundaClient;
import org.openecomp.mso.apihandlerinfra.networkbeans.NetworkRequest;
+import org.openecomp.mso.db.catalog.CatalogDatabase;
+import org.openecomp.mso.db.catalog.beans.NetworkRecipe;
+import org.openecomp.mso.db.catalog.beans.VfModule;
+import org.openecomp.mso.db.catalog.beans.VnfResource;
+import org.openecomp.mso.properties.MsoPropertiesFactory;
import org.openecomp.mso.requestsdb.InfraActiveRequests;
import org.openecomp.mso.requestsdb.InfraRequests;
import org.openecomp.mso.requestsdb.RequestsDatabase;
public class NetworkRequestHandlerTest {
+ private static final String REQ_XML = "<network-request xmlns=\"http://org.openecomp/mso/infra/network-request/v1\"> <request-info> <request-id>e1fc3ed3-31e5-48a8-913b-23184c1e9443</request-id><action>CREATE</action> <source>VID</source> <service-instance-id>e1fc3ed3-31e5-48a8-913b-23184c1e9443</service-instance-id></request-info> <network-inputs> <network-id>e1fc3ed3-31e5-48a8-913b-23184c1e9443</network-id> <network-name>nwInstanceName</network-name> <network-type>nwModelName</network-type><modelCustomizationId>e1fc3ed3-31e5-48a8-913b-23184c1e9443</modelCustomizationId> <aic-cloud-region>e1fc3ed3-31e5-48a8-913b-23184c1e9443</aic-cloud-region> <tenant-id>e1fc3ed3-31e5-48a8-913b-23184c1e9443</tenant-id><service-id>e1fc3ed3-31e5-48a8-913b-23184c1e9443</service-id> <backout-on-failure>false</backout-on-failure><sdncVersion>1802</sdncVersion><service-instance-id>e1fc3ed3-31e5-48a8-913b-23184c1e9443</service-instance-id></network-inputs> <network-params></network-params> </network-request>";
+
+ private static MockUp<RequestsDatabase> mockRDB;
+ private static MockUp<NetworkMsoInfraRequest> mockMsoRequest;
+ private static MockUp<CatalogDatabase> mockCDB;
+ private static MockUp<CamundaClient> mockCamundaClient;
NetworkRequestHandler handler = null;
-
-UriInfo uriInfo = null;
+ UriInfo uriInfo = null;
@Before
public void setup() throws Exception{
@@ -63,31 +84,127 @@ UriInfo uriInfo = null;
f1.set(handler, uriInfo);
}
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
+ msoPropertiesFactory.removeAllMsoProperties();
+ msoPropertiesFactory.initializeMsoProperties(Constants.MSO_PROP_APIHANDLER_INFRA, "src/test/resources/mso.apihandler-infra.properties");
+
+ mockRDB = new MockUp<RequestsDatabase>() {
+ @Mock
+ public InfraActiveRequests checkDuplicateByVnfName (String vnfName, String action, String requestType) {
+ return null;
+ }
+ @Mock
+ public int updateInfraStatus (String requestId, String requestStatus, long progress, String lastModifiedBy) {
+ return 1;
+ }
+
+ @Mock
+ public int updateInfraFinalStatus (String requestId, String requestStatus, String statusMessage, long progress, String responseBody, String lastModifiedBy) {
+ return 1;
+ }
+ };
+
+ mockMsoRequest = new MockUp<NetworkMsoInfraRequest>() {
+ @Mock
+ public void createRequestRecord (Status status) {
+ return;
+ }
+ };
+
+ mockCDB = new MockUp<CatalogDatabase>() {
+ @Mock
+ public NetworkRecipe getNetworkRecipe (String networkType, String action, String serviceType) {
+ final NetworkRecipe networkRecipe = new NetworkRecipe();
+ networkRecipe.setOrchestrationUri("test/vnf");
+ networkRecipe.setRecipeTimeout(180);
+ return networkRecipe;
+ }
+
+ @Mock
+ public VfModule getVfModuleType(String type, String version) {
+ final VfModule vfModule = new VfModule();
+ return vfModule;
+ }
+
+ @Mock
+ public VnfResource getVnfResource (String vnfType, String serviceVersion) {
+ final VnfResource vnfResource = new VnfResource();
+ return vnfResource;
+ }
+ };
+
+ mockCamundaClient = new MockUp<CamundaClient>() {
+ @Mock
+ public HttpResponse post(String camundaReqXML, String requestId,
+ String requestTimeout, String schemaVersion, String serviceInstanceId, String action)
+ throws ClientProtocolException, IOException {
+ ProtocolVersion pv = new ProtocolVersion("HTTP",1,1);
+ HttpResponse resp = new BasicHttpResponse(pv,200, "test response");
+ BasicHttpEntity entity = new BasicHttpEntity();
+ String body = "{\"response\":\"success\",\"message\":\"success\"}";
+ InputStream instream = new ByteArrayInputStream(body.getBytes());
+ entity.setContent(instream);
+ resp.setEntity(entity);
+ return resp;
+ }
+ };
+
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ mockRDB.tearDown();
+ mockMsoRequest.tearDown();
+ mockCDB.tearDown();
+ mockCamundaClient.tearDown();
+ }
@Test
public void manageVnfRequestTest(){
Mockito.when(uriInfo.getRequestUri()).thenReturn(URI.create("http://localhost:8080/test"));
- Response resp = handler.manageNetworkRequest("<name>Test</name>", "v2");
+ Response resp = handler.manageNetworkRequest(REQ_XML, "v2");
assertTrue(null != resp);
}
@Test
public void manageVnfRequestTestV1(){
Mockito.when(uriInfo.getRequestUri()).thenReturn(URI.create("http://localhost:8080/test"));
- Response resp = handler.manageNetworkRequest("<name>Test</name>", "v1");
+ Response resp = handler.manageNetworkRequest(REQ_XML, "v1");
assertTrue(null != resp);
}
@Test
public void manageVnfRequestTestV3(){
Mockito.when(uriInfo.getRequestUri()).thenReturn(URI.create("http://localhost:8080/test"));
- Response resp = handler.manageNetworkRequest("<name>Test</name>", "v3");
+ Response resp = handler.manageNetworkRequest(REQ_XML, "v3");
assertTrue(null != resp);
}
+
+ /*@Test
+ public void manageNetworkRequestTestV3Duplicate(){
+
+ MockUp<RequestsDatabase> mockDuplicate = new MockUp<RequestsDatabase>() {
+ @Mock
+ public InfraActiveRequests checkDuplicateByVnfName(String vnfName, String action, String requestType) {
+ return new InfraActiveRequests();
+ }
+ };
+
+ try {
+ Mockito.when(uriInfo.getRequestUri()).thenReturn(URI.create("http://localhost:8080/test"));
+ Response resp = handler.manageNetworkRequest(REQ_XML, "v3");
+ assertTrue(null != resp);
+ } finally {
+ mockDuplicate.tearDown();
+ }
+ }*/
@Test
public void manageVnfRequestTestInvalidVersion(){
- Response resp = handler.manageNetworkRequest("<name>Test</name>", "v249");
+ Response resp = handler.manageNetworkRequest(REQ_XML, "v249");
assertTrue(null != resp);
}
@@ -102,7 +219,7 @@ UriInfo uriInfo = null;
return false;
}
};
- Response resp = handler.manageNetworkRequest("<name>Test</name>", "v2");
+ Response resp = handler.manageNetworkRequest(REQ_XML, "v2");
assertTrue(null != resp);
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VolumeInfoHandlerTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VolumeInfoHandlerTest.java
index 78ed076b55..ffdf5d40b4 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VolumeInfoHandlerTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VolumeInfoHandlerTest.java
@@ -22,14 +22,78 @@ package org.openecomp.mso.apihandlerinfra;
import static org.junit.Assert.assertTrue;
+import mockit.Mock;
+import mockit.MockUp;
+import org.apache.http.HttpResponse;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.entity.BasicHttpEntity;
+import org.apache.http.message.BasicHttpResponse;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
+import org.openecomp.mso.apihandler.common.CamundaClient;
+import org.openecomp.mso.apihandlerinfra.volumebeans.ActionType;
+import org.openecomp.mso.apihandlerinfra.volumebeans.RequestStatusType;
import org.openecomp.mso.apihandlerinfra.volumebeans.VolumeRequest;
+import org.openecomp.mso.db.catalog.CatalogDatabase;
+import org.openecomp.mso.db.catalog.beans.NetworkRecipe;
+import org.openecomp.mso.db.catalog.beans.VfModule;
+import org.openecomp.mso.db.catalog.beans.VnfResource;
+import org.openecomp.mso.properties.MsoPropertiesFactory;
+import org.openecomp.mso.requestsdb.InfraActiveRequests;
import org.openecomp.mso.requestsdb.InfraRequests;
+import org.openecomp.mso.requestsdb.RequestsDatabase;
+
+import javax.ws.rs.core.Response;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Timestamp;
+import java.time.LocalDateTime;
+import java.util.Collections;
+import java.util.List;
public class VolumeInfoHandlerTest {
VolumeInfoHandler handler = new VolumeInfoHandler();
-
+
+ private static MockUp<RequestsDatabase> mockRDB;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
+ msoPropertiesFactory.removeAllMsoProperties();
+ msoPropertiesFactory.initializeMsoProperties(Constants.MSO_PROP_APIHANDLER_INFRA, "src/test/resources/mso.apihandler-infra.properties");
+
+ mockRDB = new MockUp<RequestsDatabase>() {
+ @Mock
+ public List<InfraActiveRequests> getRequestListFromInfraActive (String queryAttributeName,
+ String queryValue,
+ String requestType) {
+ final InfraActiveRequests requests = new InfraActiveRequests();
+ requests.setAction(ActionType.CREATE.name());
+ requests.setRequestStatus(RequestStatusType.IN_PROGRESS.name());
+ requests.setStartTime(Timestamp.valueOf(LocalDateTime.now()));
+ return Collections.singletonList(requests);
+ }
+ @Mock
+ public InfraActiveRequests getRequestFromInfraActive (String requestId, String requestType) {
+ final InfraActiveRequests requests = new InfraActiveRequests();
+ requests.setAction(ActionType.CREATE.name());
+ requests.setRequestStatus(RequestStatusType.IN_PROGRESS.name());
+ requests.setStartTime(Timestamp.valueOf(LocalDateTime.now()));
+ return requests;
+ }
+ };
+
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ mockRDB.tearDown();
+ }
+
@Test
public void fillVnfRequestTestV3(){
VolumeRequest qr = new VolumeRequest();
@@ -51,4 +115,21 @@ public class VolumeInfoHandlerTest {
String vnfid = (String)qr.getVolumeParams();
assertTrue(vnfid.equals("test"));
}
+
+ @Test
+ public void queryFilters() {
+ final Response response = handler.queryFilters("vnf-type", "svc-type", "aicNode", "tenant-id",
+ "vg-id", "vg-name", "v3");
+ }
+
+ @Test
+ public void queryFilters2() {
+ final Response response = handler.queryFilters(null, "svc-type", "aicNode", "tenant-id",
+ "vg-id", "vg-name", "v3");
+ }
+
+ @Test
+ public void getRequest() {
+ final Response response = handler.getRequest("request-id", "v3");
+ }
}