summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/VnfmAdapter2DriverManagerTest.java228
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java14
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java14
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfmTest.java426
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/AuthMgrTest.java15
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgrTest.java162
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/AuthRoaTest.java199
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfAdapterResourceRoaTest.java20
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfResourceRoaTest.java315
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java704
10 files changed, 1189 insertions, 908 deletions
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/VnfmAdapter2DriverManagerTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/VnfmAdapter2DriverManagerTest.java
index 7af73f86..df9ecbeb 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/VnfmAdapter2DriverManagerTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/VnfmAdapter2DriverManagerTest.java
@@ -60,15 +60,15 @@ public class VnfmAdapter2DriverManagerTest {
@Test
public void registerDriverTestNullResp() {
- new MockUp<VNFRestfulUtil>() {
-
- @Mock
- public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
- RestfulResponse response = new RestfulResponse();
-
- return null;
- }
- };
+// new MockUp<VNFRestfulUtil>() {
+//
+// @Mock
+// public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+// RestfulResponse response = new RestfulResponse();
+//
+// return null;
+// }
+// };
Map<String, String> paramsMap = new HashMap<>();
paramsMap.put("url", "/test/api");
paramsMap.put("path", "http://localhost:8080");
@@ -79,18 +79,18 @@ public class VnfmAdapter2DriverManagerTest {
@Test
public void registerDriverCreateSuccess() {
- new MockUp<VNFRestfulUtil>() {
-
- @Mock
- public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
- RestfulResponse response = new RestfulResponse();
- response.setStatus(201);
-
- String vimStr = toJson(vim);
- response.setResponseJson(vimStr);
- return response;
- }
- };
+// new MockUp<VNFRestfulUtil>() {
+//
+// @Mock
+// public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+// RestfulResponse response = new RestfulResponse();
+// response.setStatus(201);
+//
+// String vimStr = toJson(vim);
+// response.setResponseJson(vimStr);
+// return response;
+// }
+// };
Map<String, String> paramsMap = new HashMap<>();
paramsMap.put("url", "/test/api");
paramsMap.put("path", "http://localhost:8080");
@@ -101,18 +101,18 @@ public class VnfmAdapter2DriverManagerTest {
@Test
public void registerDriverOkSuccess() {
- new MockUp<VNFRestfulUtil>() {
-
- @Mock
- public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
- RestfulResponse response = new RestfulResponse();
- response.setStatus(200);
-
- String vimStr = toJson(vim);
- response.setResponseJson(vimStr);
- return response;
- }
- };
+// new MockUp<VNFRestfulUtil>() {
+//
+// @Mock
+// public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+// RestfulResponse response = new RestfulResponse();
+// response.setStatus(200);
+//
+// String vimStr = toJson(vim);
+// response.setResponseJson(vimStr);
+// return response;
+// }
+// };
Map<String, String> paramsMap = new HashMap<>();
paramsMap.put("url", "/test/api");
paramsMap.put("path", "http://localhost:8080");
@@ -123,18 +123,18 @@ public class VnfmAdapter2DriverManagerTest {
@Test
public void registerDriverTestInvalidParams() {
- new MockUp<VNFRestfulUtil>() {
-
- @Mock
- public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
- RestfulResponse response = new RestfulResponse();
- response.setStatus(415);
-
- String vimStr = toJson(vim);
- response.setResponseJson(vimStr);
- return response;
- }
- };
+// new MockUp<VNFRestfulUtil>() {
+//
+// @Mock
+// public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+// RestfulResponse response = new RestfulResponse();
+// response.setStatus(415);
+//
+// String vimStr = toJson(vim);
+// response.setResponseJson(vimStr);
+// return response;
+// }
+// };
Map<String, String> paramsMap = new HashMap<>();
paramsMap.put("url", "/test/api");
paramsMap.put("path", "http://localhost:8080");
@@ -145,18 +145,18 @@ public class VnfmAdapter2DriverManagerTest {
@Test
public void registerDriverTestInternalError() {
- new MockUp<VNFRestfulUtil>() {
-
- @Mock
- public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
- RestfulResponse response = new RestfulResponse();
- response.setStatus(500);
-
- String vimStr = toJson(vim);
- response.setResponseJson(vimStr);
- return response;
- }
- };
+// new MockUp<VNFRestfulUtil>() {
+//
+// @Mock
+// public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+// RestfulResponse response = new RestfulResponse();
+// response.setStatus(500);
+//
+// String vimStr = toJson(vim);
+// response.setResponseJson(vimStr);
+// return response;
+// }
+// };
Map<String, String> paramsMap = new HashMap<>();
paramsMap.put("url", "/test/api");
paramsMap.put("path", "http://localhost:8080");
@@ -167,15 +167,15 @@ public class VnfmAdapter2DriverManagerTest {
@Test
public void unregisterDriverTestNullResp() {
- new MockUp<VNFRestfulUtil>() {
-
- @Mock
- public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
- RestfulResponse response = new RestfulResponse();
-
- return null;
- }
- };
+// new MockUp<VNFRestfulUtil>() {
+//
+// @Mock
+// public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+// RestfulResponse response = new RestfulResponse();
+//
+// return null;
+// }
+// };
Map<String, String> paramsMap = new HashMap<>();
paramsMap.put("url", "/test/api");
paramsMap.put("path", "http://localhost:8080");
@@ -186,18 +186,18 @@ public class VnfmAdapter2DriverManagerTest {
@Test
public void unregisterDriverDeleteSuccess() {
- new MockUp<VNFRestfulUtil>() {
-
- @Mock
- public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
- RestfulResponse response = new RestfulResponse();
- response.setStatus(204);
-
- String vimStr = toJson(vim);
- response.setResponseJson(vimStr);
- return response;
- }
- };
+// new MockUp<VNFRestfulUtil>() {
+//
+// @Mock
+// public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+// RestfulResponse response = new RestfulResponse();
+// response.setStatus(204);
+//
+// String vimStr = toJson(vim);
+// response.setResponseJson(vimStr);
+// return response;
+// }
+// };
Map<String, String> paramsMap = new HashMap<>();
paramsMap.put("url", "/test/api");
paramsMap.put("path", "http://localhost:8080");
@@ -208,18 +208,18 @@ public class VnfmAdapter2DriverManagerTest {
@Test
public void unregisterDriverResourceNotFound() {
- new MockUp<VNFRestfulUtil>() {
-
- @Mock
- public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
- RestfulResponse response = new RestfulResponse();
- response.setStatus(404);
-
- String vimStr = toJson(vim);
- response.setResponseJson(vimStr);
- return response;
- }
- };
+// new MockUp<VNFRestfulUtil>() {
+//
+// @Mock
+// public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+// RestfulResponse response = new RestfulResponse();
+// response.setStatus(404);
+//
+// String vimStr = toJson(vim);
+// response.setResponseJson(vimStr);
+// return response;
+// }
+// };
Map<String, String> paramsMap = new HashMap<>();
paramsMap.put("url", "/test/api");
paramsMap.put("path", "http://localhost:8080");
@@ -230,18 +230,18 @@ public class VnfmAdapter2DriverManagerTest {
@Test
public void unregisterDriverTestInvalidParams() {
- new MockUp<VNFRestfulUtil>() {
-
- @Mock
- public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
- RestfulResponse response = new RestfulResponse();
- response.setStatus(415);
-
- String vimStr = toJson(vim);
- response.setResponseJson(vimStr);
- return response;
- }
- };
+// new MockUp<VNFRestfulUtil>() {
+//
+// @Mock
+// public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+// RestfulResponse response = new RestfulResponse();
+// response.setStatus(415);
+//
+// String vimStr = toJson(vim);
+// response.setResponseJson(vimStr);
+// return response;
+// }
+// };
Map<String, String> paramsMap = new HashMap<>();
paramsMap.put("url", "/test/api");
paramsMap.put("path", "http://localhost:8080");
@@ -252,18 +252,18 @@ public class VnfmAdapter2DriverManagerTest {
@Test
public void unregisterDriverTestInternalError() {
- new MockUp<VNFRestfulUtil>() {
-
- @Mock
- public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
- RestfulResponse response = new RestfulResponse();
- response.setStatus(500);
-
- String vimStr = toJson(vim);
- response.setResponseJson(vimStr);
- return response;
- }
- };
+// new MockUp<VNFRestfulUtil>() {
+//
+// @Mock
+// public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+// RestfulResponse response = new RestfulResponse();
+// response.setStatus(500);
+//
+// String vimStr = toJson(vim);
+// response.setResponseJson(vimStr);
+// return response;
+// }
+// };
Map<String, String> paramsMap = new HashMap<>();
paramsMap.put("url", "/test/api");
paramsMap.put("path", "http://localhost:8080");
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java
index d61c3b1c..97c967cb 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java
@@ -40,13 +40,13 @@ public class VnfmAdapter2DriverMgrServiceTest {
@Test
public void testRegister2(){
- new MockUp<VnfmAdapter2DriverMgrService>(){
- @Mock
- public String readVnfmAdapterInfoFromJson() throws IOException {
- return "{'url':'http://127.0.0.1'}";
-
- }
- };
+// new MockUp<VnfmAdapter2DriverMgrService>(){
+// @Mock
+// public String readVnfmAdapterInfoFromJson() throws IOException {
+// return "{'url':'http://127.0.0.1'}";
+//
+// }
+// };
VnfmAdapter2DriverMgrService mgr = new VnfmAdapter2DriverMgrService();
mgr.register();
mgr.unregister();
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java
index 56e1eea3..d1c1a5c4 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java
@@ -32,13 +32,13 @@ import mockit.MockUp;
public class VnfmAdapterMgrServiceTest {
@Test
public void testRegister(){
- new MockUp<VnfmAdapterMgrService>(){
-
- @Mock
- public String readVnfmAdapterInfoFromJson() throws IOException {
- return "{'abc':'123'}";
- }
- };
+// new MockUp<VnfmAdapterMgrService>(){
+//
+// @Mock
+// public String readVnfmAdapterInfoFromJson() throws IOException {
+// return "{'abc':'123'}";
+// }
+// };
VnfmAdapterMgrService mgr = new VnfmAdapterMgrService();
mgr.register();
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfmTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfmTest.java
index 1e4937b8..3c1d2495 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfmTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfmTest.java
@@ -18,13 +18,12 @@ package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.vnf;
import static org.junit.Assert.assertEquals;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
import org.junit.Test;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.ResultRequestUtil;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.adapter.impl.AdapterResourceManager;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
-import mockit.Mock;
-import mockit.MockUp;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@@ -40,21 +39,21 @@ public class VnfMgrVnfmTest {
@Test
public void testCreateVnf() {
- new MockUp<ResultRequestUtil>() {
-
- @Mock
- public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
- JSONObject resultJson = new JSONObject();
- resultJson.put("retCode", Constant.HTTP_CREATED);
- JSONObject appInfo = new JSONObject();
- appInfo.put("vnfinstanceid", "id");
- appInfo.put("project_id", "project_id");
- JSONObject data = new JSONObject();
- data.put("app_info", appInfo);
- resultJson.put("data", data);
- return resultJson;
- }
- };
+// new MockUp<ResultRequestUtil>() {
+//
+// @Mock
+// public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
+// JSONObject resultJson = new JSONObject();
+// resultJson.put("retCode", Constant.HTTP_CREATED);
+// JSONObject appInfo = new JSONObject();
+// appInfo.put("vnfinstanceid", "id");
+// appInfo.put("project_id", "project_id");
+// JSONObject data = new JSONObject();
+// data.put("app_info", appInfo);
+// resultJson.put("data", data);
+// return resultJson;
+// }
+// };
String data = "{\"vnfmInfo\":{\"url\":\"url\"}}";
@@ -68,15 +67,15 @@ public class VnfMgrVnfmTest {
@Test
public void testCreateVnfByBadRequest() {
- new MockUp<ResultRequestUtil>() {
-
- @Mock
- public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
- JSONObject resultJson = new JSONObject();
- resultJson.put("retCode", Constant.HTTP_BAD_REQUEST);
- return resultJson;
- }
- };
+// new MockUp<ResultRequestUtil>() {
+//
+// @Mock
+// public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
+// JSONObject resultJson = new JSONObject();
+// resultJson.put("retCode", Constant.HTTP_BAD_REQUEST);
+// return resultJson;
+// }
+// };
String data = "{\"vnfmInfo\":{\"url\":\"url\"}}";
JSONObject subJsonObject = JSONObject.fromObject(data);
VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
@@ -90,15 +89,15 @@ public class VnfMgrVnfmTest {
@Test
public void testCreateVnfByNotFound() {
- new MockUp<ResultRequestUtil>() {
-
- @Mock
- public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
- JSONObject resultJson = new JSONObject();
- resultJson.put("retCode", Constant.HTTP_NOTFOUND);
- return resultJson;
- }
- };
+// new MockUp<ResultRequestUtil>() {
+//
+// @Mock
+// public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
+// JSONObject resultJson = new JSONObject();
+// resultJson.put("retCode", Constant.HTTP_NOTFOUND);
+// return resultJson;
+// }
+// };
String data = "{\"vnfmInfo\":{\"url\":\"url\"}}";
JSONObject subJsonObject = JSONObject.fromObject(data);
JSONObject vnfmObjcet = new JSONObject();
@@ -112,14 +111,14 @@ public class VnfMgrVnfmTest {
@Test
public void testCreateVnfByJSONException() {
- new MockUp<ResultRequestUtil>() {
-
- @Mock
- public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
- JSONObject resultJson = new JSONObject();
- return resultJson;
- }
- };
+// new MockUp<ResultRequestUtil>() {
+//
+// @Mock
+// public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
+// JSONObject resultJson = new JSONObject();
+// return resultJson;
+// }
+// };
String data = "{\"vnfmInfo\":{\"url\":\"url\"}}";
JSONObject subJsonObject = JSONObject.fromObject(data);
JSONObject vnfmObjcet = new JSONObject();
@@ -133,15 +132,15 @@ public class VnfMgrVnfmTest {
@Test
public void testRemoveVnf() {
- new MockUp<ResultRequestUtil>() {
-
- @Mock
- public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
- JSONObject resultJson = new JSONObject();
- resultJson.put("retCode", Constant.HTTP_NOCONTENT);
- return resultJson;
- }
- };
+// new MockUp<ResultRequestUtil>() {
+//
+// @Mock
+// public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
+// JSONObject resultJson = new JSONObject();
+// resultJson.put("retCode", Constant.HTTP_NOCONTENT);
+// return resultJson;
+// }
+// };
VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
JSONObject vnfmObject = new JSONObject();
JSONObject vnfObject = new JSONObject();
@@ -158,15 +157,15 @@ public class VnfMgrVnfmTest {
@Test
public void testRemoveVnfByCsmError() {
- new MockUp<ResultRequestUtil>() {
-
- @Mock
- public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
- JSONObject resultJson = new JSONObject();
- resultJson.put("retCode", Constant.HTTP_INNERERROR);
- return resultJson;
- }
- };
+// new MockUp<ResultRequestUtil>() {
+//
+// @Mock
+// public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
+// JSONObject resultJson = new JSONObject();
+// resultJson.put("retCode", Constant.HTTP_INNERERROR);
+// return resultJson;
+// }
+// };
VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
JSONObject vnfmObject = new JSONObject();
vnfmObject.put("url", "url");
@@ -179,22 +178,22 @@ public class VnfMgrVnfmTest {
}
@Test
public void getJobTestNormal(){
- new MockUp<ResultRequestUtil>(){
- @Mock
- public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson, String authModel) {
- JSONObject obj = new JSONObject();
- JSONObject dataobj = new JSONObject();
- dataobj.put("id", "2839");
- obj.put("retCode", 200);
- JSONArray basics = new JSONArray();
- basics.add("test123");
- JSONObject basicsData = new JSONObject();
- basicsData.put("vnf_list", basics);
- obj.put("data", basicsData);
- return obj;
- }
-
- };
+// new MockUp<ResultRequestUtil>(){
+// @Mock
+// public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson, String authModel) {
+// JSONObject obj = new JSONObject();
+// JSONObject dataobj = new JSONObject();
+// dataobj.put("id", "2839");
+// obj.put("retCode", 200);
+// JSONArray basics = new JSONArray();
+// basics.add("test123");
+// JSONObject basicsData = new JSONObject();
+// basicsData.put("vnf_list", basics);
+// obj.put("data", basicsData);
+// return obj;
+// }
+//
+// };
VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
JSONObject vnfmObject = new JSONObject();
@@ -205,22 +204,22 @@ public class VnfMgrVnfmTest {
@Test
public void getJobTestCreatedNormal(){
- new MockUp<ResultRequestUtil>(){
- @Mock
- public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson, String authModel) {
- JSONObject obj = new JSONObject();
- JSONObject dataobj = new JSONObject();
- dataobj.put("id", "2839");
- obj.put("retCode", 201);
- JSONArray basics = new JSONArray();
- basics.add("test123");
- JSONObject basicsData = new JSONObject();
- basicsData.put("vnf_list", basics);
- obj.put("data", basicsData);
- return obj;
- }
-
- };
+// new MockUp<ResultRequestUtil>(){
+// @Mock
+// public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson, String authModel) {
+// JSONObject obj = new JSONObject();
+// JSONObject dataobj = new JSONObject();
+// dataobj.put("id", "2839");
+// obj.put("retCode", 201);
+// JSONArray basics = new JSONArray();
+// basics.add("test123");
+// JSONObject basicsData = new JSONObject();
+// basicsData.put("vnf_list", basics);
+// obj.put("data", basicsData);
+// return obj;
+// }
+//
+// };
VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
JSONObject vnfmObject = new JSONObject();
@@ -231,22 +230,22 @@ public class VnfMgrVnfmTest {
@Test
public void getJobTestNullData(){
- new MockUp<ResultRequestUtil>(){
- @Mock
- public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson, String authModel) {
- JSONObject obj = new JSONObject();
- JSONObject dataobj = new JSONObject();
- dataobj.put("id", "2839");
- obj.put("retCode", 201);
- JSONArray basics = new JSONArray();
- basics.add("test123");
- JSONObject basicsData = new JSONObject();
- basicsData.put("basic", basics);
- obj.put("data", null);
- return obj;
- }
-
- };
+// new MockUp<ResultRequestUtil>(){
+// @Mock
+// public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson, String authModel) {
+// JSONObject obj = new JSONObject();
+// JSONObject dataobj = new JSONObject();
+// dataobj.put("id", "2839");
+// obj.put("retCode", 201);
+// JSONArray basics = new JSONArray();
+// basics.add("test123");
+// JSONObject basicsData = new JSONObject();
+// basicsData.put("basic", basics);
+// obj.put("data", null);
+// return obj;
+// }
+//
+// };
VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
JSONObject vnfmObject = new JSONObject();
@@ -257,22 +256,22 @@ public class VnfMgrVnfmTest {
@Test
public void getJobTestInternalError(){
- new MockUp<ResultRequestUtil>(){
- @Mock
- public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson, String authModel) {
- JSONObject obj = new JSONObject();
- JSONObject dataobj = new JSONObject();
- dataobj.put("id", "2839");
- obj.put("retCode", 500);
- JSONArray basics = new JSONArray();
- basics.add("test123");
- JSONObject basicsData = new JSONObject();
- basicsData.put("basic", basics);
- obj.put("data", null);
- return obj;
- }
-
- };
+// new MockUp<ResultRequestUtil>(){
+// @Mock
+// public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson, String authModel) {
+// JSONObject obj = new JSONObject();
+// JSONObject dataobj = new JSONObject();
+// dataobj.put("id", "2839");
+// obj.put("retCode", 500);
+// JSONArray basics = new JSONArray();
+// basics.add("test123");
+// JSONObject basicsData = new JSONObject();
+// basicsData.put("basic", basics);
+// obj.put("data", null);
+// return obj;
+// }
+//
+// };
VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
JSONObject vnfmObject = new JSONObject();
@@ -284,21 +283,21 @@ public class VnfMgrVnfmTest {
@Test
public void testScaleVnfOut() {
- new MockUp<ResultRequestUtil>() {
-
- @Mock
- public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
- JSONObject resultJson = new JSONObject();
- resultJson.put("retCode", Constant.HTTP_CREATED);
- JSONObject appInfo = new JSONObject();
- appInfo.put("vnfinstanceid", "id");
- appInfo.put("project_id", "project_id");
- JSONObject data = new JSONObject();
- data.put("app_info", appInfo);
- resultJson.put("data", data);
- return resultJson;
- }
- };
+// new MockUp<ResultRequestUtil>() {
+//
+// @Mock
+// public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
+// JSONObject resultJson = new JSONObject();
+// resultJson.put("retCode", Constant.HTTP_CREATED);
+// JSONObject appInfo = new JSONObject();
+// appInfo.put("vnfinstanceid", "id");
+// appInfo.put("project_id", "project_id");
+// JSONObject data = new JSONObject();
+// data.put("app_info", appInfo);
+// resultJson.put("data", data);
+// return resultJson;
+// }
+// };
String data = "{\"type\":\"SCALE_OUT\"}}";
JSONObject subJsonObject = JSONObject.fromObject(data);
JSONObject vnfmObjcet = new JSONObject();
@@ -310,32 +309,32 @@ public class VnfMgrVnfmTest {
@Test
public void testScaleVnfIn() {
- new MockUp<ResultRequestUtil>() {
-
- @Mock
- public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
- JSONObject resultJson = new JSONObject();
- resultJson.put("retCode", Constant.HTTP_CREATED);
- JSONObject appInfo = new JSONObject();
- appInfo.put("vnfinstanceid", "id");
- appInfo.put("project_id", "project_id");
- JSONObject data = new JSONObject();
- data.put("app_info", appInfo);
- resultJson.put("data", data);
- return resultJson;
- }
- };
-
- new MockUp<AdapterResourceManager>() {
-
- @Mock
- public JSONObject readScaleInVmIdFromJson() {
- JSONObject resultJson = new JSONObject();
- JSONArray vm_list = new JSONArray();
- resultJson.put("vm_list", vm_list);
- return resultJson;
- }
- };
+// new MockUp<ResultRequestUtil>() {
+//
+// @Mock
+// public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
+// JSONObject resultJson = new JSONObject();
+// resultJson.put("retCode", Constant.HTTP_CREATED);
+// JSONObject appInfo = new JSONObject();
+// appInfo.put("vnfinstanceid", "id");
+// appInfo.put("project_id", "project_id");
+// JSONObject data = new JSONObject();
+// data.put("app_info", appInfo);
+// resultJson.put("data", data);
+// return resultJson;
+// }
+// };
+//
+// new MockUp<AdapterResourceManager>() {
+//
+// @Mock
+// public JSONObject readScaleInVmIdFromJson() {
+// JSONObject resultJson = new JSONObject();
+// JSONArray vm_list = new JSONArray();
+// resultJson.put("vm_list", vm_list);
+// return resultJson;
+// }
+// };
String data = "{\"type\":\"SCALE_IN\"}}";
JSONObject subJsonObject = JSONObject.fromObject(data);
JSONObject vnfmObjcet = new JSONObject();
@@ -344,4 +343,95 @@ public class VnfMgrVnfmTest {
assertEquals(Constant.REST_SUCCESS, result.get("retCode"));
}
+
+
+ @Test
+ public void getVduType() throws Exception {
+ JSONObject vnfmObject = new JSONObject();
+ JSONObject queryResult = new JSONObject();
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ Method m = VnfMgrVnfm.class.getDeclaredMethod("getVduType", new Class[] { JSONObject.class, JSONObject.class });
+ m.setAccessible(true);
+ m.invoke(vnfMgrVnfm, vnfmObject, queryResult);
+ }
+
+ @Test
+ public void getScaleTypeScaleOut() throws Exception {
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ Method m = VnfMgrVnfm.class.getDeclaredMethod("getScaleType", new Class[] { String.class });
+ m.setAccessible(true);
+ m.invoke(vnfMgrVnfm, "SCALE_OUT");
+
+ }
+
+ @Test
+ public void getScaleType() throws Exception {
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ Method m = VnfMgrVnfm.class.getDeclaredMethod("getScaleType", new Class[] { String.class });
+ m.setAccessible(true);
+ m.invoke(vnfMgrVnfm, "SCALE_IN");
+
+ }
+
+ @Test
+ public void getScaleTypeNoMatch() throws Exception {
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ Method m = VnfMgrVnfm.class.getDeclaredMethod("getScaleType", new Class[] { String.class });
+ m.setAccessible(true);
+ m.invoke(vnfMgrVnfm, "getScaleType");
+
+ }
+
+ @Test
+ public void handleResponseWithJobId() throws Exception {
+ JSONObject result = new JSONObject();
+ JSONObject returnObj = new JSONObject();
+ returnObj.put("job_id", "job_id");
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ Method m = VnfMgrVnfm.class.getDeclaredMethod("handleResponse",
+ new Class[] { JSONObject.class, JSONObject.class, String.class, String.class });
+ m.setAccessible(true);
+ m.invoke(vnfMgrVnfm, result, returnObj, "vnfInstanceId", "type");
+
+ }
+
+ @Test
+ public void handleResponse() throws Exception {
+ JSONObject result = new JSONObject();
+ JSONObject returnObj = new JSONObject();
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ Method m = VnfMgrVnfm.class.getDeclaredMethod("handleResponse",
+ new Class[] { JSONObject.class, JSONObject.class, String.class, String.class });
+ m.setAccessible(true);
+ m.invoke(vnfMgrVnfm, result, returnObj, "vnfInstanceId", "type");
+
+ }
+
+
+ @Test
+ public void getNativeVmId() throws Exception {
+ JSONObject returnObj = new JSONObject();
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ Method m = VnfMgrVnfm.class.getDeclaredMethod("getNativeVmId",
+ new Class[] {String.class , JSONObject.class, String.class, });
+ m.setAccessible(true);
+ m.invoke(vnfMgrVnfm, "vnfInstanceId", returnObj, "type");
+
+ }
+
+
+
+ @Test
+ public void healVnf() {
+ JSONObject json = new JSONObject();
+ JSONObject affectedvm = new JSONObject();
+ affectedvm.put("vmid","vmid" );
+ json.put("affectedvm",affectedvm );
+ json.put("action", "action");
+ json.put("url","url");
+ json.put(Constant.USERNAME, Constant.USERNAME);
+ json.put(Constant.PASSWORD,Constant.PASSWORD);
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ vnfMgrVnfm.healVnf(json, json, "vnfmId", "vnfInstanceId");
+ }
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/AuthMgrTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/AuthMgrTest.java
index af97c25a..88855d01 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/AuthMgrTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/AuthMgrTest.java
@@ -45,20 +45,11 @@ public class AuthMgrTest {
@Test
public void testAuthToken() {
-// new MockUp<VnfmRestfulUtil>() {
-//
-// @Mock
-// public RestfulResponse getRestResByDefault(String auth, String method, JSONObject authParams) {
-// RestfulResponse response = null;
-// return response;
-// }
-// };
AuthMgr authMgr = new AuthMgr();
- String data = "{\"auth\":{\"identity\":{\"password\":{\"user\":{\"name\":\"om_team\",\"password\":\"123\"}}}}}";
- JSONObject params = JSONObject.fromObject(data);
-
+ JSONObject params = new JSONObject();
+ params.put(Constant.USERNAME, Constant.USERNAME);
JSONObject result = authMgr.authToken(params);
- assertEquals(Constant.REST_FAIL, result.getInt("retCode"));
+ assertEquals(Constant.REST_SUCCESS, result.getInt("retCode"));
}
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgrTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgrTest.java
index bbf23670..b2a59493 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgrTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgrTest.java
@@ -20,24 +20,15 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
-import java.util.Map;
+import java.lang.reflect.Method;
import org.junit.Before;
import org.junit.Test;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.ResultRequestUtil;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmUtil;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient.ServiceException;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.adapter.impl.AdapterResourceManager;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.vnf.VnfMgrVnfm;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.dao.impl.VnfmDaoImpl;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.dao.inf.VnfmDao;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.entity.Vnfm;
-import mockit.Mock;
-import mockit.MockUp;
import net.sf.json.JSONArray;
-import net.sf.json.JSONException;
import net.sf.json.JSONObject;
public class VnfMgrTest {
@@ -158,8 +149,11 @@ public class VnfMgrTest {
String data =
"{\"vnfPackageId\": \"vnfPackageId\",\"vnfId\": \"vnfId\",\"additionalParam\":{\"parameters\":{\"input\":\"input\"}}}";
- JSONObject subJsonObject = JSONObject.fromObject(data);
+ //JSONObject subJsonObject = JSONObject.fromObject(data);
VnfMgr vnfMgr = new VnfMgr();
+ JSONObject subJsonObject = new JSONObject();
+ subJsonObject.put("vnfDescriptorId", "vnfDescriptorId");
+ subJsonObject.put("vnfPackageId", "vnfPackageId");
JSONObject result = vnfMgr.addVnf(subJsonObject, "vnfmId");
JSONObject restJson = new JSONObject();
@@ -344,14 +338,16 @@ public class VnfMgrTest {
vnfMgr.setVnfmDao(dao);
JSONObject vnfObject = new JSONObject();
vnfObject.put("retCode", Constant.REST_SUCCESS);
- vnfObject.put("vnfInstanceId", "vnfInstanceId");
+
vnfObject.put("vnfPackageId", "vnfPackageId");
+
JSONObject resObject = new JSONObject();
resObject.put("vnfdVersion", "vnfdVersion");
resObject.put("vnfdId", "vnfdId");
JSONObject data = new JSONObject();
- data.put("data", resObject);
- vnfMgr.saveVnfInfo(vnfObject, data);
+ data.put("vnfInstanceId", "vnfInstanceId");
+ vnfObject.put("data", data);
+ vnfMgr.saveVnfInfo(vnfObject, resObject);
}
@Test
@@ -496,10 +492,148 @@ public class VnfMgrTest {
"{\"vnfPackageId\": \"vnfPackageId\",\"vnfId\": \"vnfId\",\"additionalParam\":{\"parameters\":{\"input\":\"input\"}}}";
JSONObject subJsonObject = JSONObject.fromObject(data);
VnfMgr vnfMgr = new VnfMgr();
+ vnfMgr.setConfigedVduType("configedVduType");
JSONObject result = vnfMgr.scaleVNF(subJsonObject, "testId", "testId");
JSONObject restJson = new JSONObject();
restJson.put("retCode", Constant.REST_SUCCESS);
assertEquals(restJson, result);
}
+
+
+ @Test
+ public void scaleVNFObjectNull() {
+ VnfMgr vnfMgr = new VnfMgr();
+ vnfMgr.setConfigedVduType("configedVduType");
+ vnfMgr.scaleVNF(new JSONObject(), "vnfmId", "vnfInstanceId");
+ }
+
+ @Test
+ public void addVnfJSONObjectNull() {
+ VnfMgr vnfMgr = new VnfMgr();
+ assertNotNull(vnfMgr.addVnf(new JSONObject(), "vnfmId"));
+ }
+
+
+ @Test
+ public void getVnfBody() throws Exception {
+ JSONObject restJson =new JSONObject();
+ JSONObject data =new JSONObject();
+ data.put("vnf_id", "vnf_id");
+ data.put("vnf_name", "vnf_name");
+ data.put("vnf_type", "vnf_type");
+ data.put("vnfd_id", "vnfd_id");
+ data.put(Constant.STATUS, Constant.STATUS);
+ data.put(Constant.RETCODE, Constant.REST_SUCCESS);
+ restJson.put("data", new JSONObject[] {data});
+ JSONObject ipObj =new JSONObject();
+ ipObj.put("data",data);
+ ipObj.put(Constant.RETCODE, Constant.REST_SUCCESS);
+ VnfMgr vnfMgr = new VnfMgr();
+ Method m = VnfMgr.class.getDeclaredMethod("getVnfBody",new Class[] {JSONObject.class,JSONObject.class});
+ m.setAccessible(true);
+ assertNotNull(m.invoke(vnfMgr, restJson,ipObj));
+
+ }
+
+ @Test
+ public void getVnfBodyJSONException() throws Exception {
+ JSONObject restJson =new JSONObject();
+ JSONObject ipObj =new JSONObject();
+ VnfMgr vnfMgr = new VnfMgr();
+ Method m = VnfMgr.class.getDeclaredMethod("getVnfBody",new Class[] {JSONObject.class,JSONObject.class});
+ m.setAccessible(true);
+ assertNotNull( m.invoke(vnfMgr, restJson,ipObj));
+
+ }
+
+ @Test
+ public void getVnfBodyIndexOutOfBoundsException() throws Exception {
+ JSONObject restJson =new JSONObject();
+ restJson.put("data", new JSONObject[] {});
+ JSONObject ipObj =new JSONObject();
+ VnfMgr vnfMgr = new VnfMgr();
+ Method m = VnfMgr.class.getDeclaredMethod("getVnfBody",new Class[] {JSONObject.class,JSONObject.class});
+ m.setAccessible(true);
+ assertNotNull(m.invoke(vnfMgr, restJson,ipObj));
+ }
+
+ @Test
+ public void transferVnfBody() throws Exception {
+ JSONObject vnfObject =new JSONObject();
+ vnfObject.put("vnfInstanceName", "vnfInstanceName");
+ JSONObject ipObj =new JSONObject();
+ ipObj.put(Constant.VNFDID, Constant.VNFDID);
+ ipObj.put("planId", "planId");
+ ipObj.put("emsUuid", "emsUuid");
+ VnfMgr vnfMgr = new VnfMgr();
+ Method m = VnfMgr.class.getDeclaredMethod("transferVnfBody",new Class[] {JSONObject.class,JSONObject.class,String.class});
+ m.setAccessible(true);
+ assertNotNull(m.invoke(vnfMgr, vnfObject,ipObj,"vnfmId"));
+ }
+
+ @Test
+ public void transferToLcm() {
+ JSONObject restJson = new JSONObject();
+ JSONObject data = new JSONObject();
+ JSONObject jobInfo = new JSONObject();
+ jobInfo.put("job_id", "job_id");
+ jobInfo.put("task_progress_rate", "1");
+ jobInfo.put("task_status", "Successfully");
+ jobInfo.put("error_code", "error_code");
+ data.put("job_info", jobInfo);
+ restJson.put("data",data);
+ VnfMgr vnfMgr = new VnfMgr();
+ assertNotNull(vnfMgr.transferToLcm(restJson));
+ }
+
+ @Test
+ public void transferToLcmFailed() {
+ JSONObject restJson = new JSONObject();
+ JSONObject data = new JSONObject();
+ JSONObject jobInfo = new JSONObject();
+ jobInfo.put("job_id", "job_id");
+ jobInfo.put("task_progress_rate", "1");
+ jobInfo.put("task_status", "Failed");
+ jobInfo.put("error_code", "error_code");
+ data.put("job_info", jobInfo);
+ restJson.put("data",data);
+ VnfMgr vnfMgr = new VnfMgr();
+ assertNotNull(vnfMgr.transferToLcm(restJson));
+ }
+
+ @Test
+ public void getVmsFromVnfm() {
+ VnfMgr vnfMgr = new VnfMgr();
+ assertNotNull(vnfMgr.getVmsFromVnfm("vnfmId", "vnfInstanceId"));
+ }
+
+ @Test
+ public void getVmsFromVnfmVnfInstanceId() {
+ VnfMgr vnfMgr = new VnfMgr();
+ assertNotNull(vnfMgr.getVmsFromVnfm("vnfmId", null));
+ }
+
+ @Test
+ public void getJobFromVnfm() {
+ VnfMgr vnfMgr = new VnfMgr();
+ vnfMgr.getJobFromVnfm("jobId", "vnfmId");
+ }
+
+
+ @Test
+ public void healVnfNullObject() {
+ VnfMgr vnfMgr = new VnfMgr();
+ JSONObject jsonObject = new JSONObject();
+ vnfMgr.healVnf(jsonObject, "vnfInstanceId", "vnfmId");
+ }
+
+ @Test
+ public void healVnf() {
+ VnfMgr vnfMgr = new VnfMgr();
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("id", "id");
+ vnfMgr.healVnf(jsonObject, "vnfInstanceId", "vnfmId");
+ }
+
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/AuthRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/AuthRoaTest.java
index 2369b02a..96ac5a6a 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/AuthRoaTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/AuthRoaTest.java
@@ -19,20 +19,24 @@ package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.io.IOException;
+
+import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmJsonUtil;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.AuthMgr;
-import mockit.Mock;
import mockit.MockUp;
import net.sf.json.JSONObject;
-
+@RunWith(MockitoJUnitRunner.class)
public class AuthRoaTest {
private AuthRoa authRoa;
@@ -45,7 +49,16 @@ public class AuthRoaTest {
authMgr = new AuthMgr();
authRoa.setAuthMgr(authMgr);
}
-
+
+ @Mock
+ HttpServletRequest context;
+
+ @Mock
+ HttpServletResponse resp;
+
+ @Mock
+ ServletInputStream servletInputStream;
+
@After
public void tearDown() {
authRoa = null;
@@ -56,13 +69,13 @@ public class AuthRoaTest {
public void testAuthTokenBySubJsonObjectNull() {
MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
HttpServletRequest mockInstance = proxyStub.getMockInstance();
- new MockUp<VnfmJsonUtil>() {
-
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest context) {
- return null;
- }
- };
+// new MockUp<VnfmJsonUtil>() {
+//
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest context) {
+// return null;
+// }
+// };
MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
@@ -80,25 +93,25 @@ public class AuthRoaTest {
MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest context) {
- JSONObject subJsonObject = new JSONObject();
- return (T)subJsonObject;
- }
- };
- new MockUp<AuthMgr>() {
-
- @Mock
- public JSONObject authToken(JSONObject params) {
- JSONObject restJson = new JSONObject();
- restJson.put("retCode", Constant.REST_FAIL);
- restJson.put("data", "Fail!");
- return restJson;
- }
- };
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest context) {
+// JSONObject subJsonObject = new JSONObject();
+// return (T)subJsonObject;
+// }
+// };
+// new MockUp<AuthMgr>() {
+//
+// @Mock
+// public JSONObject authToken(JSONObject params) {
+// JSONObject restJson = new JSONObject();
+// restJson.put("retCode", Constant.REST_FAIL);
+// restJson.put("data", "Fail!");
+// return restJson;
+// }
+// };
String result = authRoa.authToken(mockInstance, mockResInstance);
assertEquals("{\"Information\": \"Fail!\"}", result);
@@ -112,72 +125,73 @@ public class AuthRoaTest {
MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest context) {
- JSONObject subJsonObject = new JSONObject();
- return (T)subJsonObject;
- }
- };
- new MockUp<AuthMgr>() {
-
- @Mock
- public JSONObject authToken(JSONObject params) {
- JSONObject restJson = new JSONObject();
- restJson.put("retCode", Constant.HTTP_INNERERROR);
- restJson.put("data", "HttpInnerError!");
- return restJson;
- }
- };
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest context) {
+// JSONObject subJsonObject = new JSONObject();
+// return (T)subJsonObject;
+// }
+// };
+// new MockUp<AuthMgr>() {
+//
+// @Mock
+// public JSONObject authToken(JSONObject params) {
+// JSONObject restJson = new JSONObject();
+// restJson.put("retCode", Constant.HTTP_INNERERROR);
+// restJson.put("data", "HttpInnerError!");
+// return restJson;
+// }
+// };
String result = authRoa.authToken(mockInstance, mockResInstance);
assertEquals("{\"Information\": \"HttpInnerError!\"}", result);
}
@Test
- public void testAuthToken() {
- MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
- HttpServletRequest mockInstance = proxyStub.getMockInstance();
-
- MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
- HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest context) {
- JSONObject subJsonObject = new JSONObject();
- return (T)subJsonObject;
- }
- };
- new MockUp<AuthMgr>() {
-
- @Mock
- public JSONObject authToken(JSONObject params) {
- JSONObject restJson = new JSONObject();
- restJson.put("retCode", Constant.REST_SUCCESS);
- JSONObject data = new JSONObject();
- data.put("accessSession", "accessSession");
- data.put("userName", "userName");
- data.put("roaRand", "roaRand");
- restJson.put("data", data);
- return restJson;
- }
- };
- String result = authRoa.authToken(mockInstance, mockResInstance);
+ public void testAuthToken() throws Exception {
+// MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+// HttpServletRequest mockInstance = proxyStub.getMockInstance();
+//
+// MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+// HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest context) {
+// JSONObject subJsonObject = new JSONObject();
+// return (T)subJsonObject;
+// }
+// };
+// new MockUp<AuthMgr>() {
+//
+// @Mock
+// public JSONObject authToken(JSONObject params) {
+// JSONObject restJson = new JSONObject();
+// restJson.put("retCode", Constant.REST_SUCCESS);
+// JSONObject data = new JSONObject();
+// data.put("accessSession", "accessSession");
+// data.put("userName", "userName");
+// data.put("roaRand", "roaRand");
+// restJson.put("data", data);
+// return restJson;
+// }
+// };
+ Mockito.when(context.getInputStream()).thenReturn(servletInputStream);
+ String result = authRoa.authToken(context, resp);
assertNotNull(result);
}
@Test
public void testDelAuthToken() {
- MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
-
- MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
- HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
- String result = authRoa.delAuthToken(null, null, mockResInstance);
+// MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+//
+// MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+// HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+ String result = authRoa.delAuthToken(null, null, resp);
JSONObject resultJson = new JSONObject();
resultJson.put("Information", "Operation success");
@@ -186,15 +200,20 @@ public class AuthRoaTest {
@Test
public void testShakehand() {
- MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
-
- MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
- HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
- String result = authRoa.shakehand(null, mockResInstance);
+ String result = authRoa.shakehand("roattr", resp);
JSONObject resultJson = new JSONObject();
resultJson.put("status", "running");
resultJson.put("description", "Operation success");
assertEquals(resultJson.toString(), result);
}
+
+ @Test
+ public void testShakehandOld() {
+ String result = authRoa.shakehandOld("roattr", resp);
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("status", "running");
+ resultJson.put("description", "Operation success");
+ assertEquals(resultJson.toString(), result);
+ }
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfAdapterResourceRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfAdapterResourceRoaTest.java
index 58c584d8..db2a3943 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfAdapterResourceRoaTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfAdapterResourceRoaTest.java
@@ -37,16 +37,16 @@ public class VnfAdapterResourceRoaTest {
@Test
public void testGetAllCloudInfo() {
- new MockUp<AdapterResourceManager>() {
-
- @Mock
- public JSONObject getAllCloud(String url, String conntoken) {
- JSONObject resultObj = new JSONObject();
- resultObj.put("dn", "test");
- resultObj.put("vim_id", "12345");
- return resultObj;
- }
- };
+// new MockUp<AdapterResourceManager>() {
+//
+// @Mock
+// public JSONObject getAllCloud(String url, String conntoken) {
+// JSONObject resultObj = new JSONObject();
+// resultObj.put("dn", "test");
+// resultObj.put("vim_id", "12345");
+// return resultObj;
+// }
+// };
VnfAdapterResourceRoa vnfAdapter = new VnfAdapterResourceRoa();
String result = vnfAdapter.getAllCloudInfo();
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfResourceRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfResourceRoaTest.java
index ddf6e44d..50c06268 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfResourceRoaTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfResourceRoaTest.java
@@ -19,26 +19,34 @@ package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
+import java.lang.reflect.Method;
+import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmJsonUtil;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmUtil;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.VnfResourceMgr;
-import mockit.Mock;
-import mockit.MockUp;
import net.sf.json.JSONObject;
-
+@RunWith(MockitoJUnitRunner.class)
public class VnfResourceRoaTest {
private VnfResourceRoa vnfResourceRoa;
private VnfResourceMgr vnfResourceMgr;
+
+ @Mock
+ HttpServletRequest context;
+
+ @Mock
+ ServletInputStream servletInputStream;
@Before
public void setUp() {
@@ -54,19 +62,9 @@ public class VnfResourceRoaTest {
}
@Test
- public void testGrantVnfResByDataObjectNull() {
- MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
- HttpServletRequest mockInstance = proxyStub.getMockInstance();
- new MockUp<VnfmJsonUtil>() {
-
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest context) {
- return null;
- }
- };
-
- String result = vnfResourceRoa.grantVnfRes(mockInstance, "vnfId");
-
+ public void testGrantVnfResByDataObjectNull() throws Exception {
+ Mockito.when(context.getInputStream()).thenReturn(servletInputStream);
+ String result = vnfResourceRoa.grantVnfRes(context, "vnfId");
JSONObject restJson = new JSONObject();
restJson.put("retCode", Constant.REST_FAIL);
restJson.put("data", "Params error");
@@ -75,29 +73,29 @@ public class VnfResourceRoaTest {
@Test
public void testGrantVnfResByGrantObjNull() {
- MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
- HttpServletRequest mockInstance = proxyStub.getMockInstance();
+ // MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ // HttpServletRequest mockInstance = proxyStub.getMockInstance();
final JSONObject dataObject = new JSONObject();
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest context) {
- return (T)dataObject;
- }
- };
- new MockUp<JSONObject>() {
-
- @Mock
- public JSONObject getJSONObject(String key) {
- if(key == "grant") {
- return null;
- }
- return dataObject;
- }
- };
-
- String result = vnfResourceRoa.grantVnfRes(mockInstance, "vnfId");
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest context) {
+// return (T)dataObject;
+// }
+// };
+// new MockUp<JSONObject>() {
+//
+// @Mock
+// public JSONObject getJSONObject(String key) {
+// if(key == "grant") {
+// return null;
+// }
+// return dataObject;
+// }
+// };
+
+ String result = vnfResourceRoa.grantVnfRes(null, "vnfId");
JSONObject restJson = new JSONObject();
restJson.put("retCode", Constant.REST_FAIL);
@@ -107,47 +105,47 @@ public class VnfResourceRoaTest {
@Test
public void testGrantVnfRes() {
- MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {
-
- @Mock
- public String getHeader(String name) {
- return "127.0.0.1";
- }
- };
- HttpServletRequest mockInstance = proxyStub.getMockInstance();
+// MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {
+//
+// @Mock
+// public String getHeader(String name) {
+// return "127.0.0.1";
+// }
+// };
+// HttpServletRequest mockInstance = proxyStub.getMockInstance();
final JSONObject dataObject = new JSONObject();
JSONObject grant = new JSONObject();
grant.put("project_id", "project_id");
dataObject.put("grant", grant);
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest context) {
- return (T)dataObject;
- }
- };
- new MockUp<VnfmUtil>() {
-
- @Mock
- public String getVnfmIdByIp(String ip) {
- return "vnfmId";
- }
- };
-
- new MockUp<VnfResourceMgr>() {
-
- @Mock
- public JSONObject grantVnfResource(JSONObject vnfObj, String vnfId, String vnfmId) {
- JSONObject resultJson = new JSONObject();
- resultJson.put("retCode", Constant.REST_SUCCESS);
- JSONObject data = new JSONObject();
- data.put("data", "success");
- resultJson.put("data", data);
- return resultJson;
- }
- };
- String result = vnfResourceRoa.grantVnfRes(mockInstance, "vnfId");
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest context) {
+// return (T)dataObject;
+// }
+// };
+// new MockUp<VnfmUtil>() {
+//
+// @Mock
+// public String getVnfmIdByIp(String ip) {
+// return "vnfmId";
+// }
+// };
+//
+// new MockUp<VnfResourceMgr>() {
+//
+// @Mock
+// public JSONObject grantVnfResource(JSONObject vnfObj, String vnfId, String vnfmId) {
+// JSONObject resultJson = new JSONObject();
+// resultJson.put("retCode", Constant.REST_SUCCESS);
+// JSONObject data = new JSONObject();
+// data.put("data", "success");
+// resultJson.put("data", data);
+// return resultJson;
+// }
+// };
+ String result = vnfResourceRoa.grantVnfRes(null, "vnfId");
JSONObject restJson = new JSONObject();
restJson.put("retCode", Constant.REST_SUCCESS);
@@ -159,45 +157,46 @@ public class VnfResourceRoaTest {
@Test
public void testGrantVnfResByFail() {
- MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {
-
- @Mock
- public String getHeader(String name) {
- return "127.0.0.1";
- }
- };
- HttpServletRequest mockInstance = proxyStub.getMockInstance();
+// MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {
+//
+// @Mock
+// public String getHeader(String name) {
+// return "127.0.0.1";
+// }
+// };
+ // HttpServletRequest mockInstance = proxyStub.getMockInstance();
final JSONObject dataObject = new JSONObject();
JSONObject grant = new JSONObject();
grant.put("project_id", "project_id");
dataObject.put("grant", grant);
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest context) {
- return (T)dataObject;
- }
- };
- new MockUp<VnfmUtil>() {
-
- @Mock
- public String getVnfmIdByIp(String ip) {
- return "vnfmId";
- }
- };
-
- new MockUp<VnfResourceMgr>() {
-
- @Mock
- public JSONObject grantVnfResource(JSONObject vnfObj, String vnfId, String vnfmId) {
- JSONObject resultJson = new JSONObject();
- resultJson.put("retCode", Constant.REST_FAIL);
- resultJson.put("data", "Fail!");
- return resultJson;
- }
- };
- String result = vnfResourceRoa.grantVnfRes(mockInstance, "vnfId");
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest context) {
+// return (T)dataObject;
+// }
+// };
+// new MockUp<VnfmUtil>() {
+//
+// @Mock
+// public String getVnfmIdByIp(String ip) {
+// return "vnfmId";
+// }
+// };
+//
+// new MockUp<VnfResourceMgr>() {
+//
+// @Mock
+// public JSONObject grantVnfResource(JSONObject vnfObj, String vnfId, String vnfmId) {
+// JSONObject resultJson = new JSONObject();
+// resultJson.put("retCode", Constant.REST_FAIL);
+// resultJson.put("data", "Fail!");
+// return resultJson;
+// }
+// };
+
+ String result = vnfResourceRoa.grantVnfRes(null, "vnfId");
JSONObject restJson = new JSONObject();
restJson.put("retCode", Constant.REST_FAIL);
@@ -207,44 +206,37 @@ public class VnfResourceRoaTest {
@Test
public void testGrantVnfResByDataNull() {
- MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {
-
- @Mock
- public String getHeader(String name) {
- return "127.0.0.1";
- }
- };
- HttpServletRequest mockInstance = proxyStub.getMockInstance();
+ //HttpServletRequest mockInstance = proxyStub.getMockInstance();
final JSONObject dataObject = new JSONObject();
JSONObject grant = new JSONObject();
grant.put("project_id", "project_id");
dataObject.put("grant", grant);
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest context) {
- return (T)dataObject;
- }
- };
- new MockUp<VnfmUtil>() {
-
- @Mock
- public String getVnfmIdByIp(String ip) {
- return "vnfmId";
- }
- };
-
- new MockUp<VnfResourceMgr>() {
-
- @Mock
- public JSONObject grantVnfResource(JSONObject vnfObj, String vnfId, String vnfmId) {
- JSONObject resultJson = new JSONObject();
- resultJson.put("retCode", Constant.REST_FAIL);
- return resultJson;
- }
- };
- String result = vnfResourceRoa.grantVnfRes(mockInstance, "vnfId");
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest context) {
+// return (T)dataObject;
+// }
+// };
+// new MockUp<VnfmUtil>() {
+//
+// @Mock
+// public String getVnfmIdByIp(String ip) {
+// return "vnfmId";
+// }
+// };
+//
+// new MockUp<VnfResourceMgr>() {
+//
+// @Mock
+// public JSONObject grantVnfResource(JSONObject vnfObj, String vnfId, String vnfmId) {
+// JSONObject resultJson = new JSONObject();
+// resultJson.put("retCode", Constant.REST_FAIL);
+// return resultJson;
+// }
+// };
+ String result = vnfResourceRoa.grantVnfRes(null, "vnfId");
JSONObject restJson = new JSONObject();
restJson.put("retCode", Constant.REST_FAIL);
@@ -253,18 +245,31 @@ public class VnfResourceRoaTest {
@Test
public void testNotify() throws IOException {
- MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {
-
- @Mock
- public String getHeader(String name) {
- return "127.0.0.1";
- }
- };
- HttpServletRequest mockInstance = proxyStub.getMockInstance();
- String result = vnfResourceRoa.notify(mockInstance);
+// MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {
+//
+// @Mock
+// public String getHeader(String name) {
+// return "127.0.0.1";
+// }
+// };
+// HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ Mockito.when(context.getInputStream()).thenReturn(servletInputStream);
+ String result = vnfResourceRoa.notify(context);
JSONObject restJson = new JSONObject();
restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
assertNotNull(result);
}
+
+
+ @Test
+ public void callLcmNotify() throws Exception{
+ VnfResourceRoa vnfRoa = new VnfResourceRoa();
+ JSONObject json = new JSONObject();
+ Method m = VnfResourceRoa.class.getDeclaredMethod("callLcmNotify", new Class[] {JSONObject.class});
+ m.setAccessible(true);
+ m.invoke(vnfRoa, json);
+
+ }
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java
index b13b4096..d98ef421 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java
@@ -20,29 +20,44 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
+import java.lang.reflect.Method;
+import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmJsonUtil;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmUtil;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient.ServiceException;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.VnfMgr;
-import mockit.Mock;
import mockit.MockUp;
-import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
-
+@RunWith(MockitoJUnitRunner.class)
public class VnfRoaTest {
private VnfRoa vnfRoa;
private VnfMgr vnfMgr;
+
+ @Mock
+ HttpServletRequest context;
+
+ @Mock
+ HttpServletResponse resp;
+
+ @Mock
+ ServletInputStream servletInputStream;
+
+ @Mock
+ VnfMgr vnfMgr1;
@Before
public void setUp() {
@@ -58,36 +73,35 @@ public class VnfRoaTest {
}
@Test
- public void testAddVnf() throws ServiceException {
+ public void testAddVnf() throws ServiceException, IOException {
final JSONObject restJson = new JSONObject();
restJson.put("retCode", Constant.REST_SUCCESS);
- MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
- HttpServletRequest mockInstance = proxyStub.getMockInstance();
-
- MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
- HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
-
- new MockUp<VnfMgr>() {
-
- @Mock
- public JSONObject addVnf(JSONObject subJsonObject, String vnfmId) {
- JSONObject retJson = new JSONObject();
- retJson.put("id", "123");
- restJson.put("data", retJson);
- return restJson;
- }
- };
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
- return (T)restJson;
- }
- };
-
- String result = vnfRoa.addVnf(mockInstance, mockResInstance, "vnfmId");
-
+// MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+// HttpServletRequest mockInstance = proxyStub.getMockInstance();
+//
+// MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+// HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+// new MockUp<VnfMgr>() {
+//
+// @Mock
+// public JSONObject addVnf(JSONObject subJsonObject, String vnfmId) {
+// JSONObject retJson = new JSONObject();
+// retJson.put("id", "123");
+// restJson.put("data", retJson);
+// return restJson;
+// }
+// };
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+// return (T)restJson;
+// }
+// };
+ Mockito.when(context.getInputStream()).thenReturn(servletInputStream);
+ String result = vnfRoa.addVnf(context, resp, "vnfmId");
JSONObject retJson = new JSONObject();
retJson.put("id", "123");
assertEquals(retJson.toString(), result);
@@ -104,21 +118,21 @@ public class VnfRoaTest {
MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
- new MockUp<VnfMgr>() {
-
- @Mock
- public JSONObject addVnf(JSONObject subJsonObject, String vnfmId) {
- return restJson;
- }
- };
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
- return (T)restJson;
- }
- };
+// new MockUp<VnfMgr>() {
+//
+// @Mock
+// public JSONObject addVnf(JSONObject subJsonObject, String vnfmId) {
+// return restJson;
+// }
+// };
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+// return (T)restJson;
+// }
+// };
String result = vnfRoa.addVnf(mockInstance, mockResInstance, "vnfmId");
@@ -135,13 +149,13 @@ public class VnfRoaTest {
MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
- new MockUp<VnfmJsonUtil>() {
-
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest context) {
- return null;
- }
- };
+// new MockUp<VnfmJsonUtil>() {
+//
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest context) {
+// return null;
+// }
+// };
String result = vnfRoa.addVnf(mockInstance, mockResInstance, "vnfmId");
@@ -150,36 +164,36 @@ public class VnfRoaTest {
}
@Test
- public void testDelVnf() throws ServiceException {
+ public void testDelVnf() throws ServiceException, IOException {
final JSONObject restJson = new JSONObject();
restJson.put("retCode", Constant.REST_SUCCESS);
- MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
- HttpServletRequest mockInstance = proxyStub.getMockInstance();
-
- MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
- HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
-
- new MockUp<VnfMgr>() {
-
- @Mock
- public JSONObject deleteVnf(String vnfId, String vnfmId, JSONObject vnfObject) {
- JSONObject retJson = new JSONObject();
- retJson.put("id", "123");
- restJson.put("data", retJson);
- return restJson;
- }
- };
-
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
- return (T)restJson;
- }
- };
-
- String result = vnfRoa.delVnf("vnfmId", mockResInstance, "vnfId", mockInstance);
+// MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+// HttpServletRequest mockInstance = proxyStub.getMockInstance();
+//
+// MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+// HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+// new MockUp<VnfMgr>() {
+//
+// @Mock
+// public JSONObject deleteVnf(String vnfId, String vnfmId, JSONObject vnfObject) {
+// JSONObject retJson = new JSONObject();
+// retJson.put("id", "123");
+// restJson.put("data", retJson);
+// return restJson;
+// }
+// };
+
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+// return (T)restJson;
+// }
+// };
+ Mockito.when(context.getInputStream()).thenReturn(servletInputStream);
+ String result = vnfRoa.delVnf("vnfmId", resp, "vnfId", context);
JSONObject retJson = new JSONObject();
retJson.put("id", "123");
assertEquals(retJson.toString(), result);
@@ -194,14 +208,14 @@ public class VnfRoaTest {
MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
- return (T)restJson;
- }
- };
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+// return (T)restJson;
+// }
+// };
String result = vnfRoa.delVnf("vnfmId", mockResInstance, "", mockInstance);
@@ -217,14 +231,14 @@ public class VnfRoaTest {
MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
- return (T)restJson;
- }
- };
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+// return (T)restJson;
+// }
+// };
String result = vnfRoa.delVnf("", mockResInstance, "vnfId", mockInstance);
@@ -240,14 +254,14 @@ public class VnfRoaTest {
MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
- return (T)restJson;
- }
- };
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+// return (T)restJson;
+// }
+// };
String result = vnfRoa.delVnf("", mockResInstance, "", mockInstance);
@@ -264,22 +278,22 @@ public class VnfRoaTest {
MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
- new MockUp<VnfMgr>() {
-
- @Mock
- public JSONObject deleteVnf(String vnfId, String vnfmId, JSONObject vnfObject) {
- return restJson;
- }
- };
-
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
- return (T)restJson;
- }
- };
+// new MockUp<VnfMgr>() {
+//
+// @Mock
+// public JSONObject deleteVnf(String vnfId, String vnfmId, JSONObject vnfObject) {
+// return restJson;
+// }
+// };
+//
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+// return (T)restJson;
+// }
+// };
String result = vnfRoa.delVnf("vnfmId", mockResInstance, "vnfId", mockInstance);
assertEquals(restJson.toString(), result);
@@ -294,14 +308,14 @@ public class VnfRoaTest {
MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
- return (T)restJson;
- }
- };
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+// return (T)restJson;
+// }
+// };
String result = vnfRoa.getVnf("vnfmId", mockResInstance, "");
@@ -317,14 +331,14 @@ public class VnfRoaTest {
MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
- return (T)restJson;
- }
- };
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+// return (T)restJson;
+// }
+// };
String result = vnfRoa.getVnf("", mockResInstance, "vnfId");
@@ -341,22 +355,22 @@ public class VnfRoaTest {
MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
- new MockUp<VnfMgr>() {
-
- @Mock
- public JSONObject getVnf(String vnfId, String vnfmId) {
- return restJson;
- }
- };
-
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
- return (T)restJson;
- }
- };
+// new MockUp<VnfMgr>() {
+//
+// @Mock
+// public JSONObject getVnf(String vnfId, String vnfmId) {
+// return restJson;
+// }
+// };
+//
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+// return (T)restJson;
+// }
+// };
String result = vnfRoa.getVnf("vnfmId", mockResInstance, "vnfId");
assertEquals(restJson.toString(), result);
@@ -372,35 +386,35 @@ public class VnfRoaTest {
MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
- new MockUp<VnfMgr>() {
-
- @Mock
- public JSONObject getVnf(String vnfId, String vnfmId) {
- JSONObject retJson = new JSONObject();
- JSONObject basicInfoJson = new JSONObject();
- basicInfoJson.put("vnfInstanceId", "123");
- basicInfoJson.put("vnfInstanceName", "1");
- basicInfoJson.put("vnfInstanceDescription", "vFW");
- basicInfoJson.put("vnfdId", "1");
- basicInfoJson.put("vnfdPackageId", "vFW");
- basicInfoJson.put("version", "vFW");
- basicInfoJson.put("vnfProvider", "hw");
- basicInfoJson.put("vnfType", "fw");
- basicInfoJson.put("vnfStatus", "active");
- retJson.put("vnfInfo", basicInfoJson);
- retJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
- return retJson;
- }
- };
-
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
- return (T)restJson;
- }
- };
+// new MockUp<VnfMgr>() {
+//
+// @Mock
+// public JSONObject getVnf(String vnfId, String vnfmId) {
+// JSONObject retJson = new JSONObject();
+// JSONObject basicInfoJson = new JSONObject();
+// basicInfoJson.put("vnfInstanceId", "123");
+// basicInfoJson.put("vnfInstanceName", "1");
+// basicInfoJson.put("vnfInstanceDescription", "vFW");
+// basicInfoJson.put("vnfdId", "1");
+// basicInfoJson.put("vnfdPackageId", "vFW");
+// basicInfoJson.put("version", "vFW");
+// basicInfoJson.put("vnfProvider", "hw");
+// basicInfoJson.put("vnfType", "fw");
+// basicInfoJson.put("vnfStatus", "active");
+// retJson.put("vnfInfo", basicInfoJson);
+// retJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
+// return retJson;
+// }
+// };
+
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+// return (T)restJson;
+// }
+// };
String result = vnfRoa.getVnf("vnfmId", mockResInstance, "vnfId");
JSONObject basicInfoJson = new JSONObject();
@@ -440,105 +454,107 @@ public class VnfRoaTest {
public void testGetJobByVnfMgrFail() throws ServiceException {
MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
- new MockUp<VnfMgr>() {
-
- @Mock
- public JSONObject getJob(String jobId, String vnfmId) {
- JSONObject restJson = new JSONObject();
- restJson.put(Constant.RETCODE, Constant.REST_FAIL);
- return restJson;
- }
- };
+// new MockUp<VnfMgr>() {
+//
+// @Mock
+// public JSONObject getJob(String jobId, String vnfmId) {
+// JSONObject restJson = new JSONObject();
+// restJson.put(Constant.RETCODE, Constant.REST_FAIL);
+// return restJson;
+// }
+// };
String result = vnfRoa.getJob("123", "1234", mockResInstance, "1111");
assertEquals("{\"retCode\":-1}", result);
}
@Test
public void testGetJob() throws ServiceException {
- new MockUp<VnfMgr>() {
-
- @Mock
- public JSONObject getJob(String jobId, String vnfmId) {
- JSONObject restJson = new JSONObject();
- JSONArray data = new JSONArray();
- JSONObject obj = new JSONObject();
- obj.put("id", "11111");
- obj.put("status", "Active");
- data.add(obj);
- restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
- restJson.put("data", data);
- return restJson;
- }
- };
+// new MockUp<VnfMgr>() {
+//
+// @Mock
+// public JSONObject getJob(String jobId, String vnfmId) {
+// JSONObject restJson = new JSONObject();
+// JSONArray data = new JSONArray();
+// JSONObject obj = new JSONObject();
+// obj.put("id", "11111");
+// obj.put("status", "Active");
+// data.add(obj);
+// restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
+// restJson.put("data", data);
+// return restJson;
+// }
+// };
String result = vnfRoa.getJob("123", "1234", null, "1111");
assertNotNull(result);
}
@Test
- public void testHealVnf() throws ServiceException {
+ public void testHealVnf() throws ServiceException, IOException {
final JSONObject restJson = new JSONObject();
restJson.put("retCode", Constant.REST_SUCCESS);
- MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
- HttpServletRequest mockInstance = proxyStub.getMockInstance();
-
- MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
- HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
-
- new MockUp<VnfMgr>() {
-
- @Mock
- public JSONObject healVnf(JSONObject jsonObject, String vnfInstanceId, String vnfmId) {
- JSONObject retJson = new JSONObject();
- retJson.put("id", "123");
- restJson.put("data", retJson);
- return restJson;
- }
- };
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
- return (T)restJson;
- }
- };
-
- String result = vnfRoa.healVnf(mockInstance, mockResInstance, "id", "id");
+// MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+// HttpServletRequest mockInstance = proxyStub.getMockInstance();
+//
+// MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+// HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+// new MockUp<VnfMgr>() {
+//
+// @Mock
+// public JSONObject healVnf(JSONObject jsonObject, String vnfInstanceId, String vnfmId) {
+// JSONObject retJson = new JSONObject();
+// retJson.put("id", "123");
+// restJson.put("data", retJson);
+// return restJson;
+// }
+// };
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+// return (T)restJson;
+// }
+// };
+ Mockito.when(context.getInputStream()).thenReturn(servletInputStream);
+
+ String result = vnfRoa.healVnf(context, resp, "id", "id");
assertNotNull(result);
}
@Test
- public void testScaleVnf() throws ServiceException {
+ public void testScaleVnf() throws ServiceException, IOException {
final JSONObject restJson = new JSONObject();
restJson.put("retCode", Constant.REST_SUCCESS);
- MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
- HttpServletRequest mockInstance = proxyStub.getMockInstance();
-
- MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
- HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
-
- new MockUp<VnfMgr>() {
-
- @Mock
- public JSONObject scaleVNF(JSONObject vnfObject, String vnfmId, String vnfInstanceId) {
- JSONObject retJson = new JSONObject();
- retJson.put("id", "123");
- restJson.put("data", retJson);
- return restJson;
- }
- };
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
- return (T)restJson;
- }
- };
-
- String result = vnfRoa.scaleVnf(mockInstance, mockResInstance, "id", "id");
+// MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+// HttpServletRequest mockInstance = proxyStub.getMockInstance();
+//
+// MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+// HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+// new MockUp<VnfMgr>() {
+//
+// @Mock
+// public JSONObject scaleVNF(JSONObject vnfObject, String vnfmId, String vnfInstanceId) {
+// JSONObject retJson = new JSONObject();
+// retJson.put("id", "123");
+// restJson.put("data", retJson);
+// return restJson;
+// }
+// };
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+// return (T)restJson;
+// }
+// };
+
+ Mockito.when(context.getInputStream()).thenReturn(servletInputStream);
+ String result = vnfRoa.scaleVnf(context, resp, "id", "id");
JSONObject retJson = new JSONObject();
retJson.put("id", "123");
@@ -556,24 +572,24 @@ public class VnfRoaTest {
MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
- new MockUp<VnfMgr>() {
-
- @Mock
- public JSONObject scaleVNF(JSONObject vnfObject, String vnfmId, String vnfInstanceId) {
- JSONObject retJson = new JSONObject();
- retJson.put("id", "123");
- restJson.put("data", retJson);
- return restJson;
- }
- };
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
- return (T)restJson;
- }
- };
+// new MockUp<VnfMgr>() {
+//
+// @Mock
+// public JSONObject scaleVNF(JSONObject vnfObject, String vnfmId, String vnfInstanceId) {
+// JSONObject retJson = new JSONObject();
+// retJson.put("id", "123");
+// restJson.put("data", retJson);
+// return restJson;
+// }
+// };
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+// return (T)restJson;
+// }
+// };
String result = vnfRoa.scaleVnf(mockInstance, mockResInstance, "id", "id");
assertEquals(restJson.toString(), result);
@@ -590,24 +606,24 @@ public class VnfRoaTest {
MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
- new MockUp<VnfMgr>() {
-
- @Mock
- public JSONObject scaleVNF(JSONObject vnfObject, String vnfmId, String vnfInstanceId) {
- JSONObject retJson = new JSONObject();
- retJson.put("id", "123");
- restJson.put("data", retJson);
- return restJson;
- }
- };
- new MockUp<VnfmJsonUtil>() {
-
- @SuppressWarnings("unchecked")
- @Mock
- public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
- return null;
- }
- };
+// new MockUp<VnfMgr>() {
+//
+// @Mock
+// public JSONObject scaleVNF(JSONObject vnfObject, String vnfmId, String vnfInstanceId) {
+// JSONObject retJson = new JSONObject();
+// retJson.put("id", "123");
+// restJson.put("data", retJson);
+// return restJson;
+// }
+// };
+// new MockUp<VnfmJsonUtil>() {
+//
+// @SuppressWarnings("unchecked")
+// @Mock
+// public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+// return null;
+// }
+// };
String result = vnfRoa.scaleVnf(mockInstance, mockResInstance, "id", "id");
assertNotNull(result);
@@ -616,35 +632,35 @@ public class VnfRoaTest {
@Test
public void testGetVnfmById() throws ServiceException {
- new MockUp<VnfmUtil>() {
-
- @Mock
- public JSONObject getVnfmById(String vnfmId) {
- JSONObject json = new JSONObject();
- json.put("vnfm", "1234");
- return json;
- }
- };
+// new MockUp<VnfmUtil>() {
+//
+// @Mock
+// public JSONObject getVnfmById(String vnfmId) {
+// JSONObject json = new JSONObject();
+// json.put("vnfm", "1234");
+// return json;
+// }
+// };
String result = vnfRoa.getVnfmById("1234", null);
assertNotNull(result);
}
@Test
public void testGetJobFromVnfm() throws ServiceException {
- new MockUp<VnfMgr>() {
-
- @Mock
- public JSONObject getJobFromVnfm(String jobId, String vnfmId) {
- JSONObject json = new JSONObject();
- json.put("retCode", "1");
- return json;
- }
-
- @Mock
- public String transferToLcm(JSONObject restJson) {
- return "success";
- }
- };
+// new MockUp<VnfMgr>() {
+//
+// @Mock
+// public JSONObject getJobFromVnfm(String jobId, String vnfmId) {
+// JSONObject json = new JSONObject();
+// json.put("retCode", "1");
+// return json;
+// }
+//
+// @Mock
+// public String transferToLcm(JSONObject restJson) {
+// return "success";
+// }
+// };
String result = vnfRoa.getJobFromVnfm("jobId", "vnfmId", null, "responseId");
assertNotNull(result);
}
@@ -652,20 +668,46 @@ public class VnfRoaTest {
@Test
public void testGetJobFromVnfmFail() throws ServiceException {
- new MockUp<VnfMgr>() {
-
- @Mock
- public JSONObject getJobFromVnfm(String jobId, String vnfmId) {
- JSONObject json = new JSONObject();
- json.put("retCode", "-1");
- return json;
- }
-
- };
+// new MockUp<VnfMgr>() {
+//
+// @Mock
+// public JSONObject getJobFromVnfm(String jobId, String vnfmId) {
+// JSONObject json = new JSONObject();
+// json.put("retCode", "-1");
+// return json;
+// }
+//
+// };
MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
String result = vnfRoa.getJobFromVnfm("jobId", "vnfmId", mockResInstance, "responseId");
assertNotNull(result);
}
+
+ @Test
+ public void getHealJobBody() throws Exception {
+ VnfRoa vnfRoa = new VnfRoa();
+ Method m = VnfRoa.class.getDeclaredMethod("getHealJobBody",new Class[] {String.class});
+ m.setAccessible(true);
+ assertNotNull(m.invoke(vnfRoa, "jobId"));
+ }
+ @Test
+ public void getJobBody() throws Exception {
+ JSONObject restJson = new JSONObject();
+ JSONObject data = new JSONObject();
+ data.put(Constant.STATUS, Constant.STATUS);
+ restJson.put("data", new JSONObject[] {data});
+ VnfRoa vnfRoa = new VnfRoa();
+ Method m = VnfRoa.class.getDeclaredMethod("getJobBody",new Class[] {JSONObject.class,String.class});
+ m.setAccessible(true);
+ assertNotNull(m.invoke(vnfRoa, restJson,"jobId"));
+ }
+
+ @Test
+ public void getVms() {
+ VnfRoa vnfRoa = new VnfRoa();
+ Mockito.when(vnfMgr1.getVmsFromVnfm(Matchers.anyString(), Matchers.any())).thenReturn(new JSONObject());
+ vnfRoa.getVms("Vmf", resp);
+ }
}