summaryrefslogtreecommitdiffstats
path: root/mso-api-handlers
diff options
context:
space:
mode:
authorAbhishek Shekhar <abhishek.shekhar1@amdocs.com>2018-03-28 19:46:15 +0530
committerAbhishek Shekhar <abhishek.shekhar1@amdocs.com>2018-03-28 20:31:28 +0530
commitb454a280561c0f5e040db9a63088e536710b31cd (patch)
tree84fed8b966e96fb640f5fc851e70b698e91a5026 /mso-api-handlers
parent4e651eb259dac4188e1568ac65e69d68a91e6296 (diff)
UT Coverage for API Handler
1. VnfMsoInfraRequest 2. MsoRequest 3. NetworkRequestHandler 4. OrchestrationRequests Change-Id: Id85e5bd157bb491287ffb229f7b87c501554ca0f Issue-ID: SO-369 Signed-off-by: Abhishek Shekhar <abhishek.shekhar1@amdocs.com>
Diffstat (limited to 'mso-api-handlers')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/pom.xml12
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/MsoRequestTest.java24
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/NetworkRequestHandlerTest.java50
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequestsTest.java3
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VnfMsoInfraRequestTest.java45
5 files changed, 90 insertions, 44 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/pom.xml b/mso-api-handlers/mso-api-handler-infra/pom.xml
index 93b6c8fbb5..97bd8348d3 100644
--- a/mso-api-handlers/mso-api-handler-infra/pom.xml
+++ b/mso-api-handlers/mso-api-handler-infra/pom.xml
@@ -225,6 +225,18 @@
<artifactId>json</artifactId>
<version>20160212</version>
</dependency>
+ <dependency>
+ <groupId>org.jmockit</groupId>
+ <artifactId>jmockit</artifactId>
+ <version>1.19</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/MsoRequestTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/MsoRequestTest.java
index 7963217721..7fb3bf00b0 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/MsoRequestTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/MsoRequestTest.java
@@ -25,18 +25,24 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
+import java.io.PrintStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
+import mockit.Expectations;
+import mockit.Mocked;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.CharEncoding;
+import org.hibernate.Session;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.openecomp.mso.apihandler.common.ValidationException;
+import org.openecomp.mso.db.AbstractSessionFactoryManager;
+import org.openecomp.mso.properties.MsoJavaProperties;
import org.openecomp.mso.serviceinstancebeans.ServiceInstancesRequest;
import com.fasterxml.jackson.core.JsonParseException;
@@ -597,4 +603,22 @@ public class MsoRequestTest {
assertNotNull(msoRequest.getRequestId());
assertEquals(msoRequest.getReqVersion(), 6);
}
+
+ @Test
+ public void createRequestRecord(@Mocked AbstractSessionFactoryManager sessionFactoryManager,
+ @Mocked Session session) throws ValidationException, IOException {
+
+ new Expectations() {{
+ sessionFactoryManager.getSessionFactory().openSession(); result = session;
+ }};
+
+ this.requestJSON = inputStream("/v6AddRelationships.json");
+ this.instanceIdMapTest.put("serviceInstanceId", "ff305d54-75b4-431b-adb2-eb6b9e5ff000");
+ this.sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
+ this.msoRequest = new MsoRequest ("V6RemoveRelationships");
+ msoRequest.parse(sir, instanceIdMapTest, Action.removeRelationships, "v6", originalRequestJSON);
+ msoRequest.createRequestRecord(Status.COMPLETE, Action.createInstance);
+
+ }
+
}
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 b182192257..2089cf1d32 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
@@ -34,14 +34,17 @@ import java.util.List;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
+import mockit.Expectations;
import mockit.Mock;
import mockit.MockUp;
+import mockit.Mocked;
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.hibernate.Session;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -50,6 +53,7 @@ import org.mockito.Mockito;
import org.openecomp.mso.apihandler.common.CamundaClient;
import org.openecomp.mso.apihandlerinfra.networkbeans.NetworkRequest;
+import org.openecomp.mso.db.AbstractSessionFactoryManager;
import org.openecomp.mso.db.catalog.CatalogDatabase;
import org.openecomp.mso.db.catalog.beans.NetworkRecipe;
import org.openecomp.mso.db.catalog.beans.VfModule;
@@ -63,7 +67,6 @@ 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;
@@ -107,13 +110,6 @@ public class NetworkRequestHandlerTest {
}
};
- 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) {
@@ -157,50 +153,42 @@ public class NetworkRequestHandlerTest {
@AfterClass
public static void tearDown() {
mockRDB.tearDown();
- mockMsoRequest.tearDown();
mockCDB.tearDown();
mockCamundaClient.tearDown();
}
@Test
- public void manageVnfRequestTest(){
+ public void manageVnfRequestTest(@Mocked AbstractSessionFactoryManager sessionFactoryManager,
+ @Mocked Session session){
+ new Expectations() {{
+ sessionFactoryManager.getSessionFactory().openSession(); result = session;
+ }};
Mockito.when(uriInfo.getRequestUri()).thenReturn(URI.create("http://localhost:8080/test"));
Response resp = handler.manageNetworkRequest(REQ_XML, "v2");
assertTrue(null != resp);
}
@Test
- public void manageVnfRequestTestV1(){
+ public void manageVnfRequestTestV1(@Mocked AbstractSessionFactoryManager sessionFactoryManager,
+ @Mocked Session session){
+ new Expectations() {{
+ sessionFactoryManager.getSessionFactory().openSession(); result = session;
+ }};
Mockito.when(uriInfo.getRequestUri()).thenReturn(URI.create("http://localhost:8080/test"));
Response resp = handler.manageNetworkRequest(REQ_XML, "v1");
assertTrue(null != resp);
}
@Test
- public void manageVnfRequestTestV3(){
+ public void manageVnfRequestTestV3(@Mocked AbstractSessionFactoryManager sessionFactoryManager,
+ @Mocked Session session){
+ new Expectations() {{
+ sessionFactoryManager.getSessionFactory().openSession(); result = session;
+ }};
Mockito.when(uriInfo.getRequestUri()).thenReturn(URI.create("http://localhost:8080/test"));
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(){
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequestsTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequestsTest.java
index be76d433aa..fa1cce462f 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequestsTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequestsTest.java
@@ -183,7 +183,8 @@ public class OrchestrationRequestsTest {
Response response = null;
try {
OrchestrationRequests requests = new OrchestrationRequests();
- response = requests.getOrchestrationRequest(new ResteasyUriInfo(new URI("")),"v5");
+ final ResteasyUriInfo ui = new ResteasyUriInfo(new URI("", "", "", "filter=service-instance-id:EQUALS:abc", ""));
+ response = requests.getOrchestrationRequest(ui,"v5");
} finally {
mockUpRDB.tearDown();
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VnfMsoInfraRequestTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VnfMsoInfraRequestTest.java
index c8ab6b5612..9a9dec3c27 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VnfMsoInfraRequestTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VnfMsoInfraRequestTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,19 +20,40 @@
package org.openecomp.mso.apihandlerinfra;
-import static org.junit.Assert.assertTrue;
-
+import mockit.Expectations;
+import mockit.Mocked;
+import mockit.Tested;
+import mockit.integration.junit4.JMockit;
+import org.hibernate.Session;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
import org.openecomp.mso.apihandler.common.ValidationException;
+import org.openecomp.mso.db.AbstractSessionFactoryManager;
import org.openecomp.mso.properties.MsoJavaProperties;
+@RunWith(JMockit.class)
public class VnfMsoInfraRequestTest {
- VnfMsoInfraRequest request = new VnfMsoInfraRequest("29919020");
-
- @Test(expected=Exception.class)
- public void parseTest() throws ValidationException {
- String reqXML = "<vnf-request><request-info> <request-id>29993</request-id><request-status>COMPLETE</request-status></request-info></vnf-request>";
- request.parse(reqXML, "v1", new MsoJavaProperties());
- }
-
+
+ VnfMsoInfraRequest request = new VnfMsoInfraRequest("29919020");
+ private String reqXML = "<vnf-request xmlns=\"http://org.openecomp/mso/infra/vnf-request/v1\"><request-info><request-id>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</request-id><action>CREATE_VF_MODULE</action><source>VID</source><!-- new 1610 field --><service-instance-id>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</service-instance-id></request-info><vnf-inputs><!-- not in use in 1610 --><vnf-name>vnfName</vnf-name><vnf-type>vnfType</vnf-type><vnf-id>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</vnf-id><volume-group-id>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</volume-group-id><vf-module-id>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</vf-module-id><vf-module-name>vfModuleName</vf-module-name><vf-module-model-name>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</vf-module-model-name><model-customization-id>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</model-customization-id><asdc-service-model-version>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</asdc-service-model-version><aic-cloud-region>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</aic-cloud-region><tenant-id>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</tenant-id><service-id>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</service-id><backout-on-failure>false</backout-on-failure><service-instance-id>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</service-instance-id></vnf-inputs><vnf-params><vnf-parameter-name>pName</vnf-parameter-name><vnf-parameter-value>pValue</vnf-parameter-value></vnf-params></vnf-request>";
+
+ @Test
+ public void parseTest() throws ValidationException {
+ request.parse(reqXML, "v3", new MsoJavaProperties());
+ }
+
+ @Test
+ public void createRequestRecord(@Mocked AbstractSessionFactoryManager sessionFactoryManager,
+ @Mocked Session session) throws ValidationException {
+
+ new Expectations() {{
+ sessionFactoryManager.getSessionFactory().openSession(); result = session;
+ }};
+
+ request.parse(reqXML, "v3", new MsoJavaProperties());
+ request.createRequestRecord(Status.COMPLETE);
+
+ }
+
}