summaryrefslogtreecommitdiffstats
path: root/huawei/vnfmadapter/VnfmadapterService
diff options
context:
space:
mode:
authorThamlurRaju <thamlurraju468@gmail.com>2018-08-27 11:25:09 +0530
committerThamlurRaju <thamlurraju468@gmail.com>2018-08-27 11:25:09 +0530
commit9b5a3ea2e2f6b60fcce2ece5ecffcdcdf879115c (patch)
tree46a78f6511dcf3fe7756aef8f42a44d3ecdf9e69 /huawei/vnfmadapter/VnfmadapterService
parent52adc0d940fef0dd96d5ca29dcf3430d8f1b2ee5 (diff)
Improve coverage of Svnfm AdapterResourceManager
88 breaches need to cover to reach 65% Coverage Sonar Link: https://sonar.onap.org/project/issues?assignees=ThamlurRaju&id=org.onap.vfc.nfvo.driver.vnfm.svnfm.huawei%3Avfc-nfvo-driver-vnfm-svnfm-huawei&open=AV8WGS_x-08if2a6pIEW&resolved=false Location: src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManager.java Change-Id: Id89403520c940bc694bd1243f8543afdf4c43e43 Issue-ID: VFC-1069 Signed-off-by: ThamlurRaju <thamlurraju468@gmail.com>
Diffstat (limited to 'huawei/vnfmadapter/VnfmadapterService')
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManagerTest.java3315
1 files changed, 3303 insertions, 12 deletions
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManagerTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManagerTest.java
index 95727339..1b4e9c30 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManagerTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManagerTest.java
@@ -23,16 +23,23 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpMethodBase;
import org.junit.Before;
import org.junit.Test;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.DownloadCsarManager;
+import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmUtil;
+import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient.RestfulParametes;
+import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient.RestfulResponse;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.VNFRestfulUtil;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.adapter.impl.AdapterResourceManager;
+import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.VnfmRestfulUtil;
+import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.connect.ConnectMgrVnfm;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.testutils.JsonUtil;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient.RestfulResponse;
import mockit.Mock;
import mockit.MockUp;
+import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
@@ -45,22 +52,25 @@ public class AdapterResourceManagerTest {
manager = new AdapterResourceManager();
}
- @Test(expected = JSONException.class)
+ @Test(expected=JSONException.class)
public void uploadVNFPackageTestJsonException() {
JSONObject vnfpkg = new JSONObject();
Map<String, String> paramsMap = new HashMap<>();
JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
- assertTrue(res != null);
-
}
-
- @Test(expected = JSONException.class)
- public void uploadVNFPackageTestJsonException2() {
+
+ @Test
+ public void uploadVNFPackageTestJsonException1() {
JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("", "");
Map<String, String> paramsMap = new HashMap<>();
- JSONObject res = manager.uploadVNFPackage(null, paramsMap);
- assertTrue(res != null);
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ }
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestJsonException2() {
+ Map<String, String> paramsMap = new HashMap<>();
+ manager.uploadVNFPackage(null, paramsMap);
}
@Test
@@ -83,11 +93,10 @@ public class AdapterResourceManagerTest {
}
- @Test
+ @Test(expected=NullPointerException.class)
public void uploadVNFPackageTestNullParam() {
JSONObject vnfpkg = new JSONObject();
vnfpkg.put("name", "test");
- Map<String, String> paramsMap = new HashMap<>();
JSONObject res = manager.uploadVNFPackage(vnfpkg, null);
assertTrue(res.get("reason").equals("csarid and vnfmid are null."));
@@ -309,4 +318,3286 @@ public class AdapterResourceManagerTest {
manager.getVnfdVersion("http://","127.0.0.1","token");
}
+ @Test(expected=NullPointerException.class)
+ public void testgetVNFDPlanInfoNull(){
+
+ manager.getVNFDPlanInfo(null, null, null);
+ }
+
+ @Test
+ public void testgetVNFDPlanInfo(){
+
+ manager.getVNFDPlanInfo("https://127.0.0.1:80", "vnfd123", "token");
+ }
+
+ @Test
+ public void testgetVNFDPlanInfoConn(){
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ new MockUp<HttpMethodBase>(){
+
+ @Mock
+ public int getStatusCode(){
+
+ return 200;
+ }
+
+ @Mock
+ public String getResponseBodyAsString()
+ throws IOException
+ {
+ JSONObject jobj = new JSONObject();
+ jobj.put("Status", 200);
+ jobj.put("UserName", "User");
+ jobj.put("password", "pass");
+ String str = jobj.toString();
+ return str;
+ }
+
+ };
+
+ manager.getVNFDPlanInfo("https://127.0.0.1:80", "vnfd123", "accessSession");
+ }
+
+ @Test
+ public void testgetVNFDPlanInfoConn500(){
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ new MockUp<HttpMethodBase>(){
+
+ @Mock
+ public int getStatusCode(){
+
+ return 500;
+ }
+
+ @Mock
+ public String getResponseBodyAsString()
+ throws IOException
+ {
+ String str = "Failed";
+ return str;
+ }
+
+ };
+
+ manager.getVNFDPlanInfo("https://127.0.0.1:80", "vnfd123", "accessSession");
+ }
+
+
+ @Test
+ public void testGetVnfdVersion200(){
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ new MockUp<HttpMethodBase>(){
+
+ @Mock
+ public int getStatusCode(){
+
+ return 200;
+ }
+
+ @Mock
+ public String getResponseBodyAsString()
+ throws IOException
+ {
+ JSONObject jobj = new JSONObject();
+ jobj.put("Status", 200);
+ jobj.put("UserName", "User");
+ jobj.put("password", "pass");
+ String str = jobj.toString();
+ return str;
+ }
+
+ };
+
+ JSONObject jobj = manager.getVnfdVersion("http://","127.0.0.1:80","accessSession");
+ }
+
+ @Test
+ public void testGetVnfdVersion500(){
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ new MockUp<HttpMethodBase>(){
+
+ @Mock
+ public int getStatusCode(){
+
+ return 500;
+ }
+
+ @Mock
+ public String getResponseBodyAsString()
+ throws IOException
+ {
+ String str = "Failed";
+ return str;
+ }
+ };
+
+ manager.getVnfdVersion("http://","127.0.0.1:80","accessSession");
+ }
+
+ @Test
+ public void uploadVNFPackageTestcsarid() {
+ RestfulParametes rp = new RestfulParametes();
+ rp.setRawData("success");
+ rp.setRawData("sdjhbfj");
+ HashMap<String,String> headerMap = new HashMap<String,String>();
+ headerMap.put("Content-Type", "application/json");
+ headerMap.put("X-TransactionId", "5851");
+ rp.setHeaderMap(headerMap);
+ HashMap<String,String> paramMap = new HashMap<String,String>();
+ paramMap.put("id", "1234");
+ rp.setParamMap(paramMap);
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ vnfpkg.put("Restfulparameters", rp);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid200");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+ }
+
+ @Test
+ public void uploadVNFPackageTestcsaridNull() {
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "caser200");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+
+ }
+
+ @Test
+ public void uploadVNFPackageTestParamEmpty() {
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ Map<String, String> paramsMap = new HashMap<>();
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ }
+
+ @Test
+ public void downloadCsarTestUrlAndFilePathWrong() {
+ String url = "http://localhost:8080";
+ String filePath = "Tset";
+ JSONObject res = manager.downloadCsar(url, filePath);
+ }
+ @Test
+ public void downloadCsarTestUrlAndFilePath() {
+ String url = "https://127.0.0.1:31943";
+ String filePath = "src/test/resources/Check.txt";
+ JSONObject res = manager.downloadCsar(url, filePath);
+ }
+
+ @Test
+ public void testGetAllCloudUrlEmpty(){
+ String url = "";
+ manager.getAllCloud(url,null);
+ }
+
+ @Test
+ public void testGetAllCloudUrlandConn(){
+ String url = "http://127.0.0.1:31943";
+ String conn = "conn";
+ manager.getAllCloud(url,conn);
+ }
+
+ @Test
+ public void testUnzipCSAREmpty(){
+ manager.unzipCSAR("vCpe.zip","");
+ }
+ @Test
+ public void testUnzipCSAREmpty1(){
+ manager.unzipCSAR("","/opt");
+ }
+
+ @Test
+ public void readVfnPkgInfoFromJsonTest() throws IOException{
+
+ System.setProperty("catalina.base", "D:/VFC/23-08-2018/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+ AdapterResourceManager.readVfnPkgInfoFromJson();
+ }
+ @Test
+ public void readVfnPkgInfoFromJsonTestNumBelowZero() throws IOException{
+
+ System.setProperty("catalina.base", "C:/Users/Huawei/Desktop");
+ AdapterResourceManager.readVfnPkgInfoFromJson();
+ }
+
+ @Test
+ public void testGetAllCloudUrlandaccessSession(){
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ new MockUp<HttpMethodBase>(){
+
+ @Mock
+ public int getStatusCode(){
+
+ return 200;
+ }
+
+ @Mock
+ public String getResponseBodyAsString()
+ throws IOException
+ {
+ String str = "{\n\t\"driverInfo\": {\n\t\t\"driverName\": \"hwvnfm\",\n\t\t\"instanceID\": \"hwvnfm-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\"services\": [{\n\t\t\t\"service_url\": \"/api/hwvnfm/v1\",\n\t\t\t\"support_sys\": [{\n\t\t\t\t\"type\": \"vnfm\",\n\t\t\t\t\"version\": \"V100R001\"\n\t\t\t}]\n\t\t}]\n\t}\n}";
+ JSONObject jobj = new JSONObject();
+ jobj.put("Status", 200);
+ jobj.put("UserName", "User");
+ jobj.put("password", "pass");
+ JSONArray ja = new JSONArray();
+ ja.add(str);
+ jobj.put("vim_info", ja);
+ String str1 = jobj.toString();
+ return str1;
+ }
+
+ };
+
+ System.setProperty("catalina.base", "C:/Users/Huawei/Desktop");
+ String url = "http://127.0.0.1:31943";
+ String conn = "accessSession";
+ manager.getAllCloud(url,conn);
+ }
+
+ @Test
+ public void testGetAllCloudUrlandaccessSession500(){
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ new MockUp<HttpMethodBase>(){
+
+ @Mock
+ public int getStatusCode(){
+
+ return 500;
+ }
+
+ @Mock
+ public String getResponseBodyAsString()
+ throws IOException
+ {
+ String str = "Failed";
+ return str;
+ }
+
+ };
+
+ System.setProperty("catalina.base", "C:/Users/Huawei/Desktop");
+ String url = "http://127.0.0.1:31943";
+ String conn = "accessSession";
+ manager.getAllCloud(url,conn);
+ }
+
+ @Test
+ public void testUpload(){
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ new MockUp<HttpMethodBase>(){
+
+ @Mock
+ public int getStatusCode(){
+
+ return 200;
+ }
+
+ @Mock
+ public String getResponseBodyAsString()
+ throws IOException
+ {
+ JSONObject jobj = new JSONObject();
+ jobj.put("Status", 200);
+ jobj.put("UserName", "User");
+ jobj.put("password", "pass");
+ String str = jobj.toString();
+ return str;
+ }
+
+ };
+
+ JSONObject vnfpackage = new JSONObject();
+ vnfpackage.put("UserName", "User");
+ vnfpackage.put("password", "Pass");
+ String vnfmurl = "http://127.0.0.1:31943";
+ String conntoken = "accessSession";
+ System.setProperty("catalina.base", "src/test/resources/");
+ manager.upload(vnfpackage, vnfmurl, conntoken);
+ }
+
+ @Test
+ public void testUploadNoJson(){
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ new MockUp<HttpMethodBase>(){
+
+ @Mock
+ public int getStatusCode(){
+
+ return 200;
+ }
+
+ @Mock
+ public String getResponseBodyAsString()
+ throws IOException
+ {
+
+ String str = "Test";
+ return str;
+ }
+
+ };
+
+ JSONObject vnfpackage = new JSONObject();
+ vnfpackage.put("UserName", "User");
+ vnfpackage.put("password", "Pass");
+ String vnfmurl = "http://127.0.0.1:31943";
+ String conntoken = "accessSession";
+ System.setProperty("catalina.base", "src/test/resources/");
+ manager.upload(vnfpackage, vnfmurl, conntoken);
+ }
+
+ @Test
+ public void testUpload500(){
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ new MockUp<HttpMethodBase>(){
+
+ @Mock
+ public int getStatusCode(){
+
+ return 500;
+ }
+
+ @Mock
+ public String getResponseBodyAsString()
+ throws IOException
+ {
+ String str = "Failed";
+ return str;
+ }
+
+ };
+
+ JSONObject vnfpackage = new JSONObject();
+ vnfpackage.put("UserName", "User");
+ vnfpackage.put("password", "Pass");
+ String vnfmurl = "http://127.0.0.1:31943";
+ String conntoken = "accessSession";
+ System.setProperty("catalina.base", "src/test/resources/");
+ manager.upload(vnfpackage, vnfmurl, conntoken);
+ }
+
+ @Test
+ public void testGetVnfmCsarInfoEmpty(){
+ manager.getVnfmCsarInfo("");
+ }
+ @Test
+ public void testGetVnfmCsarInfoNull(){
+ manager.getVnfmCsarInfo(null);
+ }
+ /*@Test
+ public void testGetVnfmCsarInfo(){
+ manager.getVnfmCsarInfo("casr-id-123");
+ }*/
+ @Test
+ public void downloadCsarTest() {
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ return "Success";
+
+ }
+ };
+
+ String url = "http://localhost:8080";
+ String filePath = "src/test/resources/Check.txt";
+ JSONObject res = manager.downloadCsar(url, filePath);
+ assertTrue(true);
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTest() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<RestfulResponse>(){
+
+ @Mock
+ public String getResponseContent() {
+
+ return "Success";
+ }
+
+ };
+
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ return js;
+ }
+ };
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(true);
+
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestSuccess() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<RestfulResponse>(){
+
+ @Mock
+ public String getResponseContent() {
+
+ return "Success";
+ }
+
+ };
+
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ return js;
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ return "Success";
+
+ }
+ };
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(true);
+
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestSuccessUNZIP() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<RestfulResponse>(){
+
+ @Mock
+ public String getResponseContent() {
+
+ return "Success";
+ }
+
+ };
+
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ return js;
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ return "Success";
+
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+ return 0;
+
+ }
+ };
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestSuccessUNZIPFTPSClient() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<RestfulResponse>(){
+
+ @Mock
+ public String getResponseContent() {
+
+ return "Success";
+ }
+
+ };
+
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ return js;
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ return "Success";
+
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+ return 0;
+
+ }
+ };
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ obj.put("ftp_server_ip", "https:127.0.0.1:80");
+ obj.put("ftp_username", "FtpUser");
+ obj.put("ftp_password", "FtpPass");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestSuccessUNZIPWithUrl() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<RestfulResponse>(){
+
+ @Mock
+ public String getResponseContent() {
+
+ return "Success";
+ }
+
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ return "Success";
+
+ }
+ };
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ return js;
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+ return 0;
+
+ }
+ };
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(true);
+
+ }
+
+
+ @Test
+ public void uploadVNFPackageTestSuccessUNZIP1() {
+
+ new MockUp<RestfulResponse>(){
+
+ @Mock
+ public String getResponseContent() {
+
+ return "Success";
+ }
+
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ return "Success";
+
+ }
+ };
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ return js;
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+ return 0;
+
+ }
+ };
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestSuccessConnect() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<RestfulResponse>(){
+
+ @Mock
+ public String getResponseContent() {
+
+ return "Success";
+ }
+
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ return "Success";
+
+ }
+ };
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ return js;
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+ return 0;
+
+ }
+ };
+
+ new MockUp<ConnectMgrVnfm>(){
+
+ @Mock
+ public int connect(JSONObject vnfmObj, String authModel) {
+
+ authModel = "accessSession";
+ return 200;
+ }
+
+ };
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(true);
+
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestSuccessConnectPath() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<RestfulResponse>(){
+
+ @Mock
+ public String getResponseContent() {
+
+ return "Success";
+ }
+
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ return "Success";
+
+ }
+ };
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ js.put("vim_info", ja);
+ return js;
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+ return 0;
+
+ }
+ };
+
+ new MockUp<ConnectMgrVnfm>(){
+
+ @Mock
+ public int connect(JSONObject vnfmObj, String authModel) {
+ vnfmObj.put("connToken", "accessSession");
+ vnfmObj.put("Content-Type", "Application/Json");
+ authModel = "accessSession";
+ return 200;
+ }
+
+ };
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/ONAP-VFC/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ new MockUp<HttpMethodBase>(){
+
+ @Mock
+ public int getStatusCode(){
+
+ return 200;
+ }
+
+ @Mock
+ public String getResponseBodyAsString()
+ throws IOException
+ {
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ JSONObject jobj = new JSONObject();
+ jobj.put("Status", 200);
+ jobj.put("UserName", "User");
+ jobj.put("password", "pass");
+ JSONArray ja = new JSONArray();
+ ja.add(str);
+ jobj.put("vim_info", ja);
+ String str1 = jobj.toString();
+ return str1;
+ }
+ };
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestSuccessConnectPath500() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<RestfulResponse>(){
+
+ @Mock
+ public String getResponseContent() {
+
+ return "Success";
+ }
+
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ return "Success";
+
+ }
+ };
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ js.put("vim_info", ja);
+ return js;
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+ return 0;
+
+ }
+ };
+
+ new MockUp<ConnectMgrVnfm>(){
+
+ @Mock
+ public int connect(JSONObject vnfmObj, String authModel) {
+ vnfmObj.put("connToken", "accessSession");
+ vnfmObj.put("Content-Type", "Application/Json");
+ authModel = "accessSession";
+ return 200;
+ }
+
+ };
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/ONAP-VFC/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ new MockUp<HttpMethodBase>(){
+
+ @Mock
+ public int getStatusCode(){
+
+ return 500;
+ }
+
+ @Mock
+ public String getResponseBodyAsString()
+ throws IOException
+ {
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ JSONObject jobj = new JSONObject();
+ jobj.put("Status", 500);
+ jobj.put("UserName", "User");
+ jobj.put("password", "pass");
+ JSONArray ja = new JSONArray();
+ ja.add(str);
+ jobj.put("vim_info", ja);
+ String str1 = jobj.toString();
+ return str1;
+ }
+ };
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(true);
+
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestSuccessConnectPathEmpty() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<RestfulResponse>(){
+
+ @Mock
+ public String getResponseContent() {
+
+ return "Success";
+ }
+
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ return "Success";
+
+ }
+ };
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n\"vim_id\": \"\",\n\t\t\"vim-info\": \"1\",\n\t\t\"vim-name\": \"\"\n}";
+ ja.add(str);
+ js.put("vim_info", ja);
+ return js;
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+ return 0;
+
+ }
+ };
+
+ new MockUp<ConnectMgrVnfm>(){
+
+ @Mock
+ public int connect(JSONObject vnfmObj, String authModel) {
+ vnfmObj.put("connToken", "accessSession");
+ vnfmObj.put("Content-Type", "Application/Json");
+ authModel = "accessSession";
+ return 200;
+ }
+
+ };
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/ONAP-VFC/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ new MockUp<HttpMethodBase>(){
+
+ @Mock
+ public int getStatusCode(){
+
+ return 200;
+ }
+
+ @Mock
+ public String getResponseBodyAsString()
+ throws IOException
+ {
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ JSONObject jobj = new JSONObject();
+ jobj.put("Status", 200);
+ jobj.put("UserName", "User");
+ jobj.put("password", "pass");
+ JSONArray ja = new JSONArray();
+ ja.add(str);
+ jobj.put("vim_info", ja);
+ String str1 = jobj.toString();
+ return str1;
+ }
+ };
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+
+ }
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestSuccessId() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<RestfulResponse>(){
+
+ @Mock
+ public String getResponseContent() {
+
+ return "Success";
+ }
+
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ return "Success";
+
+ }
+ };
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "upload-id-123");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ js.put("vim_info", ja);
+ return js;
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+ return 0;
+
+ }
+ };
+
+ new MockUp<ConnectMgrVnfm>(){
+
+ @Mock
+ public int connect(JSONObject vnfmObj, String authModel) {
+ vnfmObj.put("connToken", "accessSession");
+ vnfmObj.put("Content-Type", "Application/Json");
+ authModel = "accessSession";
+ return 200;
+ }
+
+ };
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/ONAP-VFC/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ new MockUp<HttpMethodBase>(){
+
+ @Mock
+ public int getStatusCode(){
+
+ return 200;
+ }
+
+ @Mock
+ public String getResponseBodyAsString()
+ throws IOException
+ {
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ JSONObject jobj = new JSONObject();
+ jobj.put("Status", 200);
+ jobj.put("UserName", "User");
+ jobj.put("password", "pass");
+ JSONArray ja = new JSONArray();
+ ja.add(str);
+ jobj.put("vim_info", ja);
+ String str1 = jobj.toString();
+ return str1;
+ }
+ };
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+
+ }
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestSuccessIdNull() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<RestfulResponse>(){
+
+ @Mock
+ public String getResponseContent() {
+
+ return "Success";
+ }
+
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ return "Success";
+
+ }
+ };
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", null);
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ js.put("vim_info", ja);
+ return js;
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+ return 0;
+
+ }
+ };
+
+ new MockUp<ConnectMgrVnfm>(){
+
+ @Mock
+ public int connect(JSONObject vnfmObj, String authModel) {
+ vnfmObj.put("connToken", "accessSession");
+ vnfmObj.put("Content-Type", "Application/Json");
+ authModel = "accessSession";
+ return 200;
+ }
+
+ };
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/ONAP-VFC/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ new MockUp<HttpMethodBase>(){
+
+ @Mock
+ public int getStatusCode(){
+
+ return 200;
+ }
+
+ @Mock
+ public String getResponseBodyAsString()
+ throws IOException
+ {
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ JSONObject jobj = new JSONObject();
+ jobj.put("Status", 200);
+ jobj.put("UserName", "User");
+ jobj.put("password", "pass");
+ JSONArray ja = new JSONArray();
+ ja.add(str);
+ jobj.put("vim_info", ja);
+ String str1 = jobj.toString();
+ return str1;
+ }
+ };
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+
+ }
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestSuccessIdFile0() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<RestfulResponse>(){
+
+ @Mock
+ public String getResponseContent() {
+
+ return "Success";
+ }
+
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ return "Success";
+
+ }
+ };
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/Check10.txt");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ js.put("vim_info", ja);
+ return js;
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+ return 0;
+
+ }
+ };
+
+ new MockUp<ConnectMgrVnfm>(){
+
+ @Mock
+ public int connect(JSONObject vnfmObj, String authModel) {
+ vnfmObj.put("connToken", "accessSession");
+ vnfmObj.put("Content-Type", "Application/Json");
+ authModel = "accessSession";
+ return 200;
+ }
+
+ };
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/ONAP-VFC/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ new MockUp<HttpMethodBase>(){
+
+ @Mock
+ public int getStatusCode(){
+
+ return 200;
+ }
+
+ @Mock
+ public String getResponseBodyAsString()
+ throws IOException
+ {
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ JSONObject jobj = new JSONObject();
+ jobj.put("Status", 200);
+ jobj.put("UserName", "User");
+ jobj.put("password", "pass");
+ JSONArray ja = new JSONArray();
+ ja.add(str);
+ jobj.put("vim_info", ja);
+ String str1 = jobj.toString();
+ return str1;
+ }
+ };
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestSuccessId500() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<RestfulResponse>(){
+
+ @Mock
+ public String getResponseContent() {
+
+ return "Success";
+ }
+
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ return "Success";
+
+ }
+ };
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "upload-id-123");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ js.put("vim_info", ja);
+ return js;
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+ return 0;
+
+ }
+ };
+
+ new MockUp<ConnectMgrVnfm>(){
+
+ @Mock
+ public int connect(JSONObject vnfmObj, String authModel) {
+ vnfmObj.put("connToken", "accessSession");
+ vnfmObj.put("Content-Type", "Application/Json");
+ authModel = "accessSession";
+ return 200;
+ }
+
+ };
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/ONAP-VFC/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(true);
+
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestSuccessIdEmpty() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<RestfulResponse>(){
+
+ @Mock
+ public String getResponseContent() {
+
+ return "Success";
+ }
+
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ return "Success";
+
+ }
+ };
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ js.put("vim_info", ja);
+ return js;
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+ return 0;
+
+ }
+ };
+
+ new MockUp<ConnectMgrVnfm>(){
+
+ @Mock
+ public int connect(JSONObject vnfmObj, String authModel) {
+ vnfmObj.put("connToken", "accessSession");
+ vnfmObj.put("Content-Type", "Application/Json");
+ authModel = "accessSession";
+ return 200;
+ }
+
+ };
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/ONAP-VFC/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestSuccessTemplete() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<RestfulResponse>(){
+
+ @Mock
+ public String getResponseContent() {
+
+ return "Success";
+ }
+
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ return "Success";
+
+ }
+ };
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "upload-id-123");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ JSONArray ja1 = new JSONArray();
+ String str1 = "{\n \"vnfdVersion\": \"1.0version\",\n\t\"vnfd-info\": {\n\t\t\"vnfd-name\": \"vnfd-name-123\",\n\t\t\"vnfd-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja1.add(str1);
+ js.put("vim_info", ja);
+ js.put("templates", ja1);
+ return js;
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+ return 0;
+
+ }
+ };
+
+ new MockUp<ConnectMgrVnfm>(){
+
+ @Mock
+ public int connect(JSONObject vnfmObj, String authModel) {
+ vnfmObj.put("connToken", "accessSession");
+ vnfmObj.put("Content-Type", "Application/Json");
+ authModel = "accessSession";
+ return 200;
+ }
+
+ };
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/ONAP-VFC/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestSuccessTempleteForVPlan() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<RestfulResponse>(){
+
+ @Mock
+ public String getResponseContent() {
+
+ return "Success";
+ }
+
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ return "Success";
+
+ }
+ };
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "upload-id-123");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ JSONArray ja1 = new JSONArray();
+ String str1 = "{\n \"vnfdVersion\": \"1.0version\",\n\t\"vnfd-info\": {\n\t\t\"vnfd-name\": \"vnfd-name-123\",\n\t\t\"vnfd-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";;
+ ja1.add(str1);
+ JSONArray ja2 = new JSONArray();
+ String str2 = "{\n \"template_name\": \"vnfd-name-123\",\n \"topology_template\": [{\n\t\t\t\"service_url\": \"/api/hwvnfm/v1\",\n\t\t\t\n\t\t}]\n\t\n\t\n}";
+ ja2.add(str2);
+ JSONObject jsObject = new JSONObject();
+ jsObject.put("downloadUrl", "http://localhost:80");
+ jsObject.put("csarName", "Csar_Check");
+ js.put("vim_info", ja);
+ js.put("template", ja2);
+ js.put("templates", ja1);
+ js.put("packageInfo", jsObject);
+ return js;
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+ return 0;
+
+ }
+ };
+
+ new MockUp<ConnectMgrVnfm>(){
+
+ @Mock
+ public int connect(JSONObject vnfmObj, String authModel) {
+ vnfmObj.put("connToken", "accessSession");
+ vnfmObj.put("Content-Type", "Application/Json");
+ authModel = "accessSession";
+ return 200;
+ }
+
+ };
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/ONAP-VFC/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+
+ }
+
+
+
+ @Test
+ public void uploadVNFPackageTestParamMapEmpty() {
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("", "");
+ paramsMap.put("", "");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void uploadVNFPackageTestVnfpkgEmpty() {
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("", "");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void readScaleInVmIdFromJsonTest() {
+
+ System.setProperty("catalina.base", "D:/VFC/23-08-2018/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+ AdapterResourceManager.readScaleInVmIdFromJson();
+ }
+
+ @Test
+ public void readScaleInVmIdFromJsonTestNoFile() {
+
+ System.setProperty("catalina.base", "src/test/resources");
+ AdapterResourceManager.readScaleInVmIdFromJson();
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestWithCscf() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<RestfulResponse>(){
+
+ @Mock
+ public String getResponseContent() {
+
+ return "Success";
+ }
+
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ return "Success";
+
+ }
+ };
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "upload-id-123");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ JSONArray ja1 = new JSONArray();
+ String str1 = "{\n \"vnfdVersion\": \"1.0version\",\n\t\"vnfd-info\": {\n\t\t\"vnfd-name\": \"vnfd-name-123\",\n\t\t\"vnfd-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";;
+ ja1.add(str1);
+ JSONArray ja2 = new JSONArray();
+ String str2 = "{\n \"template_name\": \"vnfd-name-123\",\n \"topology_template\": [{\n\t\t\t\"service_url\": \"/api/hwvnfm/v1\",\n\t\t\t\n\t\t}]\n\t\n\t\n}";
+ ja2.add(str2);
+ JSONObject jsObject = new JSONObject();
+ jsObject.put("downloadUrl", "http://localhost:80");
+ jsObject.put("csarName", "CSCF_SI");
+ js.put("vim_info", ja);
+ js.put("template", ja2);
+ js.put("templates", ja1);
+ js.put("packageInfo", jsObject);
+ return js;
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+ return 0;
+
+ }
+ };
+
+ new MockUp<ConnectMgrVnfm>(){
+
+ @Mock
+ public int connect(JSONObject vnfmObj, String authModel) {
+ vnfmObj.put("connToken", "accessSession");
+ vnfmObj.put("Content-Type", "Application/Json");
+ authModel = "accessSession";
+ return 200;
+ }
+
+ };
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/ONAP-VFC/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestWithMME() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "upload-id-123");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ JSONArray ja1 = new JSONArray();
+ String str1 = "{\n \"vnfdVersion\": \"1.0version\",\n\t\"vnfd-info\": {\n\t\t\"vnfd-name\": \"vnfd-name-123\",\n\t\t\"vnfd-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";;
+ ja1.add(str1);
+ JSONArray ja2 = new JSONArray();
+ String str2 = "{\n \"template_name\": \"vnfd-name-123\",\n \"topology_template\": [{\n\t\t\t\"service_url\": \"/api/hwvnfm/v1\",\n\t\t\t\n\t\t}]\n\t\n\t\n}";
+ ja2.add(str2);
+ JSONObject jsObject = new JSONObject();
+ jsObject.put("downloadUrl", "http://localhost:80");
+ jsObject.put("csarName", "MME");
+ js.put("vim_info", ja);
+ js.put("template", ja2);
+ js.put("templates", ja1);
+ js.put("packageInfo", jsObject);
+ return js;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/ONAP-VFC/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestWithSPGW() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "upload-id-123");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ JSONArray ja1 = new JSONArray();
+ String str1 = "{\n \"vnfdVersion\": \"1.0version\",\n\t\"vnfd-info\": {\n\t\t\"vnfd-name\": \"vnfd-name-123\",\n\t\t\"vnfd-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";;
+ ja1.add(str1);
+ JSONArray ja2 = new JSONArray();
+ String str2 = "{\n \"template_name\": \"vnfd-name-123\",\n \"topology_template\": [{\n\t\t\t\"service_url\": \"/api/hwvnfm/v1\",\n\t\t\t\n\t\t}]\n\t\n\t\n}";
+ ja2.add(str2);
+ JSONObject jsObject = new JSONObject();
+ jsObject.put("downloadUrl", "http://localhost:80");
+ jsObject.put("csarName", "SPGW");
+ js.put("vim_info", ja);
+ js.put("template", ja2);
+ js.put("templates", ja1);
+ js.put("packageInfo", jsObject);
+ return js;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/ONAP-VFC/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestWithHSS() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "upload-id-123");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ JSONArray ja1 = new JSONArray();
+ String str1 = "{\n \"vnfdVersion\": \"1.0version\",\n\t\"vnfd-info\": {\n\t\t\"vnfd-name\": \"vnfd-name-123\",\n\t\t\"vnfd-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";;
+ ja1.add(str1);
+ JSONArray ja2 = new JSONArray();
+ String str2 = "{\n \"template_name\": \"vnfd-name-123\",\n \"topology_template\": [{\n\t\t\t\"service_url\": \"/api/hwvnfm/v1\",\n\t\t\t\n\t\t}]\n\t\n\t\n}";
+ ja2.add(str2);
+ JSONObject jsObject = new JSONObject();
+ jsObject.put("downloadUrl", "http://localhost:80");
+ jsObject.put("csarName", "HSS");
+ js.put("vim_info", ja);
+ js.put("template", ja2);
+ js.put("templates", ja1);
+ js.put("packageInfo", jsObject);
+ return js;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/ONAP-VFC/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestWithSBC() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "upload-id-123");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ JSONArray ja1 = new JSONArray();
+ String str1 = "{\n \"vnfdVersion\": \"1.0version\",\n\t\"vnfd-info\": {\n\t\t\"vnfd-name\": \"vnfd-name-123\",\n\t\t\"vnfd-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";;
+ ja1.add(str1);
+ JSONArray ja2 = new JSONArray();
+ String str2 = "{\n \"template_name\": \"vnfd-name-123\",\n \"topology_template\": [{\n\t\t\t\"service_url\": \"/api/hwvnfm/v1\",\n\t\t\t\n\t\t}]\n\t\n\t\n}";
+ ja2.add(str2);
+ JSONObject jsObject = new JSONObject();
+ jsObject.put("downloadUrl", "http://localhost:80");
+ jsObject.put("csarName", "SBC");
+ js.put("vim_info", ja);
+ js.put("template", ja2);
+ js.put("templates", ja1);
+ js.put("packageInfo", jsObject);
+ return js;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/ONAP-VFC/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestWithPCRF() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "upload-id-123");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ JSONArray ja1 = new JSONArray();
+ String str1 = "{\n \"vnfdVersion\": \"1.0version\",\n\t\"vnfd-info\": {\n\t\t\"vnfd-name\": \"vnfd-name-123\",\n\t\t\"vnfd-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";;
+ ja1.add(str1);
+ JSONArray ja2 = new JSONArray();
+ String str2 = "{\n \"template_name\": \"vnfd-name-123\",\n \"topology_template\": [{\n\t\t\t\"service_url\": \"/api/hwvnfm/v1\",\n\t\t\t\n\t\t}]\n\t\n\t\n}";
+ ja2.add(str2);
+ JSONObject jsObject = new JSONObject();
+ jsObject.put("downloadUrl", "http://localhost:80");
+ jsObject.put("csarName", "PCRF");
+ js.put("vim_info", ja);
+ js.put("template", ja2);
+ js.put("templates", ja1);
+ js.put("packageInfo", jsObject);
+ return js;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/ONAP-VFC/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("download csar file failed."));
+
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestWithTAS() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "upload-id-123");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ JSONArray ja1 = new JSONArray();
+ String str1 = "{\n \"vnfdVersion\": \"1.0version\",\n\t\"vnfd-info\": {\n\t\t\"vnfd-name\": \"vnfd-name-123\",\n\t\t\"vnfd-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";;
+ ja1.add(str1);
+ JSONArray ja2 = new JSONArray();
+ String str2 = "{\n \"template_name\": \"vnfd-name-123\",\n \"topology_template\": [{\n\t\t\t\"service_url\": \"/api/hwvnfm/v1\",\n\t\t\t\n\t\t}]\n\t\n\t\n}";
+ ja2.add(str2);
+ JSONObject jsObject = new JSONObject();
+ jsObject.put("downloadUrl", "http://localhost:80");
+ jsObject.put("csarName", "TAS");
+ js.put("vim_info", ja);
+ js.put("template", ja2);
+ js.put("templates", ja1);
+ js.put("packageInfo", jsObject);
+ return js;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/ONAP-VFC/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("download csar file failed."));
+
+ }
+
+ @Test
+ public void uploadVNFPackageTestWithCSCF() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "upload-id-123");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ JSONArray ja1 = new JSONArray();
+ String str1 = "{\n \"vnfdVersion\": \"1.0version\",\n\t\"vnfd-info\": {\n\t\t\"vnfd-name\": \"vnfd-name-123\",\n\t\t\"vnfd-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";;
+ ja1.add(str1);
+ JSONArray ja2 = new JSONArray();
+ String str2 = "{\n \"template_name\": \"vnfd-name-123\",\n \"topology_template\": [{\n\t\t\t\"service_url\": \"/api/hwvnfm/v1\",\n\t\t\t\n\t\t}]\n\t\n\t\n}";
+ ja2.add(str2);
+ JSONObject jsObject = new JSONObject();
+ jsObject.put("downloadUrl", "http://localhost:80");
+ jsObject.put("csarName", "CSCF");
+ JSONObject jsEms = new JSONObject();
+ jsEms.put("emsUuid", "123erbhi-hjdek123");
+ JSONObject jsCsar = new JSONObject();
+ jsCsar.put("csar_file_path", "/home/ubuntu/check/");
+ jsCsar.put("csar_file_name", "Csar_File");
+ jsCsar.put("emsUuid", jsEms);
+ JSONObject jsTemp = new JSONObject();
+ jsTemp.put("template", jsCsar);
+ js.put("vCSCF", jsTemp);
+ js.put("vim_info", ja);
+ js.put("template", ja2);
+ js.put("templates", ja1);
+ js.put("packageInfo", jsObject);
+ return js;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/VFC/23-08-2018/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ JSONObject vnfpkg = new JSONObject();
+ JSONObject vnfpkg1 = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg1, paramsMap);
+ assertTrue(res.get("reason").equals("download csar file failed."));
+ }
+
+ @Test
+ public void uploadVNFPackageTestWithOutEmsUid() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "upload-id-123");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ JSONArray ja1 = new JSONArray();
+ String str1 = "{\n \"vnfdVersion\": \"1.0version\",\n\t\"vnfd-info\": {\n\t\t\"vnfd-name\": \"vnfd-name-123\",\n\t\t\"vnfd-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";;
+ ja1.add(str1);
+ JSONArray ja2 = new JSONArray();
+ String str2 = "{\n \"template_name\": \"vnfd-name-123\",\n \"topology_template\": [{\n\t\t\t\"service_url\": \"/api/hwvnfm/v1\",\n\t\t\t\n\t\t}]\n\t\n\t\n}";
+ ja2.add(str2);
+ JSONObject jsObject = new JSONObject();
+ jsObject.put("downloadUrl", "http://localhost:80");
+ jsObject.put("csarName", "CSCF");
+ JSONObject jsCsar = new JSONObject();
+ jsCsar.put("csar_file_path", "/home/ubuntu/check/");
+ jsCsar.put("csar_file_name", "Csar_File");
+ JSONObject jsTemp = new JSONObject();
+ jsTemp.put("template", jsCsar);
+ js.put("vCSCF", jsTemp);
+ js.put("vim_info", ja);
+ js.put("template", ja2);
+ js.put("templates", ja1);
+ js.put("packageInfo", jsObject);
+ return js;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/VFC/23-08-2018/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ JSONObject vnfpkg = new JSONObject();
+ JSONObject vnfpkg1 = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg1, paramsMap);
+ assertTrue(res.get("reason").equals("download csar file failed."));
+ }
+
+ @Test
+ public void uploadVNFPackageTestWithCSDowCsar() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ String response = "Success";
+ return response;
+ }
+ };
+
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "upload-id-123");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ JSONArray ja1 = new JSONArray();
+ String str1 = "{\n \"vnfdVersion\": \"1.0version\",\n\t\"vnfd-info\": {\n\t\t\"vnfd-name\": \"vnfd-name-123\",\n\t\t\"vnfd-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";;
+ ja1.add(str1);
+ JSONArray ja2 = new JSONArray();
+ String str2 = "{\n \"template_name\": \"vnfd-name-123\",\n \"topology_template\": [{\n\t\t\t\"service_url\": \"/api/hwvnfm/v1\",\n\t\t\t\n\t\t}]\n\t\n\t\n}";
+ ja2.add(str2);
+ JSONObject jsObject = new JSONObject();
+ jsObject.put("downloadUrl", "http://localhost:80");
+ jsObject.put("csarName", "CSCF");
+ JSONObject jsEms = new JSONObject();
+ jsEms.put("emsUuid", "123erbhi-hjdek123");
+ JSONObject jsCsar = new JSONObject();
+ jsCsar.put("csar_file_path", "/home/ubuntu/check/");
+ jsCsar.put("csar_file_name", "Csar_File");
+ jsCsar.put("emsUuid", jsEms);
+ JSONObject jsTemp = new JSONObject();
+ jsTemp.put("template", jsCsar);
+ js.put("vCSCF", jsTemp);
+ js.put("vim_info", ja);
+ js.put("template", ja2);
+ js.put("templates", ja1);
+ js.put("packageInfo", jsObject);
+ return js;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/VFC/23-08-2018/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ JSONObject vnfpkg = new JSONObject();
+ JSONObject vnfpkg1 = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg1, paramsMap);
+ assertTrue(res.get("reason").equals("unzip csar file failed."));
+ }
+
+ @Test
+ public void uploadVNFPackageTestWithUnZipCsar() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+ return rr;
+
+ }
+ };
+
+ new MockUp<VnfmUtil>(){
+ @Mock
+ public JSONObject getVnfmById(String vnfmId) {
+
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("url", "https://localhost:80");
+ jsonObject.put("userName", "ubuntu");
+ jsonObject.put("password", "******");
+ return jsonObject;
+
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ String response = "Success";
+ return response;
+ }
+
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+
+ return 0;
+ }
+ };
+
+ new MockUp<ConnectMgrVnfm>(){
+ @Mock
+ public int connect(JSONObject vnfmObj, String authModel) {
+
+
+ return 404;
+
+ }
+ };
+
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "upload-id-123");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ JSONArray ja1 = new JSONArray();
+ String str1 = "{\n \"vnfdVersion\": \"1.0version\",\n\t\"vnfd-info\": {\n\t\t\"vnfd-name\": \"vnfd-name-123\",\n\t\t\"vnfd-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";;
+ ja1.add(str1);
+ JSONArray ja2 = new JSONArray();
+ String str2 = "{\n \"template_name\": \"vnfd-name-123\",\n \"topology_template\": [{\n\t\t\t\"service_url\": \"/api/hwvnfm/v1\",\n\t\t\t\n\t\t}]\n\t\n\t\n}";
+ ja2.add(str2);
+ JSONObject jsObject = new JSONObject();
+ jsObject.put("downloadUrl", "http://localhost:80");
+ jsObject.put("csarName", "CSCF");
+ JSONObject jsEms = new JSONObject();
+ jsEms.put("emsUuid", "123erbhi-hjdek123");
+ JSONObject jsCsar = new JSONObject();
+ jsCsar.put("csar_file_path", "/home/ubuntu/check/");
+ jsCsar.put("csar_file_name", "Csar_File");
+ jsCsar.put("emsUuid", jsEms);
+ JSONObject jsTemp = new JSONObject();
+ jsTemp.put("template", jsCsar);
+ js.put("vCSCF", jsTemp);
+ js.put("vim_info", ja);
+ js.put("template", ja2);
+ js.put("templates", ja1);
+ js.put("packageInfo", jsObject);
+ return js;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/VFC/23-08-2018/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ JSONObject vnfpkg = new JSONObject();
+ JSONObject vnfpkg1 = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg1, paramsMap);
+ assertTrue(res.get("reason").equals("connect fail."));
+ }
+
+ @Test(expected=JSONException.class)
+ public void uploadVNFPackageTestWithConnectMgr() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<VnfmUtil>(){
+ @Mock
+ public JSONObject getVnfmById(String vnfmId) {
+
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("url", "https://localhost:80");
+ jsonObject.put("userName", "ubuntu");
+ jsonObject.put("password", "******");
+ return jsonObject;
+
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ String response = "Success";
+ return response;
+ }
+
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+
+ return 0;
+ }
+ };
+
+ new MockUp<HttpClient>(){
+ @Mock
+ public int executeMethod(HttpMethod method) {
+ return 200;
+ }
+ };
+
+ new MockUp<HttpMethodBase>(){
+
+ @Mock
+ public int getStatusCode(){
+
+ return 200;
+ }
+
+ };
+
+ new MockUp<ConnectMgrVnfm>(){
+ @Mock
+ public int connect(JSONObject vnfmObj, String authModel) {
+
+
+ return 200;
+
+ }
+
+ @Mock
+ public String getAccessSession() {
+
+ return "conn";
+ }
+ };
+
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "upload-id-123");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ JSONArray ja1 = new JSONArray();
+ String str1 = "{\n \"vnfdVersion\": \"1.0version\",\n\t\"vnfd-info\": {\n\t\t\"vnfd-name\": \"vnfd-name-123\",\n\t\t\"vnfd-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";;
+ ja1.add(str1);
+ JSONArray ja2 = new JSONArray();
+ String str2 = "{\n \"template_name\": \"vnfd-name-123\",\n \"topology_template\": [{\n\t\t\t\"service_url\": \"/api/hwvnfm/v1\",\n\t\t\t\n\t\t}]\n\t\n\t\n}";
+ ja2.add(str2);
+ JSONObject jsObject = new JSONObject();
+ jsObject.put("downloadUrl", "http://localhost:80");
+ jsObject.put("csarName", "CSCF");
+ JSONObject jsEms = new JSONObject();
+ jsEms.put("emsUuid", "123erbhi-hjdek123");
+ JSONObject jsCsar = new JSONObject();
+ jsCsar.put("csar_file_path", "/home/ubuntu/check/");
+ jsCsar.put("csar_file_name", "Csar_File");
+ jsCsar.put("emsUuid", jsEms);
+ JSONObject jsTemp = new JSONObject();
+ jsTemp.put("template", jsCsar);
+ js.put("vCSCF", jsTemp);
+ js.put("vim_info", ja);
+ js.put("template", ja2);
+ js.put("templates", ja1);
+ js.put("packageInfo", jsObject);
+ return js;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/VFC/23-08-2018/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ JSONObject vnfpkg = new JSONObject();
+ JSONObject vnfpkg1 = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg1, paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+ }
+
+ @Test
+ public void uploadVNFPackageTestWithConnectMgrGetAllFail() {
+
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rr = new RestfulResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("Content-Type", "Application/Json");
+ header.put("X-FormId", "jhfdl");
+ rr.setRespHeaderMap(header);
+ rr.setStatus(200);
+ rr.setResponseJson("shdfhj");
+
+ return rr;
+
+ }
+ };
+
+ new MockUp<VnfmUtil>(){
+ @Mock
+ public JSONObject getVnfmById(String vnfmId) {
+
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("url", "https://localhost:80");
+ jsonObject.put("userName", "ubuntu");
+ jsonObject.put("password", "******");
+ return jsonObject;
+
+ }
+ };
+
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public String download(String url, String filepath) {
+ String response = "Success";
+ return response;
+ }
+
+ @Mock
+ public int unzipCSAR(String fileName, String filePath) {
+
+ return 0;
+ }
+ };
+
+ new MockUp<ConnectMgrVnfm>(){
+ @Mock
+ public int connect(JSONObject vnfmObj, String authModel) {
+
+
+ return 200;
+
+ }
+
+ @Mock
+ public String getAccessSession() {
+
+ return "conn";
+ }
+ };
+
+ new MockUp<JSONObject>(){
+ @Mock
+ public JSONObject fromObject(Object object){
+ JSONObject js = new JSONObject();
+ js.put("id", "upload-id-123");
+ js.put("Result", "Success");
+ js.put("Check", "Ok");
+ js.put("url", "http://localhost:80");
+ js.put("userName", "User");
+ js.put("password", "pass");
+ js.put("downloadUri", "http://127.0.0.1:80");
+ js.put("keyStore", "C:/Users/Huawei/Desktop/etc/conf/server.p12");
+ js.put("keyStorePass", "Changeme_123");
+ js.put("keyStoreType", "PKCS12");
+ JSONArray ja = new JSONArray();
+ String str = "{\n \"vim_id\": \"vim-0-1\",\n\t\"vim-info\": {\n\t\t\"vim-name\": \"vim-name-123\",\n\t\t\"vim-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";
+ ja.add(str);
+ JSONArray ja1 = new JSONArray();
+ String str1 = "{\n \"vnfdVersion\": \"1.0version\",\n\t\"vnfd-info\": {\n\t\t\"vnfd-name\": \"vnfd-name-123\",\n\t\t\"vnfd-id\": \"vim-0-1\",\n\t\t\"ip\": \"127.0.0.1\",\n\t\t\"port\": \"8482\",\n\t\t\"protocol\": \"http\",\n\t\t\n\t}\n}";;
+ ja1.add(str1);
+ JSONArray ja2 = new JSONArray();
+ String str2 = "{\n \"template_name\": \"vnfd-name-123\",\n \"topology_template\": [{\n\t\t\t\"service_url\": \"/api/hwvnfm/v1\",\n\t\t\t\n\t\t}]\n\t\n\t\n}";
+ ja2.add(str2);
+ JSONObject jsObject = new JSONObject();
+ jsObject.put("downloadUrl", "http://localhost:80");
+ jsObject.put("csarName", "CSCF");
+ JSONObject jsEms = new JSONObject();
+ jsEms.put("emsUuid", "123erbhi-hjdek123");
+ JSONObject jsCsar = new JSONObject();
+ jsCsar.put("csar_file_path", "/home/ubuntu/check/");
+ jsCsar.put("csar_file_name", "Csar_File");
+ jsCsar.put("emsUuid", jsEms);
+ JSONObject jsTemp = new JSONObject();
+ jsTemp.put("template", jsCsar);
+ js.put("vCSCF", jsTemp);
+ js.put("vim_info", ja);
+ js.put("template", ja2);
+ js.put("templates", ja1);
+ js.put("packageInfo", jsObject);
+ return js;
+ }
+ };
+
+ System.setProperty("catalina.base", "D:/VFC/23-08-2018/svnfm/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release");
+
+ JSONObject vnfpkg = new JSONObject();
+ JSONObject vnfpkg1 = new JSONObject();
+ vnfpkg.put("name", "test");
+ JSONObject obj = new JSONObject();
+ obj.put("csar_file_path", "src/test/resources/Check10.txt");
+ obj.put("csar_file_name", "casrFile");
+ vnfpkg.put("template", obj);
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "vnfmid1234");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg1, paramsMap);
+ assertTrue(res.get("reason").equals("get allcloud failed and IOException.Connection refused: connect"));
+ }
+
}