summaryrefslogtreecommitdiffstats
path: root/huawei
diff options
context:
space:
mode:
Diffstat (limited to 'huawei')
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java35
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmUtilTest.java93
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java79
3 files changed, 128 insertions, 79 deletions
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java
index 3e93f2c2..8792f528 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java
@@ -16,9 +16,11 @@
package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
+import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.connect.ConnectMgrVnfm;
import mockit.Mock;
@@ -36,10 +38,15 @@ public class ResultRequestUtilTest {
return 500;
}
};
+
+
JSONObject vnfmObject = new JSONObject();
String path = "http://localhost:8080";
String methodName = "get";
String paramsJson = "";
+ vnfmObject.put("url", path);
+ vnfmObject.put(Constant.USERNAME, Constant.USERNAME);
+ vnfmObject.put(Constant.PASSWORD, Constant.PASSWORD);
JSONObject resp = ResultRequestUtil.call(vnfmObject, path, methodName, paramsJson);
assertTrue(resp.get("data").equals("connect fail."));
}
@@ -91,5 +98,33 @@ public class ResultRequestUtilTest {
JSONObject resp = ResultRequestUtil.call(vnfmObject, path, methodName, paramsJson);
assertTrue(resp.get("data").equals("get connection error"));
}
+
+
+ @Test
+ public void call() {
+
+ JSONObject vnfmObject = new JSONObject();
+ vnfmObject.put("url","https://localhost:8080/%s" );
+ vnfmObject.put(Constant.USERNAME, Constant.USERNAME);
+ vnfmObject.put(Constant.PASSWORD, Constant.PASSWORD);
+ String path = "https://localhost:8080/%s";
+ String methodName = "get";
+ String paramsJson = "";
+ assertNotNull(ResultRequestUtil.call( vnfmObject, path, methodName, paramsJson,
+ "authModel"));
+
+ }
+
+ @Test
+ public void callSouth() {
+ JSONObject vnfmObject = new JSONObject();
+ vnfmObject.put("url", "https://localhost:8080/%s");
+ vnfmObject.put(Constant.USERNAME, Constant.USERNAME);
+ vnfmObject.put(Constant.PASSWORD, Constant.PASSWORD);
+ String path = "https://localhost:8080/%s";
+ String methodName = "get";
+ String paramsJson = "";
+ assertNotNull(ResultRequestUtil.callSouth(vnfmObject, path, methodName, paramsJson, "authModel"));
+ }
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmUtilTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmUtilTest.java
index e95e9578..3cd28d7a 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmUtilTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmUtilTest.java
@@ -38,14 +38,14 @@ public class VnfmUtilTest {
@Test
public void getVnfmByIdTestSuccess(){
- new MockUp<VnfmRestfulUtil>(){
- @Mock
- public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
- RestfulResponse resp = new RestfulResponse();
- resp.setStatus(200);
- return resp;
- }
- };
+// new MockUp<VnfmRestfulUtil>(){
+// @Mock
+// public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
+// RestfulResponse resp = new RestfulResponse();
+// resp.setStatus(200);
+// return resp;
+// }
+// };
JSONObject resp = VnfmUtil.getVnfmById("1234");
assertNotNull(resp);
}
@@ -58,55 +58,56 @@ public class VnfmUtilTest {
@Test
public void getVnfmIdByIpTestSuccess(){
- new MockUp<VnfmRestfulUtil>(){
- @Mock
- public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
- RestfulResponse resp = new RestfulResponse();
- resp.setStatus(200);
- JSONArray respArray = new JSONArray();
- JSONObject obj = new JSONObject();
- obj.put("url", "localhost");
- obj.put("vnfmId", "1234");
- respArray.add(obj);
- resp.setResponseJson(respArray.toString());
- return resp;
- }
- };
+// new MockUp<VnfmRestfulUtil>(){
+// @Mock
+// public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
+// RestfulResponse resp = new RestfulResponse();
+// resp.setStatus(200);
+// JSONArray respArray = new JSONArray();
+// JSONObject obj = new JSONObject();
+// obj.put("url", "localhost");
+// obj.put("vnfmId", "1234");
+// respArray.add(obj);
+// resp.setResponseJson(respArray.toString());
+// return resp;
+// }
+// };
String resp = VnfmUtil.getVnfmIdByIp("localhost");
assertTrue("1234".equals(resp));
}
@Test
public void getVnfmIdByIpTestSuccessInvalidIP(){
- new MockUp<VnfmRestfulUtil>(){
- @Mock
- public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
- RestfulResponse resp = new RestfulResponse();
- resp.setStatus(200);
- JSONArray respArray = new JSONArray();
- JSONObject obj = new JSONObject();
- obj.put("url", "127.0.0.1");
- obj.put("vnfmId", "1234");
- respArray.add(obj);
- resp.setResponseJson(respArray.toString());
- return resp;
- }
- };
+// new MockUp<VnfmRestfulUtil>(){
+// @Mock
+// public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
+// RestfulResponse resp = new RestfulResponse();
+// resp.setStatus(200);
+// JSONArray respArray = new JSONArray();
+// JSONObject obj = new JSONObject();
+// obj.put("url", "127.0.0.1");
+// obj.put("vnfmId", "1234");
+// respArray.add(obj);
+// resp.setResponseJson(respArray.toString());
+// return resp;
+// }
+// };
String resp = VnfmUtil.getVnfmIdByIp("localhost");
assertTrue("".equals(resp));
}
@Test
public void getVnfmIdByIpTestSuccessEmptyResp(){
- new MockUp<VnfmRestfulUtil>(){
- @Mock
- public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
- RestfulResponse resp = new RestfulResponse();
- resp.setStatus(200);
- JSONArray respArray = new JSONArray();
- resp.setResponseJson(respArray.toString());
- return resp;
- }
- };
+// new MockUp<VnfmRestfulUtil>(){
+// @Mock
+// public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
+// RestfulResponse resp = new RestfulResponse();
+// resp.setStatus(200);
+// JSONArray respArray = new JSONArray();
+// resp.setResponseJson(respArray.toString());
+// return resp;
+// }
+// };
+ VnfmUtil.mockForTest("Vfnid");
String resp = VnfmUtil.getVnfmIdByIp("localhost");
assertTrue("".equals(resp));
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java
index fec98449..60b5f639 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java
@@ -53,51 +53,51 @@ public class VnfmRestfulUtilTest {
@Test
public void testSendReqToApp() {
- new MockUp<VnfmRestfulUtil>() {
-
- @Mock
- public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) {
- RestfulResponse restfulResponse = new RestfulResponse();
- restfulResponse.setStatus(Constant.HTTP_OK);
- String responseString = "{\"retCode\":1,\"data\":\"success\"}";
- restfulResponse.setResponseJson(responseString);
- return restfulResponse;
- }
- };
+// new MockUp<VnfmRestfulUtil>() {
+//
+// @Mock
+// public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) {
+// RestfulResponse restfulResponse = new RestfulResponse();
+// restfulResponse.setStatus(Constant.HTTP_OK);
+// String responseString = "{\"retCode\":1,\"data\":\"success\"}";
+// restfulResponse.setResponseJson(responseString);
+// return restfulResponse;
+// }
+// };
JSONObject result = VnfmRestfulUtil.sendReqToApp("path", "put", new JSONObject());
assertEquals(Constant.REST_SUCCESS, result.get("retCode"));
}
@Test
public void testSendReqToAppByErrorMsg() {
- new MockUp<VnfmRestfulUtil>() {
-
- @Mock
- public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) {
- RestfulResponse restfulResponse = new RestfulResponse();
- restfulResponse.setStatus(Constant.HTTP_OK);
- String responseString = "{\"retCode\":-1,\"data\":\"fail\",\"msg\":\"fail\"}";
- restfulResponse.setResponseJson(responseString);
- return restfulResponse;
- }
- };
+// new MockUp<VnfmRestfulUtil>() {
+//
+// @Mock
+// public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) {
+// RestfulResponse restfulResponse = new RestfulResponse();
+// restfulResponse.setStatus(Constant.HTTP_OK);
+// String responseString = "{\"retCode\":-1,\"data\":\"fail\",\"msg\":\"fail\"}";
+// restfulResponse.setResponseJson(responseString);
+// return restfulResponse;
+// }
+// };
JSONObject result = VnfmRestfulUtil.sendReqToApp("path", "put", new JSONObject());
assertEquals(Constant.REST_FAIL, result.get("retCode"));
}
@Test
public void testSendReqToAppByError() {
- new MockUp<VnfmRestfulUtil>() {
-
- @Mock
- public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) {
- RestfulResponse restfulResponse = new RestfulResponse();
- restfulResponse.setStatus(Constant.HTTP_OK);
- String responseString = "{\"retCode\":-1,\"data\":\"fail\"}";
- restfulResponse.setResponseJson(responseString);
- return restfulResponse;
- }
- };
+// new MockUp<VnfmRestfulUtil>() {
+//
+// @Mock
+// public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) {
+// RestfulResponse restfulResponse = new RestfulResponse();
+// restfulResponse.setStatus(Constant.HTTP_OK);
+// String responseString = "{\"retCode\":-1,\"data\":\"fail\"}";
+// restfulResponse.setResponseJson(responseString);
+// return restfulResponse;
+// }
+// };
JSONObject result = VnfmRestfulUtil.sendReqToApp("path", "put", new JSONObject());
assertEquals(Constant.REST_FAIL, result.get("retCode"));
}
@@ -238,4 +238,17 @@ public class VnfmRestfulUtilTest {
RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse("/test/123", "", "test123");
assertNull(resp);
}
+
+ @Test
+ public void getRemoteResponse() {
+ Map <String, String > headerMap = new HashMap<String, String>();
+
+ VnfmRestfulUtil.getRemoteResponse( "url", "get", headerMap,"params");
+ VnfmRestfulUtil.getRemoteResponse( "url", "post", headerMap,"params");
+ VnfmRestfulUtil.getRemoteResponse( "url", "put", headerMap,"params");
+ assertNull(VnfmRestfulUtil.getRemoteResponse( "url", "delete", headerMap,"params"));
+
+
+
+ }
}