summaryrefslogtreecommitdiffstats
path: root/huawei/vnfmadapter/VnfmadapterService/service/src/test/java
diff options
context:
space:
mode:
authorvictor.gao <victor.gao@huawei.com>2017-07-03 11:44:26 +0800
committervictor.gao <victor.gao@huawei.com>2017-07-03 11:44:26 +0800
commit7c9d941a80634d40d03f38c3f24ea503822d4b79 (patch)
tree247416f9c660e9eb2d05c71184fc3fe91bfe7160 /huawei/vnfmadapter/VnfmadapterService/service/src/test/java
parent52543689bca23d9bd6b759a8dbf8f06bf61701f3 (diff)
Change: add OPEN-O seed code for VF-C
Change-Id: Iecacac039e86db2eae006c8947d6dd681e458b83 Signed-off-by: victor.gao <victor.gao@huawei.com>
Diffstat (limited to 'huawei/vnfmadapter/VnfmadapterService/service/src/test/java')
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/DownloadCsarManagerTest.java74
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/FileUtil.java50
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/ResultRequestUtilTest.java63
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/VnfmUtilTest.java113
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/servicetoken/HttpRestfulHelpTest.java46
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/servicetoken/VNFRestfulUtilTest.java322
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java240
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/activator/RoaVnfmServicePostProcessorTest.java52
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/activator/TestRoaVnfmService2DriverMgr.java52
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/adapter/impl/AdapterResourceManagerTest.java311
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/adapter/impl/Driver2MSBManagerTest.java281
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/adapter/impl/VnfmAdapter2DriverManagerTest.java281
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java51
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java45
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/constant/TestConstant.java39
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/api/ConnectInfoTest.java89
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/AbstractSslContextTest.java46
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/HttpRequestsTest.java98
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/SslAnonymousSocketTest.java51
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/SslCertificateSocketTest.java79
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/SslProtocolSocketFactoryTest.java47
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/vnf/VnfMgrVnfmTest.java307
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/dao/impl/VnfmDaoImplTest.java64
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/entity/VnfmTest.java77
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/process/AuthMgrTest.java64
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/process/RegisterMgrTest.java66
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/process/VnfMgrTest.java497
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/process/VnfResourceMgrTest.java235
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/AuthRoaTest.java203
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/SwaggerRoaTest.java42
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/VnfAdapterResourceRoaTest.java55
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/VnfResourceRoaTest.java268
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/VnfRoaTest.java579
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/exceptionmapper/ExceptionMessageTest.java68
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/exceptionmapper/GenericExceptionMapperTest.java43
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/exceptionmapper/ServiceExceptionMapperTest.java44
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/testutils/JsonUtil.java51
37 files changed, 5093 insertions, 0 deletions
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/DownloadCsarManagerTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/DownloadCsarManagerTest.java
new file mode 100644
index 00000000..85ac321e
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/DownloadCsarManagerTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.nfvo.vnfmadapter.common;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.StatusLine;
+import org.apache.http.message.BasicHttpResponse;
+import org.apache.http.message.BasicStatusLine;
+import org.junit.Test;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * Created by QuanZhong on 2017/3/17.
+ */
+public class DownloadCsarManagerTest {
+
+ @Test
+ public void getFileNameTest(){
+ ProtocolVersion version = new ProtocolVersion("HTTP",1,1);
+ StatusLine sl = new BasicStatusLine(version,200,"success");
+ HttpResponse response = new BasicHttpResponse(sl);
+ response.setHeader("Content-Disposition","filename");
+ DownloadCsarManager.getFileName(response);
+ }
+
+ @Test
+ public void downloadTest(){
+ DownloadCsarManager.download("http://www.baidu.com");
+ DownloadCsarManager.download("http://www.baidu.com","/opt");
+ DownloadCsarManager.getRandomFileName();
+ }
+ @Test
+ public void getFilePath(){
+ ProtocolVersion version = new ProtocolVersion("HTTP",1,1);
+ StatusLine sl = new BasicStatusLine(version,200,"success");
+ HttpResponse response = new BasicHttpResponse(sl);
+ response.setHeader("Content-Disposition","filename");
+ DownloadCsarManager.getFilePath(response);
+ }
+ @Test
+ public void testUnzip(){
+ DownloadCsarManager.unzipCSAR("test.zip","/opt");
+ }
+
+ @Test
+ public void testJsonUtils(){
+ MockHttpServletRequest req = new MockHttpServletRequest();
+ req.setContent("[{'abc':123}]".getBytes());
+ VnfmJsonUtil.getJsonFromContexts(req);
+ }
+ @Test
+ public void testJsonUtils2(){
+ MockHttpServletRequest req = new MockHttpServletRequest();
+ req.setContent("{'abc':123}".getBytes());
+ VnfmJsonUtil.getJsonFromContexts(req);
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/FileUtil.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/FileUtil.java
new file mode 100644
index 00000000..10f24353
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/FileUtil.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.common;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+public class FileUtil {
+
+ public static String ReadFile(String path) {
+ File file = new File(path);
+ BufferedReader reader = null;
+ String laststr = "";
+ try {
+ reader = new BufferedReader(new FileReader(file));
+ String tempString = null;
+ while((tempString = reader.readLine()) != null) {
+ laststr = laststr + tempString;
+ }
+ reader.close();
+ } catch(IOException e) {
+ e.printStackTrace();
+ } finally {
+ if(reader != null) {
+ try {
+ reader.close();
+ } catch(IOException e1) {
+ }
+ }
+ }
+ return laststr;
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/ResultRequestUtilTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/ResultRequestUtilTest.java
new file mode 100644
index 00000000..1e8a9f3b
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/ResultRequestUtilTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.common;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.openo.nfvo.vnfmadapter.service.csm.connect.ConnectMgrVnfm;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+public class ResultRequestUtilTest {
+
+ @Test
+ public void callTestInternalError(){
+ new MockUp<ConnectMgrVnfm>(){
+ @Mock
+ public int connect(JSONObject vnfmObj) {
+ return 500;
+ }
+ };
+ JSONObject vnfmObject = new JSONObject();;
+ String path = "http://localhost:8080";
+ String methodName = "get";
+ String paramsJson = "";
+ JSONObject resp = ResultRequestUtil.call(vnfmObject, path, methodName, paramsJson);
+ assertTrue(resp.get("data").equals("connect fail."));
+ }
+
+ @Test
+ public void callTestConnectionErrot(){
+ new MockUp<ConnectMgrVnfm>(){
+ @Mock
+ public int connect(JSONObject vnfmObj) {
+ return 200;
+ }
+ };
+ JSONObject vnfmObject = new JSONObject();
+ vnfmObject.put("url", "/test/123");
+ String path = "http://localhost:8080";
+ String methodName = "get";
+ String paramsJson = "";
+ JSONObject resp = ResultRequestUtil.call(vnfmObject, path, methodName, paramsJson);
+ assertTrue(resp.get("data").equals("get connection error"));
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/VnfmUtilTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/VnfmUtilTest.java
new file mode 100644
index 00000000..fa60eb48
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/VnfmUtilTest.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.common;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+import org.openo.nfvo.vnfmadapter.common.servicetoken.VnfmRestfulUtil;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+public class VnfmUtilTest {
+
+ @Test
+ public void getVnfmByIdTestNullResp(){
+ JSONObject resp = VnfmUtil.getVnfmById("1234");
+ assertNull(resp);
+ }
+
+ @Test
+ public void getVnfmByIdTestSuccess(){
+ new MockUp<VnfmRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
+ RestfulResponse resp = new RestfulResponse();
+ resp.setStatus(200);
+ return resp;
+ }
+ };
+ JSONObject resp = VnfmUtil.getVnfmById("1234");
+ assertNotNull(resp);
+ }
+
+ @Test
+ public void getVnfmIdByIpTestNullResp(){
+ String resp = VnfmUtil.getVnfmIdByIp("localhost");
+ assertTrue("".equals(resp));
+ }
+
+ @Test
+ public void getVnfmIdByIpTestSuccess(){
+ new MockUp<VnfmRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
+ RestfulResponse resp = new RestfulResponse();
+ resp.setStatus(200);
+ JSONArray respArray = new JSONArray();
+ JSONObject obj = new JSONObject();
+ obj.put("url", "localhost");
+ obj.put("vnfmId", "1234");
+ respArray.add(obj);
+ resp.setResponseJson(respArray.toString());
+ return resp;
+ }
+ };
+ String resp = VnfmUtil.getVnfmIdByIp("localhost");
+ assertTrue("1234".equals(resp));
+ }
+
+ @Test
+ public void getVnfmIdByIpTestSuccessInvalidIP(){
+ new MockUp<VnfmRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
+ RestfulResponse resp = new RestfulResponse();
+ resp.setStatus(200);
+ JSONArray respArray = new JSONArray();
+ JSONObject obj = new JSONObject();
+ obj.put("url", "127.0.0.1");
+ obj.put("vnfmId", "1234");
+ respArray.add(obj);
+ resp.setResponseJson(respArray.toString());
+ return resp;
+ }
+ };
+ String resp = VnfmUtil.getVnfmIdByIp("localhost");
+ assertTrue("".equals(resp));
+ }
+ @Test
+ public void getVnfmIdByIpTestSuccessEmptyResp(){
+ new MockUp<VnfmRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
+ RestfulResponse resp = new RestfulResponse();
+ resp.setStatus(200);
+ JSONArray respArray = new JSONArray();
+ resp.setResponseJson(respArray.toString());
+ return resp;
+ }
+ };
+ String resp = VnfmUtil.getVnfmIdByIp("localhost");
+ assertTrue("".equals(resp));
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/servicetoken/HttpRestfulHelpTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/servicetoken/HttpRestfulHelpTest.java
new file mode 100644
index 00000000..a50dde98
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/servicetoken/HttpRestfulHelpTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.common.servicetoken;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.openo.baseservice.roa.util.restclient.Restful;
+
+/**
+ * <br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Aug 10, 2016
+ */
+public class HttpRestfulHelpTest {
+
+ @Test
+ public void testGetRestInstance() {
+ Restful rest = HttpRestfulHelp.getRestInstance(null, null);
+ assertNotNull(rest);
+ }
+
+ @Test
+ public void testGetRestInstance1() {
+ HttpRestfulHelp.getRestInstance(null, null);
+ Restful rest = HttpRestfulHelp.getRestInstance(null, null);
+ assertNotNull(rest);
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/servicetoken/VNFRestfulUtilTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/servicetoken/VNFRestfulUtilTest.java
new file mode 100644
index 00000000..3da7a813
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/servicetoken/VNFRestfulUtilTest.java
@@ -0,0 +1,322 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.common.servicetoken;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+import org.openo.nfvo.vnfmadapter.testutils.JsonUtil;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+/**
+ * <br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Aug 10, 2016
+ */
+public class VNFRestfulUtilTest {
+
+ @Test
+ public void getRestResByDefaultTestGet(){
+ String path="http://localhost:8080";
+ String methodNames = "get";
+ JSONObject bodyParam = new JSONObject();
+ bodyParam.put("id", "1234");
+ RestfulResponse resp = VNFRestfulUtil.getRestResByDefault(path, methodNames, bodyParam);
+ assertNotNull(resp);
+ }
+
+ @Test
+ public void getRestResByDefaultTestDelete(){
+ String path="http://localhost:8080";
+ String methodNames = "delete";
+ JSONObject bodyParam = new JSONObject();
+ bodyParam.put("id", "1234");
+ RestfulResponse resp = VNFRestfulUtil.getRestResByDefault(path, methodNames, bodyParam);
+ assertNotNull(resp);
+ }
+ @Test
+ public void getRestResByDefaultTestPost(){
+ String path="http://localhost:8080";
+ String methodNames = "post";
+ JSONObject bodyParam = new JSONObject();
+ bodyParam.put("id", "1234");
+ RestfulResponse resp = VNFRestfulUtil.getRestResByDefault(path, methodNames, bodyParam);
+ assertNotNull(resp);
+ }
+
+ @Test
+ public void sendReqToAppTestNullResp(){
+ String path="http://localhost:8080";
+ String methodNames = "get";
+ JSONObject bodyParam = new JSONObject();
+ bodyParam.put("id", "1234");
+ JSONObject resp = VNFRestfulUtil.sendReqToApp(path, methodNames, bodyParam);
+ assertNotNull(resp);
+ }
+ @Test
+ public void sendReqToAppTest(){
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) {
+ RestfulResponse resp = new RestfulResponse();
+ resp.setStatus(200);
+ Map<String,Object> map = new HashMap<>();
+ map.put("retCode", 1);
+ resp.setResponseJson(toJson(map));
+ return resp;
+ }
+ };
+ String path="http://localhost:8080/vnfdmgr/v1";
+ String methodNames = "get";
+ JSONObject bodyParam = new JSONObject();
+ bodyParam.put("vnfmInfo", new JSONObject().put("id", "6775"));
+ JSONObject resp = VNFRestfulUtil.sendReqToApp(path, methodNames, bodyParam);
+ assertNotNull(resp);
+ }
+
+ @Test
+ public void sendReqToAppTest2(){
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) {
+ RestfulResponse resp = new RestfulResponse();
+ resp.setStatus(200);
+ Map<String,Object> map = new HashMap<>();
+ map.put("retCode", -1);
+ resp.setResponseJson(toJson(map));
+ return resp;
+ }
+ };
+ String path="http://localhost:8080/vnfdmgr/v1";
+ String methodNames = "get";
+ JSONObject bodyParam = new JSONObject();
+ bodyParam.put("vnfmInfo", new JSONObject().put("id", "6775"));
+ JSONObject resp = VNFRestfulUtil.sendReqToApp(path, methodNames, bodyParam);
+ assertNotNull(resp);
+ }
+ @Test
+ public void sendReqToAppTest3(){
+ new MockUp<VNFRestfulUtil>(){
+ @Mock
+ public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) {
+ RestfulResponse resp = new RestfulResponse();
+ resp.setStatus(500);
+ Map<String,Object> map = new HashMap<>();
+ map.put("retCode", -1);
+ resp.setResponseJson(toJson(map));
+ return resp;
+ }
+ };
+ String path="http://localhost:8080/vnfdmgr/v1";
+ String methodNames = "get";
+ JSONObject bodyParam = new JSONObject();
+ bodyParam.put("vnfmInfo", new JSONObject().put("id", "6775"));
+ JSONObject resp = VNFRestfulUtil.sendReqToApp(path, methodNames, bodyParam);
+ assertNotNull(resp);
+ }
+
+ @Test
+ public void getRemoteResponseTest(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "delete");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+
+ boolean isNfvoApp = false;
+ RestfulResponse resp = VNFRestfulUtil.getRemoteResponse(paramsMap, "", "test123", isNfvoApp);
+ assertNull(resp);
+ }
+
+ @Test
+ public void getRemoteResponse2Test(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "get");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+
+ boolean isNfvoApp = false;
+ RestfulResponse resp = VNFRestfulUtil.getRemoteResponse(paramsMap, "", "test123", isNfvoApp);
+ assertNull(resp);
+ }
+
+ @Test
+ public void getRemoteResponse3Test(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "post");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+
+ boolean isNfvoApp = false;
+ RestfulResponse resp = VNFRestfulUtil.getRemoteResponse(paramsMap, "", "test123", isNfvoApp);
+ assertNull(resp);
+ }
+ @Test
+ public void getRemoteResponse4Test(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "put");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+
+ boolean isNfvoApp = false;
+ RestfulResponse resp = VNFRestfulUtil.getRemoteResponse(paramsMap, "", "test123", isNfvoApp);
+ assertNull(resp);
+ }
+ @Test
+ public void getRemoteResponse5Test(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "patch");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+ boolean isNfvoApp = false;
+ RestfulResponse resp = VNFRestfulUtil.getRemoteResponse(paramsMap, "", "test123", isNfvoApp);
+ assertNull(resp);
+ }
+ @Test
+ public void getRemoteResponseTrueTest(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "patch");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+ boolean isNfvoApp = true;
+ RestfulResponse resp = VNFRestfulUtil.getRemoteResponse(paramsMap, "", "test123", isNfvoApp);
+ assertNull(resp);
+ }
+
+ @Test
+ public void getRemoteResponseDeleteTest(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "delete");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+ RestfulResponse resp = VNFRestfulUtil.getRemoteResponse(paramsMap, "");
+ assertNull(resp);
+ }
+ @Test
+ public void getRemoteResponseGetTest(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "get");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+
+ RestfulResponse resp = VNFRestfulUtil.getRemoteResponse(paramsMap, "");
+ assertNull(resp);
+ }
+ @Test
+ public void getRemoteResponsePostTest(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "post");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+
+ RestfulResponse resp = VNFRestfulUtil.getRemoteResponse(paramsMap, "");
+ assertNull(resp);
+ }
+ @Test
+ public void getRemoteResponsePutTest(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "put");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+
+ RestfulResponse resp = VNFRestfulUtil.getRemoteResponse(paramsMap, "");
+ assertNull(resp);
+ }
+ @Test
+ public void getRemoteResponsePatchTest(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "patch");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+
+ RestfulResponse resp = VNFRestfulUtil.getRemoteResponse(paramsMap, "");
+ assertNull(resp);
+ }
+
+ @Test
+ public void getRemoteResponseNullTest(){
+
+ RestfulResponse resp = VNFRestfulUtil.getRemoteResponse(null, "");
+ assertNull(resp);
+ }
+ @Test
+ public void generateParamsMapTest(){
+ String url = "/test/123";
+ String methodType="get";
+ String path="http://localhost:8080";
+ String authMode="test";
+ Map<String, String> res = VNFRestfulUtil.generateParamsMap(url, methodType, path, authMode);
+ assertTrue(res.get("url").equals("/test/123"));
+ }
+
+ @Test
+ public void generateParams2MapTest(){
+ String url = "/test/123";
+ String methodType="get";
+ String path="http://localhost:8080";
+ Map<String, String> res = VNFRestfulUtil.generateParamsMap(url, methodType, path);
+ assertTrue(res.get("url").equals("/test/123"));
+ }
+ @Test
+ public void getResultToVnfmTest(){
+ JSONObject vnfmInfo= new JSONObject();
+ vnfmInfo.put("retCode", 1);
+ String vnfmId="123";
+ JSONObject res = VNFRestfulUtil.getResultToVnfm(vnfmInfo, vnfmId);
+ assertNotNull(res);
+ }
+
+ @Test
+ public void getResultToVnfm2Test(){
+ JSONObject vnfmInfo= new JSONObject();
+ vnfmInfo.put("retCode", -1);
+ String vnfmId="123";
+ JSONObject res = VNFRestfulUtil.getResultToVnfm(vnfmInfo, vnfmId);
+ assertNotNull(res);
+ }
+
+ public static String toJson(Map o) {
+ try {
+ return JsonUtil.marshal(o);
+ } catch (IOException e) {
+ return "";
+ }
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java
new file mode 100644
index 00000000..d03b39c5
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java
@@ -0,0 +1,240 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.common.servicetoken;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+import org.openo.nfvo.vnfmadapter.service.constant.Constant;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+public class VnfmRestfulUtilTest {
+ @Test
+ public void testGetRestResByDefaultByNull() {
+ RestfulResponse result = VnfmRestfulUtil.getRestResByDefault("path", "methodNames", new JSONObject());
+ assertNull(result);
+ }
+
+ @Test
+ public void testGetRestResByDefaultByGet() {
+ RestfulResponse result = VnfmRestfulUtil.getRestResByDefault("path", "get", new JSONObject());
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetRestResByDefaultByPut() {
+ RestfulResponse result = VnfmRestfulUtil.getRestResByDefault("path", "put", new JSONObject());
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testSendReqToApp() {
+ new MockUp<VnfmRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) {
+ RestfulResponse restfulResponse = new RestfulResponse();
+ restfulResponse.setStatus(Constant.HTTP_OK);
+ String responseString = "{\"retCode\":1,\"data\":\"success\"}";
+ restfulResponse.setResponseJson(responseString);
+ return restfulResponse;
+ }
+ };
+ JSONObject result = VnfmRestfulUtil.sendReqToApp("path", "put", new JSONObject());
+ assertEquals(Constant.REST_SUCCESS, result.get("retCode"));
+ }
+
+ @Test
+ public void testSendReqToAppByErrorMsg() {
+ new MockUp<VnfmRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) {
+ RestfulResponse restfulResponse = new RestfulResponse();
+ restfulResponse.setStatus(Constant.HTTP_OK);
+ String responseString = "{\"retCode\":-1,\"data\":\"fail\",\"msg\":\"fail\"}";
+ restfulResponse.setResponseJson(responseString);
+ return restfulResponse;
+ }
+ };
+ JSONObject result = VnfmRestfulUtil.sendReqToApp("path", "put", new JSONObject());
+ assertEquals(Constant.REST_FAIL, result.get("retCode"));
+ }
+
+ @Test
+ public void testSendReqToAppByError() {
+ new MockUp<VnfmRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) {
+ RestfulResponse restfulResponse = new RestfulResponse();
+ restfulResponse.setStatus(Constant.HTTP_OK);
+ String responseString = "{\"retCode\":-1,\"data\":\"fail\"}";
+ restfulResponse.setResponseJson(responseString);
+ return restfulResponse;
+ }
+ };
+ JSONObject result = VnfmRestfulUtil.sendReqToApp("path", "put", new JSONObject());
+ assertEquals(Constant.REST_FAIL, result.get("retCode"));
+ }
+
+ @Test
+ public void testSendReqToAppByFail() {
+ JSONObject result = VnfmRestfulUtil.sendReqToApp("path", "put", new JSONObject());
+ assertEquals(Constant.REST_FAIL, result.get("retCode"));
+ }
+
+ @Test
+ public void testSendReqToAppByVnfmInfo() {
+ JSONObject paraJson = new JSONObject();
+ JSONObject vnfmObj = new JSONObject();
+ vnfmObj.put("id", "id");
+ paraJson.put("vnfmInfo", vnfmObj);
+ JSONObject result = VnfmRestfulUtil.sendReqToApp("path", "put", paraJson);
+ assertEquals(Constant.REST_FAIL, result.get("retCode"));
+ }
+
+ @Test
+ public void testGenerateParamsMap2() {
+ Map<String, String> result = VnfmRestfulUtil.generateParamsMap("url", "methodType", "path", "authMode");
+ Map<String, String> paramsMap = new HashMap<String, String>(6);
+ paramsMap.put("url", "url");
+ paramsMap.put("methodType", "methodType");
+ paramsMap.put("path", "path");
+ paramsMap.put("authMode", "authMode");
+ assertEquals(paramsMap, result);
+ }
+ @Test
+ public void getRemoteResponseTestGet(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "get");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+ boolean isNfvoApp = false;
+ RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse(paramsMap, "", "test123", isNfvoApp);
+ assertNull(resp);
+ }
+ @Test
+ public void getRemoteResponseTestGetTrueNfvo(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "get");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+ boolean isNfvoApp = true;
+ RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse(paramsMap, "", "test123", isNfvoApp);
+ assertNull(resp);
+ }
+ @Test
+ public void getRemoteResponseTestPost(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "post");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+
+ boolean isNfvoApp = false;
+ RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse(paramsMap, "", "test123", isNfvoApp);
+ assertNull(resp);
+ }
+ @Test
+ public void getRemoteResponseTestPut(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "put");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+
+ boolean isNfvoApp = false;
+ RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse(paramsMap, "", "test123", isNfvoApp);
+ assertNull(resp);
+ }
+
+ @Test
+ public void getRemoteResponseTestDelete(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "delete");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+
+ boolean isNfvoApp = false;
+ RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse(paramsMap, "", "test123", isNfvoApp);
+ assertNull(resp);
+ }
+
+ @Test
+ public void getRemoteResponse2TestDelete(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "delete");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+ RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse("/test/123", "", "test123");
+ assertNull(resp);
+ }
+ @Test
+ public void getRemoteResponse2TestGet(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "get");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+ RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse("/test/123", "", "test123");
+ assertNull(resp);
+ }
+ @Test
+ public void getRemoteResponse2Testput(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "put");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "test");
+ RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse("/test/123", "", "test123");
+ assertNull(resp);
+ }
+ @Test
+ public void getRemoteResponse2TestPost(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "put");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "post");
+ RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse("/test/123", "", "test123");
+ assertNull(resp);
+ }
+ @Test
+ public void getRemoteResponse2TestPatch(){
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/123");
+ paramsMap.put("methodType", "patch");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("authMode", "post");
+ RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse("/test/123", "", "test123");
+ assertNull(resp);
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/activator/RoaVnfmServicePostProcessorTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/activator/RoaVnfmServicePostProcessorTest.java
new file mode 100644
index 00000000..82d8c2b4
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/activator/RoaVnfmServicePostProcessorTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.nfvo.vnfmadapter.service.activator;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openo.nfvo.vnfmadapter.service.api.internalsvc.impl.VnfmAdapterMgrService;
+
+/**
+ * Created by QuanZhong on 2017/3/17.
+ */
+public class RoaVnfmServicePostProcessorTest {
+ @Test
+ public void testPostProcessAfterInitialization(){
+ RoaVnfmServicePostProcessor dm = new RoaVnfmServicePostProcessor();
+ dm.postProcessAfterInitialization(new VnfmAdapterMgrService(),"abc");
+ Assert.assertTrue(true);
+ }
+ @Test
+ public void testPostProcessAfterInitialization2(){
+ RoaVnfmServicePostProcessor dm = new RoaVnfmServicePostProcessor();
+ dm.postProcessAfterInitialization(null,"abc");
+ Assert.assertTrue(true);
+ }
+
+ @Test
+ public void testpostProcessBeforeDestruction(){
+ RoaVnfmServicePostProcessor dm = new RoaVnfmServicePostProcessor();
+ dm.postProcessBeforeDestruction(new VnfmAdapterMgrService(),"abc");
+ Assert.assertTrue(true);
+ }
+
+ @Test
+ public void testpostProcessBeforeInitialization(){
+ RoaVnfmServicePostProcessor dm = new RoaVnfmServicePostProcessor();
+ dm.postProcessBeforeInitialization(new VnfmAdapterMgrService(),"abc");
+ Assert.assertTrue(true);
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/activator/TestRoaVnfmService2DriverMgr.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/activator/TestRoaVnfmService2DriverMgr.java
new file mode 100644
index 00000000..f75f4e44
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/activator/TestRoaVnfmService2DriverMgr.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.nfvo.vnfmadapter.service.activator;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openo.nfvo.vnfmadapter.service.api.internalsvc.impl.VnfmAdapter2DriverMgrService;
+
+/**
+ * Created by QuanZhong on 2017/3/17.
+ */
+public class TestRoaVnfmService2DriverMgr {
+ @Test
+ public void testPostProcessAfterInitialization(){
+ RoaVnfmService2DriverMgr dm = new RoaVnfmService2DriverMgr();
+ dm.postProcessAfterInitialization(new VnfmAdapter2DriverMgrService(),"abc");
+ Assert.assertTrue(true);
+ }
+ @Test
+ public void testPostProcessAfterInitialization2(){
+ RoaVnfmService2DriverMgr dm = new RoaVnfmService2DriverMgr();
+ dm.postProcessAfterInitialization(null,"abc");
+ Assert.assertTrue(true);
+ }
+
+ @Test
+ public void testpostProcessBeforeDestruction(){
+ RoaVnfmService2DriverMgr dm = new RoaVnfmService2DriverMgr();
+ dm.postProcessBeforeDestruction(new VnfmAdapter2DriverMgrService(),"abc");
+ Assert.assertTrue(true);
+ }
+
+ @Test
+ public void testpostProcessBeforeInitialization(){
+ RoaVnfmService2DriverMgr dm = new RoaVnfmService2DriverMgr();
+ dm.postProcessBeforeInitialization(new VnfmAdapter2DriverMgrService(),"abc");
+ Assert.assertTrue(true);
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/adapter/impl/AdapterResourceManagerTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/adapter/impl/AdapterResourceManagerTest.java
new file mode 100644
index 00000000..895c167b
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/adapter/impl/AdapterResourceManagerTest.java
@@ -0,0 +1,311 @@
+/*
+ * Copyright 2016-2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.adapter.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+import org.openo.nfvo.vnfmadapter.common.DownloadCsarManager;
+import org.openo.nfvo.vnfmadapter.common.servicetoken.VNFRestfulUtil;
+import org.openo.nfvo.vnfmadapter.testutils.JsonUtil;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONException;
+import net.sf.json.JSONObject;
+
+public class AdapterResourceManagerTest {
+
+ AdapterResourceManager manager = null;
+
+ @Before
+ public void setUp() {
+ manager = new AdapterResourceManager();
+ }
+
+ @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() {
+ JSONObject vnfpkg = new JSONObject();
+ Map<String, String> paramsMap = new HashMap<>();
+ JSONObject res = manager.uploadVNFPackage(null, paramsMap);
+ assertTrue(res != null);
+
+ }
+
+ @Test
+ public void uploadVNFPackageTestJsonException3() {
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ Map<String, String> paramsMap = new HashMap<>();
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("csarid and vnfmid are null."));
+
+ }
+
+ @Test
+ public void uploadVNFPackageTestEmptyParam() {
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ Map<String, String> paramsMap = new HashMap<>();
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("csarid and vnfmid are null."));
+
+ }
+
+ @Test
+ 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."));
+
+ }
+
+ @Test
+ public void uploadVNFPackageTestInvalidCsrid() {
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("csarid is null."));
+
+ }
+
+ @Test
+ public void uploadVNFPackageTestInvalidCsrid2() {
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", null);
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("csarid is null."));
+
+ }
+
+ @Test
+ public void uploadVNFPackageTestInvalidVnfmid() {
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", null);
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("vnfmid is null."));
+
+ }
+
+ @Test
+ public void uploadVNFPackageTestInvalidVnfmid2() {
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("csarid", "csarid123");
+ paramsMap.put("vnfmid", "");
+ JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap);
+ assertTrue(res.get("reason").equals("vnfmid is null."));
+
+ }
+
+ @Test
+ public void uploadVNFPackageTestNullResp() {
+ JSONObject vnfpkg = new JSONObject();
+ vnfpkg.put("name", "test");
+ 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 downloadCsarTestNullUrl() {
+ String url = null;
+ String filePath = null;
+ JSONObject res = manager.downloadCsar(url, filePath);
+ assertTrue(res.get("reason").equals("url is null."));
+ }
+
+ @Test
+ public void downloadCsarTestEmptyUrl() {
+ String url = "";
+ String filePath = null;
+ JSONObject res = manager.downloadCsar(url, filePath);
+ assertTrue(res.get("reason").equals("url is null."));
+ }
+
+ @Test
+ public void downloadCsarTestNullFilePath() {
+ String url = "http://localhost:8080";
+ String filePath = null;
+ JSONObject res = manager.downloadCsar(url, filePath);
+ assertTrue(res.get("reason").equals("downloadUrl filePath is null."));
+ }
+
+ @Test
+ public void downloadCsarTestEmptyFilePath() {
+ String url = "http://localhost:8080";
+ String filePath = "";
+ JSONObject res = manager.downloadCsar(url, filePath);
+ assertTrue(res.get("reason").equals("downloadUrl filePath is null."));
+ }
+
+ @Test
+ public void getVnfmConnInfoTestSuccess() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse resp = new RestfulResponse();
+ resp.setStatus(200);
+ Map<String, String> objMap = new HashMap<String, String>();
+ objMap.put("id", "test123");
+
+ String responseString = toJson(objMap);
+ resp.setResponseJson(responseString);
+ return resp;
+ }
+
+ };
+ Map<String, String> paramsMap = new HashMap<String, String>();
+ JSONObject res = manager.getVnfmConnInfo(paramsMap);
+ assertTrue(res.get("id").equals("test123"));
+ }
+
+ @Test
+ public void getVnfmConnInfoTestNullResp() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+
+ return null;
+ }
+
+ };
+ Map<String, String> paramsMap = new HashMap<String, String>();
+ JSONObject res = manager.getVnfmConnInfo(paramsMap);
+ assertTrue(res.get("reason").equals("RestfulResponse is null."));
+ }
+
+ @Test
+ public void getVnfmConnInfoTestServerError() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse resp = new RestfulResponse();
+ resp.setStatus(500);
+ Map<String, String> objMap = new HashMap<String, String>();
+ objMap.put("id", "test123");
+
+ String responseString = toJson(objMap);
+ resp.setResponseJson(responseString);
+ return resp;
+ }
+
+ };
+ Map<String, String> paramsMap = new HashMap<String, String>();
+ JSONObject res = manager.getVnfmConnInfo(paramsMap);
+ assertTrue(res.get("reason").equals("ESR return fail."));
+ }
+
+ @Test
+ public void uploadTestInternalError() {
+ JSONObject vnfpackage = new JSONObject();
+ String vnfmurl = "http://localhost";
+ String conntoken = "test";
+ JSONObject res = manager.upload(vnfpackage, vnfmurl, conntoken);
+ assertEquals(res.get("retCode"), 500);
+ }
+
+ public static String toJson(Map o) {
+ try {
+ return JsonUtil.marshal(o);
+ } catch(IOException e) {
+ return "";
+ }
+ }
+
+ @Test
+ public void testGetAllCloud(){
+ String url = null;
+ manager.getAllCloud(url,null);
+ }
+
+ @Test
+ public void testGetAllCloud2(){
+ String url = "http://127.0.0.1:31943";
+ manager.getAllCloud(url,null);
+ }
+ @Test
+ public void testUnzipCSAR(){
+ manager.unzipCSAR(null,null);
+ }
+ @Test
+ public void testUnzipCSAR2(){
+ manager.unzipCSAR("vCpe.zip",null);
+ }
+ @Test
+ public void testUnzipCSAR3(){
+ manager.unzipCSAR("vCpe.zip","/opt");
+ }
+ @Test
+ public void testUnzipCSAR4(){
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public int unzipCSAR(String fileName,String filePath){
+ return 0;
+ }
+ };
+ manager.unzipCSAR("vCpe.zip","/opt");
+ }
+ @Test
+ public void testUnzipCSAR5(){
+ new MockUp<DownloadCsarManager>(){
+ @Mock
+ public int unzipCSAR(String fileName,String filePath){
+ return -1;
+ }
+ };
+ manager.unzipCSAR("vCpe.zip","/opt");
+ }
+
+ @Test
+ public void testGetVnfdVersion(){
+ manager.getVnfdVersion("http://","127.0.0.1","token");
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/adapter/impl/Driver2MSBManagerTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/adapter/impl/Driver2MSBManagerTest.java
new file mode 100644
index 00000000..48a04118
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/adapter/impl/Driver2MSBManagerTest.java
@@ -0,0 +1,281 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.adapter.impl;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+import org.openo.nfvo.vnfmadapter.common.servicetoken.VNFRestfulUtil;
+import org.openo.nfvo.vnfmadapter.testutils.JsonUtil;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Jan 24, 2017
+ */
+public class Driver2MSBManagerTest {
+
+ Driver2MSBManager manager = new Driver2MSBManager();
+
+ Map<String, String> vim = new HashMap<String, String>();
+
+ @Before
+ public void setUp() {
+ vim.put("vimId", "123");
+ vim.put("name", "123");
+ vim.put("url", "123");
+ vim.put("userName", "123");
+ vim.put("password", "123");
+ vim.put("type", "123");
+ vim.put("version", "123");
+ }
+
+ @Test
+ public void registerDriverTestNullResp() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+
+ return null;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.registerDriver(paramsMap, new JSONObject());
+ assertTrue(obj.get("reason").equals("RestfulResponse is null."));
+ }
+
+ @Test
+ public void registerDriverCreateSuccess() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+ response.setStatus(201);
+
+ String vimStr = toJson(vim);
+ response.setResponseJson(vimStr);
+ return response;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.registerDriver(paramsMap, new JSONObject());
+ assertTrue(Integer.valueOf(obj.get("retCode").toString()) == 201);
+ }
+
+ @Test
+ public void registerDriverOkSuccess() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+ response.setStatus(200);
+
+ String vimStr = toJson(vim);
+ response.setResponseJson(vimStr);
+ return response;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.registerDriver(paramsMap, new JSONObject());
+ assertTrue(Integer.valueOf(obj.get("retCode").toString()) == -1);
+ }
+
+ @Test
+ public void registerDriverTestInvalidParams() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+ response.setStatus(415);
+
+ String vimStr = toJson(vim);
+ response.setResponseJson(vimStr);
+ return response;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.registerDriver(paramsMap, new JSONObject());
+ assertTrue(obj.get("reason").equals("MSB return fail,invalid parameters."));
+ }
+
+ @Test
+ public void registerDriverTestInternalError() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+ response.setStatus(500);
+
+ String vimStr = toJson(vim);
+ response.setResponseJson(vimStr);
+ return response;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.registerDriver(paramsMap, new JSONObject());
+ assertTrue(obj.get("reason").equals("MSB return fail,internal system error."));
+ }
+
+ @Test
+ public void unregisterDriverTestNullResp() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+
+ return null;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.unregisterDriver(paramsMap);
+ assertTrue(obj.get("reason").equals("RestfulResponse is null."));
+ }
+
+ @Test
+ public void unregisterDriverDeleteSuccess() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+ response.setStatus(204);
+
+ String vimStr = toJson(vim);
+ response.setResponseJson(vimStr);
+ return response;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.unregisterDriver(paramsMap);
+ assertTrue(Integer.valueOf(obj.get("retCode").toString()) == 204);
+ }
+
+ @Test
+ public void unregisterDriverResourceNotFound() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+ response.setStatus(404);
+
+ String vimStr = toJson(vim);
+ response.setResponseJson(vimStr);
+ return response;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.unregisterDriver(paramsMap);
+ assertTrue(obj.get("reason").equals("MSB return fail,can't find the service instance."));
+ }
+
+ @Test
+ public void unregisterDriverTestInvalidParams() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+ response.setStatus(415);
+
+ String vimStr = toJson(vim);
+ response.setResponseJson(vimStr);
+ return response;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.unregisterDriver(paramsMap);
+ assertTrue(obj.get("reason").equals("MSB return fail,invalid parameters."));
+ }
+
+ @Test
+ public void unregisterDriverTestInternalError() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+ response.setStatus(500);
+
+ String vimStr = toJson(vim);
+ response.setResponseJson(vimStr);
+ return response;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.unregisterDriver(paramsMap);
+ assertTrue(obj.get("reason").equals("MSB return fail,internal system error."));
+ }
+
+ public static String toJson(Map o) {
+ try {
+ return JsonUtil.marshal(o);
+ } catch(IOException e) {
+ return "";
+ }
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/adapter/impl/VnfmAdapter2DriverManagerTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/adapter/impl/VnfmAdapter2DriverManagerTest.java
new file mode 100644
index 00000000..f79fa704
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/adapter/impl/VnfmAdapter2DriverManagerTest.java
@@ -0,0 +1,281 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.adapter.impl;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+import org.openo.nfvo.vnfmadapter.common.servicetoken.VNFRestfulUtil;
+import org.openo.nfvo.vnfmadapter.testutils.JsonUtil;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Jan 24, 2017
+ */
+public class VnfmAdapter2DriverManagerTest {
+
+ VnfmAdapter2DriverManager manager = new VnfmAdapter2DriverManager();
+
+ Map<String, String> vim = new HashMap<String, String>();
+
+ @Before
+ public void setUp() {
+ vim.put("vimId", "123");
+ vim.put("name", "123");
+ vim.put("url", "123");
+ vim.put("userName", "123");
+ vim.put("password", "123");
+ vim.put("type", "123");
+ vim.put("version", "123");
+ }
+
+ @Test
+ public void registerDriverTestNullResp() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+
+ return null;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.registerDriver(paramsMap, new JSONObject());
+ assertTrue(obj.get("reason").equals("RestfulResponse is null."));
+ }
+
+ @Test
+ public void registerDriverCreateSuccess() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+ response.setStatus(201);
+
+ String vimStr = toJson(vim);
+ response.setResponseJson(vimStr);
+ return response;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.registerDriver(paramsMap, new JSONObject());
+ assertTrue(Integer.valueOf(obj.get("retCode").toString()) == 201);
+ }
+
+ @Test
+ public void registerDriverOkSuccess() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+ response.setStatus(200);
+
+ String vimStr = toJson(vim);
+ response.setResponseJson(vimStr);
+ return response;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.registerDriver(paramsMap, new JSONObject());
+ assertTrue(Integer.valueOf(obj.get("retCode").toString()) == -1);
+ }
+
+ @Test
+ public void registerDriverTestInvalidParams() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+ response.setStatus(415);
+
+ String vimStr = toJson(vim);
+ response.setResponseJson(vimStr);
+ return response;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.registerDriver(paramsMap, new JSONObject());
+ assertTrue(obj.get("reason").equals("DriverManager return fail,invalid parameters."));
+ }
+
+ @Test
+ public void registerDriverTestInternalError() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+ response.setStatus(500);
+
+ String vimStr = toJson(vim);
+ response.setResponseJson(vimStr);
+ return response;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.registerDriver(paramsMap, new JSONObject());
+ assertTrue(obj.get("reason").equals("DriverManager return fail,internal system error."));
+ }
+
+ @Test
+ public void unregisterDriverTestNullResp() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+
+ return null;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.unregisterDriver(paramsMap);
+ assertTrue(obj.get("reason").equals("RestfulResponse is null."));
+ }
+
+ @Test
+ public void unregisterDriverDeleteSuccess() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+ response.setStatus(204);
+
+ String vimStr = toJson(vim);
+ response.setResponseJson(vimStr);
+ return response;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.unregisterDriver(paramsMap);
+ assertTrue(Integer.valueOf(obj.get("retCode").toString()) == 204);
+ }
+
+ @Test
+ public void unregisterDriverResourceNotFound() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+ response.setStatus(404);
+
+ String vimStr = toJson(vim);
+ response.setResponseJson(vimStr);
+ return response;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.unregisterDriver(paramsMap);
+ assertTrue(obj.get("reason").equals("DriverManager return fail,can't find the service instance."));
+ }
+
+ @Test
+ public void unregisterDriverTestInvalidParams() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+ response.setStatus(415);
+
+ String vimStr = toJson(vim);
+ response.setResponseJson(vimStr);
+ return response;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.unregisterDriver(paramsMap);
+ assertTrue(obj.get("reason").equals("DriverManager return fail,invalid parameters."));
+ }
+
+ @Test
+ public void unregisterDriverTestInternalError() {
+ new MockUp<VNFRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse response = new RestfulResponse();
+ response.setStatus(500);
+
+ String vimStr = toJson(vim);
+ response.setResponseJson(vimStr);
+ return response;
+ }
+ };
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/test/openoapi");
+ paramsMap.put("path", "http://localhost:8080");
+ paramsMap.put("methodType", "get");
+ JSONObject obj = manager.unregisterDriver(paramsMap);
+ assertTrue(obj.get("reason").equals("DriverManager return fail,internal system error."));
+ }
+
+ public static String toJson(Map o) {
+ try {
+ return JsonUtil.marshal(o);
+ } catch(IOException e) {
+ return "";
+ }
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java
new file mode 100644
index 00000000..e3393b42
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.ai.internalsvc.impl;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.junit.Test;
+import org.openo.nfvo.vnfmadapter.service.api.internalsvc.impl.VnfmAdapter2DriverMgrService;
+
+import java.io.IOException;
+
+/**
+ * Created by QuanZhong on 2017/3/20.
+ */
+public class VnfmAdapter2DriverMgrServiceTest {
+
+ @Test
+ public void testRegister(){
+ VnfmAdapter2DriverMgrService mgr = new VnfmAdapter2DriverMgrService();
+ mgr.register();
+ mgr.unregister();
+ }
+
+ @Test
+ public void testRegister2(){
+ new MockUp<VnfmAdapter2DriverMgrService>(){
+ @Mock
+ public String readVnfmAdapterInfoFromJson() throws IOException {
+ return "{'url':'http://127.0.0.1'}";
+
+ }
+ };
+ VnfmAdapter2DriverMgrService mgr = new VnfmAdapter2DriverMgrService();
+ mgr.register();
+ mgr.unregister();
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java
new file mode 100644
index 00000000..2a6b7444
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.ai.internalsvc.impl;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+import org.junit.Test;
+import org.openo.nfvo.vnfmadapter.service.api.internalsvc.impl.VnfmAdapterMgrService;
+import org.openo.nfvo.vnfmadapter.service.process.VnfMgr;
+
+import java.io.IOException;
+
+/**
+ * Created by QuanZhong on 2017/3/20.
+ */
+public class VnfmAdapterMgrServiceTest {
+ @Test
+ public void testRegister(){
+ new MockUp<VnfmAdapterMgrService>(){
+
+ @Mock
+ public String readVnfmAdapterInfoFromJson() throws IOException {
+ return "{'abc':'123'}";
+ }
+ };
+ VnfmAdapterMgrService mgr = new VnfmAdapterMgrService();
+ mgr.register();
+
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/constant/TestConstant.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/constant/TestConstant.java
new file mode 100644
index 00000000..f2142f14
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/constant/TestConstant.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.nfvo.vnfmadapter.service.constant;
+
+import junit.framework.Assert;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.openo.nfvo.vnfmadapter.service.constant.Constant.AUTHLIST;
+
+/**
+ * Created by QuanZhong on 2017/3/17.
+ */
+public class TestConstant {
+ @Test
+ public void testCreate(){
+ List<String> authlist = AUTHLIST;
+ authlist.contains("abc");
+ String url = UrlConstant.PORT_COMMON;
+ authlist.contains(url);
+ String abc = ParamConstants.CONNECTMGR_CONNECT;
+ authlist.contains(abc);
+ Assert.assertTrue(true);
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/api/ConnectInfoTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/api/ConnectInfoTest.java
new file mode 100644
index 00000000..83a396df
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/api/ConnectInfoTest.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.csm.api;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class ConnectInfoTest {
+
+ @Test
+ public void constructorTestNullUrl(){
+ ConnectInfo info = new ConnectInfo(null);
+ assertTrue(info.getUrl().equals(""));
+ }
+ @Test
+ public void constructorTestValidUrl(){
+ ConnectInfo info = new ConnectInfo("localhost");
+ assertTrue(info.getUrl().equals("localhost"));
+ }
+ @Test
+ public void constructorTest2NullData(){
+ ConnectInfo info = new ConnectInfo(null,null,null,null);
+ assertTrue(info.getUrl().equals("") && info.getUserName().equals("")
+ && info.getUserPwd().equals("") && info.getAuthenticateMode().equals(""));
+ }
+ @Test
+ public void constructorTestValidData(){
+ ConnectInfo info = new ConnectInfo("localhost","user","password","auth");
+ assertTrue(info.getUrl().equals("localhost") && info.getUserName().equals("user")
+ && info.getUserPwd().equals("password") && info.getAuthenticateMode().equals("auth"));
+ }
+ @Test
+ public void hashCodeTest(){
+ ConnectInfo info1 = new ConnectInfo("localhost","user","password","auth");
+ ConnectInfo info2 = new ConnectInfo("localhost","user","password","auth");
+ assertTrue(info1.hashCode() == info2.hashCode());
+ }
+
+ @Test
+ public void equalsTest(){
+ ConnectInfo info1 = new ConnectInfo("localhost","user","password","auth");
+ ConnectInfo info2 = new ConnectInfo("localhost","user","password","auth");
+ assertTrue(info1.equals(info2));
+ }
+ @Test
+ public void equalsTest2(){
+ ConnectInfo info1 = new ConnectInfo("localhost","user","password","auth");
+ assertTrue(info1.equals(info1));
+ }
+ @Test
+ public void equalsTest3(){
+ ConnectInfo info1 = new ConnectInfo("localhost","user","password","auth");
+ assertTrue(!info1.equals(null));
+ }
+ @Test
+ public void equalsTest4(){
+ ConnectInfo info1 = new ConnectInfo("localhost","user","password","auth");
+ assertTrue(!info1.equals(new Object()));
+ }
+ @Test
+ public void equalsTest5(){
+ ConnectInfo info1 = new ConnectInfo(null,"user","password","auth");
+ ConnectInfo info2 = new ConnectInfo("localhost","user","password","auth");
+ assertTrue(!info1.equals(info2));
+ }
+ @Test
+ public void equalsTest6(){
+ ConnectInfo info1 = new ConnectInfo("testurl","user","password","auth");
+ ConnectInfo info2 = new ConnectInfo("localhost","user","password","auth");
+ assertTrue(!info1.equals(info2));
+ }
+
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/AbstractSslContextTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/AbstractSslContextTest.java
new file mode 100644
index 00000000..20ed64d7
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/AbstractSslContextTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.csm.connect;
+
+import net.sf.json.JSONObject;
+import org.junit.Test;
+
+/**
+ * Created by QuanZhong on 2017/3/20.
+ */
+public class AbstractSslContextTest {
+ @Test
+ public void createKeyManagerTest(){
+ AbstractSslContext asc = new AbstractSslContext();
+ JSONObject json = new JSONObject();
+ json.put("keyStore","");
+ json.put("keyStorePass","");
+ json.put("keyStoreType","");
+ asc.createKeyManager(json);
+ }
+
+ @Test
+ public void createTrustManagerTest(){
+ AbstractSslContext asc = new AbstractSslContext();
+ JSONObject json = new JSONObject();
+ json.put("trustStore","");
+ json.put("trustStorePass","");
+ json.put("trustStoreType","");
+ asc.createTrustManager(json);
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/HttpRequestsTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/HttpRequestsTest.java
new file mode 100644
index 00000000..3a0a8ec3
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/HttpRequestsTest.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.csm.connect;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.httpclient.Header;
+import org.junit.Test;
+import org.openo.nfvo.vnfmadapter.common.VnfmException;
+
+public class HttpRequestsTest {
+
+ String authenticateMode = "test";
+ HttpRequests.Builder builder = new HttpRequests.Builder(authenticateMode);
+
+ @Test
+ public void addHeaderTest(){
+ builder.addHeader("id", "1234");
+ assertTrue(true);
+ }
+ @Test
+ public void addHeadersTest(){
+ Header header = new Header();
+ builder.addHeaders(header, header);
+ assertNotNull(builder);
+ }
+ @Test
+ public void addHeadersListTest(){
+ List<Header> list = new ArrayList<>();
+ Header header = new Header();
+ list.add(header);
+ builder.addHeaders(list);
+ assertNotNull(builder);
+ }
+
+ @Test(expected = VnfmException.class)
+ public void setUrlTestException() throws VnfmException{
+ String url=null;
+ String path=null;
+ builder.setUrl(url, path);
+ }
+ @Test(expected = VnfmException.class)
+ public void setUrlTestException2() throws VnfmException{
+ String url="";
+ String path=null;
+ builder.setUrl(url, path);
+ }
+
+ @Test(expected = VnfmException.class)
+ public void setUrlTestNormal() throws VnfmException{
+ String url="/test/123";
+ String path="http://localhost:8080";
+ builder.setUrl(url, path);
+ }
+
+ @Test(expected = VnfmException.class)
+ public void setUrl2TestException() throws VnfmException{
+ String url=null;
+ String path=null;
+ builder.setUrl(url, path,101);
+ }
+ @Test(expected = VnfmException.class)
+ public void setUrl2TestException2() throws VnfmException{
+ String url="";
+ String path=null;
+ builder.setUrl(url, path,101);
+ }
+
+ @Test(expected = VnfmException.class)
+ public void setUrl2TestNormal() throws VnfmException{
+ String url="/test/123";
+ String path="http://localhost:8080";
+ builder.setUrl(url, path,101);
+ }
+ @Test(expected = Exception.class)
+ public void requestTestException(){
+ String res = builder.request();
+ assertNotNull(res);
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/SslAnonymousSocketTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/SslAnonymousSocketTest.java
new file mode 100644
index 00000000..23f3280d
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/SslAnonymousSocketTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.csm.connect;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+
+import org.apache.commons.httpclient.ConnectTimeoutException;
+import org.apache.commons.httpclient.params.HttpConnectionParams;
+import org.junit.Test;
+
+public class SslAnonymousSocketTest {
+
+ @Test(expected = IOException.class)
+ public void createSocketTestException() throws IOException, ConnectTimeoutException {
+ String host= "localhost";
+ int port = 29912;
+ InetAddress localAddress = null;
+ int localPort = 4859;
+ HttpConnectionParams params = null;
+ SslAnonymousSocket sslsocket = new SslAnonymousSocket();
+ Socket socket = sslsocket.createSocket(host, port, localAddress, localPort, params);
+ }
+
+ @Test(expected = Exception.class)
+ public void createSocketTestException2() throws IOException, ConnectTimeoutException {
+ String host= "localhost";
+ int port = 29912;
+ InetAddress localAddress = null;
+ int localPort = 4859;
+ HttpConnectionParams params = new HttpConnectionParams();
+ SslAnonymousSocket sslsocket = new SslAnonymousSocket();
+ Socket socket = sslsocket.createSocket(host, port, localAddress, localPort, params);
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/SslCertificateSocketTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/SslCertificateSocketTest.java
new file mode 100644
index 00000000..80156a02
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/SslCertificateSocketTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.csm.connect;
+
+import org.apache.commons.httpclient.params.HttpConnectionParams;
+import org.junit.Test;
+import org.openo.nfvo.vnfmadapter.common.VnfmException;
+
+import java.io.IOException;
+
+/**
+ * Created by QuanZhong on 2017/3/20.
+ */
+public class SslCertificateSocketTest {
+ @Test
+ public void initTest(){
+ SslCertificateSocket socket = new SslCertificateSocket();
+ try {
+ socket.init();
+ } catch (VnfmException e) {
+ e.printStackTrace();
+ }
+ }
+ @Test
+ public void createSocketTest(){
+ SslCertificateSocket socket = new SslCertificateSocket();
+ try {
+ socket.createSocket("http://127.0.0.1",1234);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void createSocketTest2(){
+ SslCertificateSocket socket = new SslCertificateSocket();
+ try {
+ socket.createSocket("http://127.0.0.1",1234,null,4321,null);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ @Test
+ public void createSocketTest3(){
+ SslCertificateSocket socket = new SslCertificateSocket();
+ try {
+ HttpConnectionParams params = new HttpConnectionParams();
+ params.setConnectionTimeout(0);
+ socket.createSocket("http://127.0.0.1",1234,null,4321,params);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ @Test
+ public void createSocketTest4(){
+ SslCertificateSocket socket = new SslCertificateSocket();
+ try {
+ HttpConnectionParams params = new HttpConnectionParams();
+ params.setConnectionTimeout(3000);
+ socket.createSocket("http://127.0.0.1",1234,null,4321,params);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/SslProtocolSocketFactoryTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/SslProtocolSocketFactoryTest.java
new file mode 100644
index 00000000..4ecea255
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/connect/SslProtocolSocketFactoryTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.csm.connect;
+
+import static org.junit.Assert.*;
+
+import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
+import org.junit.Test;
+import org.openo.nfvo.vnfmadapter.common.VnfmException;
+
+public class SslProtocolSocketFactoryTest {
+
+ @Test
+ public void getInstanceTest(){
+ SslProtocolSocketFactory factory = SslProtocolSocketFactory.getInstance();
+ assertNotNull(factory);
+ }
+
+ @Test(expected = VnfmException.class)
+ public void getTest() throws VnfmException{
+ ProtocolSocketFactory factory = SslProtocolSocketFactory.getInstance().get("test");
+ }
+ @Test
+ public void refreshTestException() throws VnfmException{
+ SslProtocolSocketFactory.getInstance().refresh("test");
+ assertTrue(true);
+ }
+ @Test
+ public void refreshTest() throws VnfmException{
+ SslProtocolSocketFactory.getInstance().refresh("Anonymous");
+ assertTrue(true);
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/vnf/VnfMgrVnfmTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/vnf/VnfMgrVnfmTest.java
new file mode 100644
index 00000000..403483f0
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/csm/vnf/VnfMgrVnfmTest.java
@@ -0,0 +1,307 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.csm.vnf;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.openo.nfvo.vnfmadapter.common.ResultRequestUtil;
+import org.openo.nfvo.vnfmadapter.service.constant.Constant;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+/**
+ * <br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Aug 10, 2016
+ */
+public class VnfMgrVnfmTest {
+
+ @Test
+ public void testCreateVnf() {
+ new MockUp<ResultRequestUtil>() {
+
+ @Mock
+ public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson) {
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("retCode", Constant.HTTP_CREATED);
+ JSONObject appInfo = new JSONObject();
+ appInfo.put("vnfinstanceid", "id");
+ appInfo.put("project_id", "project_id");
+ JSONObject data = new JSONObject();
+ data.put("app_info", appInfo);
+ resultJson.put("data", data);
+ return resultJson;
+ }
+ };
+ String data = "{\"vnfmInfo\":{\"url\":\"url\"}}";
+ JSONObject subJsonObject = JSONObject.fromObject(data);
+ JSONObject vnfmObjcet = new JSONObject();
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ JSONObject result = vnfMgrVnfm.createVnf(subJsonObject, vnfmObjcet);
+
+ assertEquals(Constant.REST_SUCCESS, result.get("retCode"));
+ }
+
+ @Test
+ public void testCreateVnfByBadRequest() {
+ new MockUp<ResultRequestUtil>() {
+
+ @Mock
+ public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson) {
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("retCode", Constant.HTTP_BAD_REQUEST);
+ return resultJson;
+ }
+ };
+ String data = "{\"vnfmInfo\":{\"url\":\"url\"}}";
+ JSONObject subJsonObject = JSONObject.fromObject(data);
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ JSONObject vnfmObjcet = new JSONObject();
+ JSONObject result = vnfMgrVnfm.createVnf(subJsonObject, vnfmObjcet);
+
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("retCode", Constant.REST_FAIL);
+ assertEquals(resultJson, result);
+ }
+
+ @Test
+ public void testCreateVnfByNotFound() {
+ new MockUp<ResultRequestUtil>() {
+
+ @Mock
+ public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson) {
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("retCode", Constant.HTTP_NOTFOUND);
+ return resultJson;
+ }
+ };
+ String data = "{\"vnfmInfo\":{\"url\":\"url\"}}";
+ JSONObject subJsonObject = JSONObject.fromObject(data);
+ JSONObject vnfmObjcet = new JSONObject();
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ JSONObject result = vnfMgrVnfm.createVnf(subJsonObject, vnfmObjcet);
+
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("retCode", Constant.REST_FAIL);
+ assertEquals(resultJson, result);
+ }
+
+ @Test
+ public void testCreateVnfByJSONException() {
+ new MockUp<ResultRequestUtil>() {
+
+ @Mock
+ public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson) {
+ JSONObject resultJson = new JSONObject();
+ return resultJson;
+ }
+ };
+ String data = "{\"vnfmInfo\":{\"url\":\"url\"}}";
+ JSONObject subJsonObject = JSONObject.fromObject(data);
+ JSONObject vnfmObjcet = new JSONObject();
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ JSONObject result = vnfMgrVnfm.createVnf(subJsonObject, vnfmObjcet);
+
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("retCode", Constant.REST_FAIL);
+ assertEquals(resultJson, result);
+ }
+
+ @Test
+ public void testRemoveVnf() {
+ new MockUp<ResultRequestUtil>() {
+
+ @Mock
+ public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson) {
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("retCode", Constant.HTTP_NOCONTENT);
+ return resultJson;
+ }
+ };
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ JSONObject vnfmObject = new JSONObject();
+ JSONObject vnfObject = new JSONObject();
+ vnfmObject.put("url", "url");
+ JSONObject result = vnfMgrVnfm.removeVnf(vnfmObject, "vnfId", vnfObject);
+
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("retCode", Constant.REST_SUCCESS);
+ JSONObject retJson = new JSONObject();
+ retJson.put("jobId", "vnfId" + "_" + Constant.DELETE);
+ resultJson.put("data", retJson);
+ assertEquals(resultJson, result);
+ }
+
+ @Test
+ public void testRemoveVnfByCsmError() {
+ new MockUp<ResultRequestUtil>() {
+
+ @Mock
+ public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson) {
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("retCode", Constant.HTTP_INNERERROR);
+ return resultJson;
+ }
+ };
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ JSONObject vnfmObject = new JSONObject();
+ vnfmObject.put("url", "url");
+ JSONObject vnfObject = new JSONObject();
+ JSONObject result = vnfMgrVnfm.removeVnf(vnfmObject, "vnfId", vnfObject);
+
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("retCode", Constant.REST_FAIL);
+ assertEquals(resultJson, result);
+ }
+ @Test
+ public void getJobTestNormal(){
+ new MockUp<ResultRequestUtil>(){
+ @Mock
+ public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson) {
+ JSONObject obj = new JSONObject();
+ JSONObject dataobj = new JSONObject();
+ dataobj.put("id", "2839");
+ obj.put("retCode", 200);
+ JSONArray basics = new JSONArray();
+ basics.add("test123");
+ JSONObject basicsData = new JSONObject();
+ basicsData.put("basic", basics);
+ obj.put("data", basicsData);
+ return obj;
+ }
+
+ };
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ JSONObject vnfmObject = new JSONObject();
+
+ String jobId = "1234";
+ JSONObject resp = vnfMgrVnfm.getJob(vnfmObject, jobId);
+ assertEquals(resp.get("retCode"),1);
+ }
+
+ @Test
+ public void getJobTestCreatedNormal(){
+ new MockUp<ResultRequestUtil>(){
+ @Mock
+ public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson) {
+ JSONObject obj = new JSONObject();
+ JSONObject dataobj = new JSONObject();
+ dataobj.put("id", "2839");
+ obj.put("retCode", 201);
+ JSONArray basics = new JSONArray();
+ basics.add("test123");
+ JSONObject basicsData = new JSONObject();
+ basicsData.put("basic", basics);
+ obj.put("data", basicsData);
+ return obj;
+ }
+
+ };
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ JSONObject vnfmObject = new JSONObject();
+
+ String jobId = "1234";
+ JSONObject resp = vnfMgrVnfm.getJob(vnfmObject, jobId);
+ assertEquals(resp.get("retCode"),1);
+ }
+
+ @Test
+ public void getJobTestNullData(){
+ new MockUp<ResultRequestUtil>(){
+ @Mock
+ public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson) {
+ JSONObject obj = new JSONObject();
+ JSONObject dataobj = new JSONObject();
+ dataobj.put("id", "2839");
+ obj.put("retCode", 201);
+ JSONArray basics = new JSONArray();
+ basics.add("test123");
+ JSONObject basicsData = new JSONObject();
+ basicsData.put("basic", basics);
+ obj.put("data", null);
+ return obj;
+ }
+
+ };
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ JSONObject vnfmObject = new JSONObject();
+
+ String jobId = "1234";
+ JSONObject resp = vnfMgrVnfm.getJob(vnfmObject, jobId);
+ assertEquals(resp.get("retCode"),-1);
+ }
+
+ @Test
+ public void getJobTestInternalError(){
+ new MockUp<ResultRequestUtil>(){
+ @Mock
+ public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson) {
+ JSONObject obj = new JSONObject();
+ JSONObject dataobj = new JSONObject();
+ dataobj.put("id", "2839");
+ obj.put("retCode", 500);
+ JSONArray basics = new JSONArray();
+ basics.add("test123");
+ JSONObject basicsData = new JSONObject();
+ basicsData.put("basic", basics);
+ obj.put("data", null);
+ return obj;
+ }
+
+ };
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ JSONObject vnfmObject = new JSONObject();
+
+ String jobId = "1234";
+ JSONObject resp = vnfMgrVnfm.getJob(vnfmObject, jobId);
+ assertEquals(resp.get("retCode"),-1);
+ }
+
+
+ @Test
+ public void testScaleVnf() {
+ new MockUp<ResultRequestUtil>() {
+
+ @Mock
+ public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson) {
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("retCode", Constant.HTTP_CREATED);
+ JSONObject appInfo = new JSONObject();
+ appInfo.put("vnfinstanceid", "id");
+ appInfo.put("project_id", "project_id");
+ JSONObject data = new JSONObject();
+ data.put("app_info", appInfo);
+ resultJson.put("data", data);
+ return resultJson;
+ }
+ };
+ String data = "{\"vnfmInfo\":{\"url\":\"url\"}}";
+ JSONObject subJsonObject = JSONObject.fromObject(data);
+ JSONObject vnfmObjcet = new JSONObject();
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ JSONObject result = vnfMgrVnfm.scaleVnf(subJsonObject,vnfmObjcet,"test123","test123");
+
+ assertEquals(Constant.REST_SUCCESS, result.get("retCode"));
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/dao/impl/VnfmDaoImplTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/dao/impl/VnfmDaoImplTest.java
new file mode 100644
index 00000000..4564d69b
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/dao/impl/VnfmDaoImplTest.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.nfvo.vnfmadapter.service.dao.impl;
+
+import junit.framework.Assert;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.vnfmadapter.service.entity.Vnfm;
+
+/**
+ * Created by QuanZhong on 2017/3/17.
+ */
+public class VnfmDaoImplTest {
+
+ @Test
+ public void insertVnfm() throws ServiceException {
+ VnfmDaoImpl dao = new VnfmDaoImpl();
+ dao.insertVnfm(new Vnfm());
+ Assert.assertTrue(true);
+ }
+
+ @Test
+ public void deleteVnfm() throws ServiceException {
+ VnfmDaoImpl dao = new VnfmDaoImpl();
+ dao.deleteVnfm("abc");
+ Assert.assertTrue(true);
+ }
+
+ @Test
+ public void updateVnfm() throws ServiceException {
+ VnfmDaoImpl dao = new VnfmDaoImpl();
+ dao.updateVnfm(new Vnfm());
+ Assert.assertTrue(true);
+ }
+
+ @Test
+ public void indexVnfms() throws ServiceException {
+ VnfmDaoImpl dao = new VnfmDaoImpl();
+ dao.insertVnfm(new Vnfm());
+ Assert.assertTrue(true);
+
+ }
+
+ @Test
+ public void getVnfmById() {
+ VnfmDaoImpl dao = new VnfmDaoImpl();
+ dao.getVnfmById("abc");
+ Assert.assertTrue(true);
+
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/entity/VnfmTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/entity/VnfmTest.java
new file mode 100644
index 00000000..c9996788
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/entity/VnfmTest.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.entity;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class VnfmTest {
+ Vnfm vnfm;
+
+ @Before
+ public void setUp(){
+ vnfm = new Vnfm();
+ vnfm.setId("123");
+ vnfm.setId("v1");
+ vnfm.setVnfdId("1234");
+ vnfm.setVnfPackageId("abcd");
+ }
+
+ @Test
+ public void hashCodeTest(){
+ Vnfm tempVnfm = new Vnfm();
+ tempVnfm.setId("123");
+ tempVnfm.setId("v1");
+ tempVnfm.setVnfdId("1234");
+ tempVnfm.setVnfPackageId("abcd");
+ assertTrue(vnfm.hashCode() == tempVnfm.hashCode());
+ }
+
+ @Test
+ public void equalsTest1(){
+ Vnfm tempVnfm = new Vnfm();
+ tempVnfm.setId("123");
+ tempVnfm.setId("v1");
+ tempVnfm.setVnfdId("1234");
+ tempVnfm.setVnfPackageId("abcd");
+ assertTrue(vnfm.equals(tempVnfm));
+ }
+
+ @Test
+ public void equalsTest2(){
+ assertTrue(vnfm.equals(vnfm));
+ }
+
+ @Test
+ public void equalsTest3(){
+
+ assertTrue(!vnfm.equals(null));
+ }
+ @Test
+ public void equalsTest4(){
+
+ assertTrue(!vnfm.equals(new Object()));
+ }
+ @Test
+ public void equalsTest5(){
+
+ assertTrue(!vnfm.equals(new Object()));
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/process/AuthMgrTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/process/AuthMgrTest.java
new file mode 100644
index 00000000..718423c9
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/process/AuthMgrTest.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.process;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+import org.openo.nfvo.vnfmadapter.common.servicetoken.VnfmRestfulUtil;
+import org.openo.nfvo.vnfmadapter.service.constant.Constant;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+public class AuthMgrTest {
+
+ @Test
+ public void testAuthTokenByDomainNameByJSONException() {
+ AuthMgr authMgr = new AuthMgr();
+ String data = "{\"auth\":{}}";
+ JSONObject params = JSONObject.fromObject(data);
+
+ JSONObject result = authMgr.authToken(params);
+
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_FAIL);
+ restJson.put("data", "JSONException");
+ assertEquals(restJson, result);
+ }
+
+ @Test
+ public void testAuthToken() {
+ new MockUp<VnfmRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRestResByDefault(String auth, String method, JSONObject authParams) {
+ RestfulResponse response = null;
+ return response;
+ }
+ };
+
+ AuthMgr authMgr = new AuthMgr();
+ String data = "{\"auth\":{\"identity\":{\"password\":{\"user\":{\"name\":\"om_team\",\"password\":\"123\"}}}}}";
+ JSONObject params = JSONObject.fromObject(data);
+
+ JSONObject result = authMgr.authToken(params);
+ assertEquals(Constant.REST_SUCCESS, result.getInt("retCode"));
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/process/RegisterMgrTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/process/RegisterMgrTest.java
new file mode 100644
index 00000000..eee4e1df
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/process/RegisterMgrTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.process;
+
+import org.junit.Test;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+import org.openo.nfvo.vnfmadapter.common.servicetoken.VnfmRestfulUtil;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Jan 13, 2017
+ */
+public class RegisterMgrTest {
+
+ @Test
+ public void testRegister() {
+ new MockUp<VnfmRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
+ RestfulResponse rsp = new RestfulResponse();
+ rsp.setStatus(200);
+ return rsp;
+ }
+ };
+ RegisterMgr register = new RegisterMgr();
+ register.register();
+ }
+
+ @Test
+ public void testUnRegister() {
+ new MockUp<VnfmRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
+ RestfulResponse rsp = new RestfulResponse();
+ rsp.setStatus(200);
+ return rsp;
+ }
+ };
+ RegisterMgr register = new RegisterMgr();
+ register.unRegister();
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/process/VnfMgrTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/process/VnfMgrTest.java
new file mode 100644
index 00000000..5f2b94d1
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/process/VnfMgrTest.java
@@ -0,0 +1,497 @@
+/*
+ * Copyright 2016-2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.process;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.vnfmadapter.common.ResultRequestUtil;
+import org.openo.nfvo.vnfmadapter.common.VnfmUtil;
+import org.openo.nfvo.vnfmadapter.service.adapter.impl.AdapterResourceManager;
+import org.openo.nfvo.vnfmadapter.service.constant.Constant;
+import org.openo.nfvo.vnfmadapter.service.csm.vnf.VnfMgrVnfm;
+import org.openo.nfvo.vnfmadapter.service.dao.impl.VnfmDaoImpl;
+import org.openo.nfvo.vnfmadapter.service.dao.inf.VnfmDao;
+import org.openo.nfvo.vnfmadapter.service.entity.Vnfm;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONArray;
+import net.sf.json.JSONException;
+import net.sf.json.JSONObject;
+
+public class VnfMgrTest {
+
+ private VnfmDao vnfmDao;
+
+ private VnfMgr vnfMgr;
+
+ @Before
+ public void setUp() {
+ vnfMgr = new VnfMgr();
+ vnfmDao = new VnfmDaoImpl();
+ vnfMgr.setVnfmDao(vnfmDao);
+ }
+
+ @Test
+ public void testAddVnfByInvalidateDataVnfInfoNull() {
+ String data = "{}";
+ JSONObject subJsonObject = JSONObject.fromObject(data);
+ VnfMgr vnfMgr = new VnfMgr();
+ JSONObject result = vnfMgr.addVnf(subJsonObject, "vnmfId");
+
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_FAIL);
+ assertEquals(restJson, result);
+ }
+
+ @Test
+ public void testAddVnfByInvalidateDataVnfInfoEmpty() {
+ String data = "{}";
+ JSONObject subJsonObject = JSONObject.fromObject(data);
+ VnfMgr vnfMgr = new VnfMgr();
+ JSONObject result = vnfMgr.addVnf(subJsonObject, "vnmfId");
+
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_FAIL);
+ assertEquals(restJson, result);
+ }
+
+ @Test
+ public void testAddVnfByVnfmObjcetIsNullObject() {
+ new MockUp<VnfmUtil>() {
+
+ @Mock
+ public JSONObject getVnfmById(String vnfmId) {
+ return new JSONObject(true);
+ }
+ };
+ String data =
+ "{\"soId\": \"soId\",\"vapp_info\":{\"vnfm_id\":\"vnfm_id\",\"soId\": \"soId\",\"do_id\": \"do_id\"}}";
+ JSONObject subJsonObject = JSONObject.fromObject(data);
+ VnfMgr vnfMgr = new VnfMgr();
+ JSONObject result = vnfMgr.addVnf(subJsonObject, "vnmfId");
+
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_FAIL);
+ assertEquals(restJson, result);
+ }
+
+ @Test
+ public void testAddVnfByVnfmObjcetTypeEmpty() {
+ new MockUp<VnfmUtil>() {
+
+ @Mock
+ public JSONObject getVnfmById(String vnfmId) {
+ JSONObject obj = new JSONObject();
+ obj.put("type", "");
+ return obj;
+ }
+ };
+ String data =
+ "{\"soId\": \"soId\",\"vapp_info\":{\"vnfm_id\":\"vnfm_id\",\"soId\": \"soId\",\"do_id\": \"do_id\"}}";
+ JSONObject subJsonObject = JSONObject.fromObject(data);
+ VnfMgr vnfMgr = new VnfMgr();
+ JSONObject result = vnfMgr.addVnf(subJsonObject, "vnmfId");
+
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_FAIL);
+ assertEquals(restJson, result);
+ }
+
+ @Test
+ public void testAddVnf() {
+ new MockUp<VnfmUtil>() {
+
+ @Mock
+ public JSONObject getVnfmById(String vnfmId) {
+ JSONObject obj = new JSONObject();
+ obj.put("type", "hw");
+ obj.put("vnfmId", "123");
+ obj.put("userName", "admin");
+ obj.put("password", "admin");
+ obj.put("url", "https://10.2.31.2:30001");
+ return obj;
+ }
+ };
+
+ new MockUp<VnfMgrVnfm>() {
+
+ @Mock
+ public JSONObject createVnf(JSONObject subJsonObject, JSONObject vnfmObjcet) {
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_SUCCESS);
+ return restJson;
+ }
+ };
+
+ new MockUp<AdapterResourceManager>() {
+
+ @Mock
+ public JSONObject uploadVNFPackage(JSONObject subJsonObject, Map<String, String> conMap) {
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_SUCCESS);
+ restJson.put("vnfdId", "123");
+ return restJson;
+ }
+ };
+
+ String data =
+ "{\"vnfPackageId\": \"vnfPackageId\",\"vnfId\": \"vnfId\",\"additionalParam\":{\"parameters\":{\"input\":\"input\"}}}";
+ JSONObject subJsonObject = JSONObject.fromObject(data);
+ VnfMgr vnfMgr = new VnfMgr();
+ JSONObject result = vnfMgr.addVnf(subJsonObject, "vnfmId");
+
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_SUCCESS);
+ assertEquals(restJson, result);
+ }
+
+ @Test
+ public void testDeleteVnf() {
+ new MockUp<VnfmUtil>() {
+
+ @Mock
+ public JSONObject getVnfmById(String vnfmId) {
+ JSONObject obj = new JSONObject();
+ obj.put("type", "hw");
+ obj.put("vnfmId", "123");
+ obj.put("userName", "admin");
+ obj.put("password", "admin");
+ obj.put("url", "https://10.2.31.2:30001");
+ return obj;
+ }
+ };
+ new MockUp<VnfMgrVnfm>() {
+
+ @Mock
+ public JSONObject removeVnf(JSONObject vnfmObject, String vnfId, JSONObject vnfObject) {
+ JSONObject obj = new JSONObject();
+ obj.put("retCode", Constant.REST_SUCCESS);
+ return obj;
+ }
+ };
+ VnfMgr vnfMgr = new VnfMgr();
+ JSONObject vnfObject = new JSONObject();
+ JSONObject result = vnfMgr.deleteVnf("vnfId", "vnfmId", vnfObject);
+
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_SUCCESS);
+ assertEquals(restJson, result);
+ }
+
+ @Test
+ public void testDeleteVnfByVnfmObjcetIsNullObject() {
+ new MockUp<VnfmUtil>() {
+
+ @Mock
+ public JSONObject getVnfmById(String vnfmId) {
+ JSONObject obj = new JSONObject(true);
+ return obj;
+ }
+ };
+ VnfMgr vnfMgr = new VnfMgr();
+ JSONObject vnfObject = new JSONObject();
+ JSONObject result = vnfMgr.deleteVnf("vnfId", "vnfmId", vnfObject);
+
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_FAIL);
+ assertEquals(restJson, result);
+
+ }
+
+ @Test
+ public void testDeleteVnfByException() {
+ new MockUp<VnfmUtil>() {
+
+ @Mock
+ public JSONObject getVnfmById(String vnfmId) {
+ throw new JSONException();
+ }
+ };
+ VnfMgr vnfMgr = new VnfMgr();
+ JSONObject vnfObject = new JSONObject();
+ JSONObject result = vnfMgr.deleteVnf("vnfId", "vnfmId", vnfObject);
+
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_FAIL);
+ assertEquals(restJson, result);
+
+ }
+
+ @Test
+ public void testGetVnf() {
+ new MockUp<VnfmUtil>() {
+
+ @Mock
+ public JSONObject getVnfmById(String vnfmId) {
+ JSONObject obj = new JSONObject();
+ obj.put("type", "hw");
+ obj.put("vnfmId", "123");
+ obj.put("userName", "admin");
+ obj.put("password", "admin");
+ obj.put("url", "https://10.2.31.2:30001");
+ return obj;
+ }
+ };
+
+ new MockUp<VnfmDaoImpl>() {
+
+ @Mock
+ public Vnfm getVnfmById(String vnfmId) {
+ Vnfm obj = new Vnfm();
+ obj.setId("123");
+ obj.setVersion("v2.0");
+ obj.setVnfdId("234");
+ obj.setVnfPackageId("123");
+ return obj;
+ }
+ };
+
+ new MockUp<ResultRequestUtil>() {
+
+ @Mock
+ public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson) {
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("retCode", Constant.HTTP_OK);
+ JSONObject data = new JSONObject();
+
+ JSONArray result = new JSONArray();
+ JSONObject basicInfo = new JSONObject();
+ basicInfo.put("id", "NE=345");
+ basicInfo.put("vapp_name", "sc");
+ basicInfo.put("status", "active");
+ result.add(basicInfo);
+ data.put("basic", result);
+ resultJson.put("data", data.toString());
+ return resultJson;
+ }
+ };
+
+ JSONObject result = vnfMgr.getVnf("vnfId", "vnfmId");
+
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_SUCCESS);
+ result.remove("vnfInfo");
+ assertEquals(restJson, result);
+ }
+
+ @Test
+ public void testGetVnfFail() {
+ new MockUp<VnfmUtil>() {
+
+ @Mock
+ public JSONObject getVnfmById(String vnfmId) {
+ JSONObject obj = new JSONObject(true);
+ return obj;
+ }
+ };
+
+ JSONObject result = vnfMgr.getVnf("vnfId", "vnfmId");
+ JSONObject restJson = new JSONObject();
+ restJson.put(Constant.RETCODE, Constant.REST_FAIL);
+ assertEquals(restJson, result);
+ }
+
+ @Test
+ public void testGetVnfFail1() {
+ new MockUp<VnfmUtil>() {
+
+ @Mock
+ public JSONObject getVnfmById(String vnfmId) {
+ throw new JSONException();
+ }
+ };
+
+ JSONObject result = vnfMgr.getVnf("vnfId", "vnfmId");
+ JSONObject restJson = new JSONObject();
+ restJson.put(Constant.RETCODE, Constant.REST_FAIL);
+ assertEquals(restJson, result);
+ }
+
+ @Test
+ public void testSaveVnfInfo() {
+ new MockUp<VnfmDaoImpl>() {
+
+ @Mock
+ public int insertVnfm(Vnfm vnfm) throws ServiceException {
+ return 1;
+ }
+ };
+
+ VnfMgr vnfMgr = new VnfMgr();
+ VnfmDao dao = new VnfmDaoImpl();
+ vnfMgr.setVnfmDao(dao);
+ JSONObject vnfObject = new JSONObject();
+ vnfObject.put("retCode", Constant.REST_SUCCESS);
+ vnfObject.put("vnfInstanceId", "vnfInstanceId");
+ vnfObject.put("vnfPackageId", "vnfPackageId");
+ JSONObject resObject = new JSONObject();
+ resObject.put("vnfdVersion", "vnfdVersion");
+ resObject.put("vnfdId", "vnfdId");
+ vnfMgr.saveVnfInfo(vnfObject, resObject);
+ }
+
+ @Test
+ public void testSaveVnfInfoFail() {
+ new MockUp<VnfmDaoImpl>() {
+
+ @Mock
+ public int insertVnfm(Vnfm vnfm) throws ServiceException {
+ return 1;
+ }
+ };
+
+ VnfMgr vnfMgr = new VnfMgr();
+ VnfmDao dao = new VnfmDaoImpl();
+ vnfMgr.setVnfmDao(dao);
+ JSONObject vnfObject = new JSONObject();
+ vnfObject.put("retCode", Constant.REST_FAIL);
+ vnfObject.put("vnfInstanceId", "vnfInstanceId");
+ vnfObject.put("vnfPackageId", "vnfPackageId");
+ JSONObject resObject = new JSONObject();
+ resObject.put("vnfdVersion", "vnfdVersion");
+ resObject.put("vnfdId", "vnfdId");
+ vnfMgr.saveVnfInfo(vnfObject, resObject);
+ }
+
+ @Test
+ public void testSaveVnfInfoServiceException() {
+ new MockUp<VnfmDaoImpl>() {
+
+ @Mock
+ public int insertVnfm(Vnfm vnfm) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+
+ VnfMgr vnfMgr = new VnfMgr();
+ VnfmDao dao = new VnfmDaoImpl();
+ vnfMgr.setVnfmDao(dao);
+ JSONObject vnfObject = new JSONObject();
+ vnfObject.put("retCode", Constant.REST_SUCCESS);
+ vnfObject.put("vnfInstanceId", "vnfInstanceId");
+ vnfObject.put("vnfPackageId", "vnfPackageId");
+ JSONObject resObject = new JSONObject();
+ resObject.put("vnfdVersion", "vnfdVersion");
+ resObject.put("vnfdId", "vnfdId");
+ vnfMgr.saveVnfInfo(vnfObject, resObject);
+ }
+
+ @Test
+ public void testGetJob() {
+ new MockUp<VnfmUtil>() {
+
+ @Mock
+ public JSONObject getVnfmById(String vnfmId) {
+ JSONObject obj = new JSONObject();
+ obj.put("test", "success");
+ return obj;
+ }
+ };
+
+ new MockUp<VnfMgrVnfm>() {
+
+ @Mock
+ public JSONObject getJob(JSONObject vnfmObject, String jobId) {
+ JSONObject res = new JSONObject();
+ res.put(Constant.RETCODE, Constant.REST_SUCCESS);
+ return res;
+ }
+ };
+ VnfMgr vnfMgr = new VnfMgr();
+ JSONObject result = vnfMgr.getJob("", "");
+
+ JSONObject restJson = new JSONObject();
+ restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
+ assertEquals(restJson, result);
+ }
+
+ @Test
+ public void testGetJobFail() {
+ new MockUp<VnfmUtil>() {
+
+ @Mock
+ public JSONObject getVnfmById(String vnfmId) {
+ return new JSONObject();
+ }
+ };
+ VnfMgr vnfMgr = new VnfMgr();
+ JSONObject result = vnfMgr.getJob("", "");
+
+ JSONObject restJson = new JSONObject();
+ restJson.put(Constant.RETCODE, Constant.REST_FAIL);
+ assertEquals(restJson, result);
+ }
+
+ @Test
+ public void testGetJobFail1() {
+ new MockUp<VnfmUtil>() {
+
+ @Mock
+ public JSONObject getVnfmById(String vnfmId) {
+ return new JSONObject(true);
+ }
+ };
+ VnfMgr vnfMgr = new VnfMgr();
+ JSONObject result = vnfMgr.getJob("", "");
+
+ JSONObject restJson = new JSONObject();
+ restJson.put(Constant.RETCODE, Constant.REST_FAIL);
+ assertEquals(restJson, result);
+ }
+ @Test
+ public void testScaleVnf() {
+ new MockUp<VnfmUtil>() {
+
+ @Mock
+ public JSONObject getVnfmById(String vnfmId) {
+ JSONObject obj = new JSONObject();
+ obj.put("type", "hw");
+ obj.put("vnfmId", "123");
+ obj.put("userName", "admin");
+ obj.put("password", "admin");
+ obj.put("url", "https://10.2.31.2:30001");
+ return obj;
+ }
+ };
+
+ new MockUp<VnfMgrVnfm>() {
+
+ @Mock
+ public JSONObject scaleVnf(JSONObject vnfObject, JSONObject vnfmObject, String vnfmId, String vnfInstanceId) {
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_SUCCESS);
+ return restJson;
+ }
+ };
+
+ String data =
+ "{\"vnfPackageId\": \"vnfPackageId\",\"vnfId\": \"vnfId\",\"additionalParam\":{\"parameters\":{\"input\":\"input\"}}}";
+ JSONObject subJsonObject = JSONObject.fromObject(data);
+ VnfMgr vnfMgr = new VnfMgr();
+ JSONObject result = vnfMgr.scaleVNF(subJsonObject,"testId","testId");
+
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_SUCCESS);
+ assertEquals(restJson, result);
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/process/VnfResourceMgrTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/process/VnfResourceMgrTest.java
new file mode 100644
index 00000000..c706178b
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/process/VnfResourceMgrTest.java
@@ -0,0 +1,235 @@
+/*
+ * Copyright 2016-2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.process;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+import org.openo.nfvo.vnfmadapter.common.servicetoken.VnfmRestfulUtil;
+import org.openo.nfvo.vnfmadapter.service.constant.Constant;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+/**
+ * <br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Aug 9, 2016
+ */
+public class VnfResourceMgrTest {
+
+ @Test
+ public void testgrantVnfResource() {
+
+ String data =
+ "{\"type\": \"instantiation\",\"operation_right\": \"increase\",\"vnf_name\": \"vnf_name\",\"vm_list\": [{\"vm_flavor\": {\"storage\": [{\"vol_type\": \"local_volume\",\"vol_size\": \"2\",\"storage_type\": \"local_image\",\"disk_size\": \"100\"}],\"num_cpus\": \"6\",\"mem_size\": \"8\"},\"init_number\": \"1\"}],\"version\": \"version\",\"template_id\": \"template_id\",\"template_name\": \"template_name\",\"plan_id\": \"plan_id\",\"plan_name\": \"plan_name\",\"project_id\": \"project_id\",\"project_name\": \"project_name\",\"creator\": \"creator\",\"status\": \"status\",\"tenant\": \"tenant\",\"parent_tenant\": \"parent_tenant\",\"vnfd_id\": \"vnfd_id\",\"location\": \"location\",\"dr_location\": \"dr_location\",\"nfvo_id\": \"nfvo_id\"}";
+ JSONObject vnfObj = JSONObject.fromObject(data);
+ VnfResourceMgr vnfResourceMgr = new VnfResourceMgr();
+ JSONObject result = vnfResourceMgr.grantVnfResource(vnfObj, "vnfId", "vnfmId");
+
+ JSONObject retJson = new JSONObject();
+ retJson.put("retCode", Constant.REST_FAIL);
+ retJson.put("errorMsg", "params parse exception");
+ assertEquals(retJson, result);
+ }
+
+ @Test
+ public void testgrantVnfResourceSuccess() {
+ new MockUp<VnfmRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
+ RestfulResponse rsp = new RestfulResponse();
+ rsp.setStatus(200);
+ rsp.setResponseJson(new JSONObject().toString());
+ return rsp;
+ }
+ };
+
+ JSONObject vnfObj = new JSONObject();
+ String data =
+ "{\"type\": \"instantiation\",\"location\": \"RomaRespool\",\"version\":\"V500R001C20\",\"vendor\": \"V500R001C20B001\",\"tenant\": \"admin\",\"vnf_id\":\"NE=1304\",\"vnfm_id\": \"9a49755d-8050-4369-9e7d-0a0855097585\",\"project_id\":\"\",\"operation_right\": \"increase\",\"vnf_name\": \"wangyuans4\",\"vim_id\":\"\",\"dr_location\": \"RomaRespool\",\"nfvo_id\": \"\",\"vnf_type\": \"vNGFW\",\"plan_id\":\"V4\",\"plan_name\": \"V4\",\"vnfd_id\": \"vNGFW\",\"vm_list\": [{\"vm_flavor\":{\"location\": \"\",\"priority\": \"1\",\"storage\": [{\"vol_type\":\"local_volume\",\"vol_size\": \"200\"},{\"storage_type\": \"local_image\",\"disk_size\":\"80\"}],\"vdu_name\": \"OMU\",\"num_cpus\": \"4\",\"mem_size\": \"8192\"},\"init_number\":\"1\"}],\"ex_vim_list\": []}";
+ vnfObj = JSONObject.fromObject(data);
+ VnfResourceMgr grantTest = new VnfResourceMgr();
+ JSONObject result = grantTest.grantVnfResource(vnfObj, "1111", "abc");
+
+ JSONObject retJson = new JSONObject();
+ assertEquals(retJson, result);
+ }
+
+ @Test
+ public void testgrantVnfResourceSuccess1() {
+ new MockUp<VnfmRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
+ RestfulResponse rsp = new RestfulResponse();
+ rsp.setStatus(200);
+ rsp.setResponseJson(new JSONObject().toString());
+ return rsp;
+ }
+ };
+
+ JSONObject vnfObj = new JSONObject();
+ String data =
+ "{\"type\": \"instantiation\",\"location\": \"RomaRespool\",\"version\":\"V500R001C20\",\"vendor\": \"V500R001C20B001\",\"tenant\": \"admin\",\"vnf_id\":\"NE=1304\",\"vnfm_id\": \"9a49755d-8050-4369-9e7d-0a0855097585\",\"project_id\":\"\",\"operation_right\": \"decrease\",\"vnf_name\": \"wangyuans4\",\"vim_id\":\"\",\"dr_location\": \"RomaRespool\",\"nfvo_id\": \"\",\"vnf_type\": \"vNGFW\",\"plan_id\":\"V4\",\"plan_name\": \"V4\",\"vnfd_id\": \"vNGFW\",\"vm_list\": [{\"vm_flavor\":{\"location\": \"\",\"priority\": \"1\",\"storage\": [{\"vol_type\":\"local_volume\",\"vol_size\": \"200\"},{\"storage_type\": \"local_image\",\"disk_size\":\"80\"}],\"vdu_name\": \"OMU\",\"num_cpus\": \"4\",\"mem_size\": \"8192\"},\"init_number\":\"1\"}],\"ex_vim_list\": []}";
+ vnfObj = JSONObject.fromObject(data);
+ VnfResourceMgr grantTest = new VnfResourceMgr();
+ JSONObject result = grantTest.grantVnfResource(vnfObj, "1111", "abc");
+
+ JSONObject retJson = new JSONObject();
+ assertEquals(retJson, result);
+ }
+
+ @Test
+ public void testgrantVnfResourceSuccess2() {
+ new MockUp<VnfmRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
+ RestfulResponse rsp = new RestfulResponse();
+ rsp.setStatus(200);
+ rsp.setResponseJson(new JSONObject().toString());
+ return rsp;
+ }
+ };
+
+ JSONObject vnfObj = new JSONObject();
+ String data =
+ "{\"type\": \"scale\",\"location\": \"RomaRespool\",\"version\":\"V500R001C20\",\"vendor\": \"V500R001C20B001\",\"tenant\": \"admin\",\"vnf_id\":\"NE=1304\",\"vnfm_id\": \"9a49755d-8050-4369-9e7d-0a0855097585\",\"project_id\":\"\",\"operation_right\": \"decrease\",\"vnf_name\": \"wangyuans4\",\"vim_id\":\"\",\"dr_location\": \"RomaRespool\",\"nfvo_id\": \"\",\"vnf_type\": \"vNGFW\",\"plan_id\":\"V4\",\"plan_name\": \"V4\",\"vnfd_id\": \"vNGFW\",\"vm_list\": [{\"vm_flavor\":{\"location\": \"\",\"priority\": \"1\",\"storage\": [{\"vol_type\":\"local_volume\",\"vol_size\": \"200\"},{\"storage_type\": \"local_image\",\"disk_size\":\"80\"}],\"vdu_name\": \"OMU\",\"num_cpus\": \"4\",\"mem_size\": \"8192\"},\"init_number\":\"1\"}],\"ex_vim_list\": []}";
+ vnfObj = JSONObject.fromObject(data);
+ VnfResourceMgr grantTest = new VnfResourceMgr();
+ JSONObject result = grantTest.grantVnfResource(vnfObj, "1111", "abc");
+
+ JSONObject retJson = new JSONObject();
+ assertEquals(retJson, result);
+ }
+
+ @Test
+ public void testgrantVnfResourceSuccess3() {
+ new MockUp<VnfmRestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
+ RestfulResponse rsp = new RestfulResponse();
+ rsp.setStatus(200);
+ rsp.setResponseJson(new JSONObject().toString());
+ return rsp;
+ }
+ };
+
+ JSONObject vnfObj = new JSONObject();
+ String data =
+ "{\"type\": \"scale\",\"location\": \"RomaRespool\",\"version\":\"V500R001C20\",\"vendor\": \"V500R001C20B001\",\"tenant\": \"admin\",\"vnf_id\":\"NE=1304\",\"vnfm_id\": \"9a49755d-8050-4369-9e7d-0a0855097585\",\"project_id\":\"\",\"operation_right\": \"increase\",\"vnf_name\": \"wangyuans4\",\"vim_id\":\"\",\"dr_location\": \"RomaRespool\",\"nfvo_id\": \"\",\"vnf_type\": \"vNGFW\",\"plan_id\":\"V4\",\"plan_name\": \"V4\",\"vnfd_id\": \"vNGFW\",\"vm_list\": [{\"vm_flavor\":{\"location\": \"\",\"priority\": \"1\",\"storage\": [{\"vol_type\":\"local_volume\",\"vol_size\": \"200\"},{\"storage_type\": \"local_image\",\"disk_size\":\"80\"}],\"vdu_name\": \"OMU\",\"num_cpus\": \"4\",\"mem_size\": \"8192\"},\"init_number\":\"1\"}],\"ex_vim_list\": []}";
+ vnfObj = JSONObject.fromObject(data);
+ VnfResourceMgr grantTest = new VnfResourceMgr();
+ JSONObject result = grantTest.grantVnfResource(vnfObj, "1111", "abc");
+
+ JSONObject retJson = new JSONObject();
+ assertEquals(retJson, result);
+ }
+
+ @Test
+ public void testgrantVnfResourceByResMapNull() {
+
+ String data =
+ "{\"type\": \"instantiation\",\"operation_right\": \"increase\",\"vnf_name\": \"vnf_name\",\"vm_list\": [{\"vm_flavors\": {\"storage\": [{\"vol_type\": \"local_volume\",\"vol_size\": \"2\",\"storage_type\": \"local_image\",\"disk_size\": \"100\"}],\"num_cpus\": \"6\",\"mem_size\": \"8\"},\"init_number\": \"1\"}],\"version\": \"version\",\"template_id\": \"template_id\",\"template_name\": \"template_name\",\"plan_id\": \"plan_id\",\"plan_name\": \"plan_name\",\"project_id\": \"project_id\",\"project_name\": \"project_name\",\"creator\": \"creator\",\"status\": \"status\",\"tenant\": \"tenant\",\"parent_tenant\": \"parent_tenant\",\"vnfd_id\": \"vnfd_id\",\"location\": \"location\",\"dr_location\": \"dr_location\",\"nfvo_id\": \"nfvo_id\"}";
+ JSONObject vnfObj = JSONObject.fromObject(data);
+ VnfResourceMgr vnfResourceMgr = new VnfResourceMgr();
+ JSONObject result = vnfResourceMgr.grantVnfResource(vnfObj, "vnfId", "vnfmId");
+
+ JSONObject retJson = new JSONObject();
+ retJson.put("retCode", Constant.REST_FAIL);
+ retJson.put("errorMsg", "resource params error");
+ assertEquals(retJson, result);
+ }
+
+ @Test
+ public void testgrantVnfResourceByTypeIsEmpty() {
+ String data =
+ "{\"type\": \"\",\"operation_right\": \"increase\",\"vnf_name\": \"vnf_name\",\"vm_list\": [{\"vm_flavor\": {\"storage\": [{\"vol_type\": \"local_volume\",\"vol_size\": \"2\",\"storage_type\": \"local_image\",\"disk_size\": \"100\"}],\"num_cpus\": \"6\",\"mem_size\": \"8\"},\"init_number\": \"1\"}],\"version\": \"version\",\"template_id\": \"template_id\",\"template_name\": \"template_name\",\"plan_id\": \"plan_id\",\"plan_name\": \"plan_name\",\"project_id\": \"project_id\",\"project_name\": \"project_name\",\"creator\": \"creator\",\"status\": \"status\",\"tenant\": \"tenant\",\"parent_tenant\": \"parent_tenant\",\"vnfd_id\": \"vnfd_id\",\"location\": \"location\",\"dr_location\": \"dr_location\",\"nfvo_id\": \"nfvo_id\"}";
+ JSONObject vnfObj = JSONObject.fromObject(data);
+ VnfResourceMgr vnfResourceMgr = new VnfResourceMgr();
+ JSONObject result = vnfResourceMgr.grantVnfResource(vnfObj, "vnfId", "vnfmId");
+
+ JSONObject retJson = new JSONObject();
+ retJson.put("retCode", Constant.REST_FAIL);
+ retJson.put("errorMsg", "basic params error");
+ assertEquals(retJson, result);
+ }
+
+ @Test
+ public void testgrantVnfResourceByVnfNameIsEmpty() {
+ String data =
+ "{\"type\": \"instantiation\",\"operation_right\": \"increase\",\"vnf_name\": \"\",\"vm_list\": [{\"vm_flavor\": {\"storage\": [{\"vol_type\": \"local_volume\",\"vol_size\": \"2\",\"storage_type\": \"local_image\",\"disk_size\": \"100\"}],\"num_cpus\": \"6\",\"mem_size\": \"8\"},\"init_number\": \"1\"}],\"version\": \"version\",\"template_id\": \"template_id\",\"template_name\": \"template_name\",\"plan_id\": \"plan_id\",\"plan_name\": \"plan_name\",\"project_id\": \"project_id\",\"project_name\": \"project_name\",\"creator\": \"creator\",\"status\": \"status\",\"tenant\": \"tenant\",\"parent_tenant\": \"parent_tenant\",\"vnfd_id\": \"vnfd_id\",\"location\": \"location\",\"dr_location\": \"dr_location\",\"nfvo_id\": \"nfvo_id\"}";
+ JSONObject vnfObj = JSONObject.fromObject(data);
+ VnfResourceMgr vnfResourceMgr = new VnfResourceMgr();
+ JSONObject result = vnfResourceMgr.grantVnfResource(vnfObj, "vnfId", "vnfmId");
+
+ JSONObject retJson = new JSONObject();
+ retJson.put("retCode", Constant.REST_FAIL);
+ retJson.put("errorMsg", "basic params error");
+ assertEquals(retJson, result);
+ }
+
+ @Test
+ public void testgrantVnfResourceByVnfIdIsEmpty() {
+ String data =
+ "{\"type\": \"instantiation\",\"operation_right\": \"increase\",\"vnf_name\": \"vnf_name\",\"vm_list\": [{\"vm_flavor\": {\"storage\": [{\"vol_type\": \"local_volume\",\"vol_size\": \"2\",\"storage_type\": \"local_image\",\"disk_size\": \"100\"}],\"num_cpus\": \"6\",\"mem_size\": \"8\"},\"init_number\": \"1\"}],\"version\": \"version\",\"template_id\": \"template_id\",\"template_name\": \"template_name\",\"plan_id\": \"plan_id\",\"plan_name\": \"plan_name\",\"project_id\": \"project_id\",\"project_name\": \"project_name\",\"creator\": \"creator\",\"status\": \"status\",\"tenant\": \"tenant\",\"parent_tenant\": \"parent_tenant\",\"vnfd_id\": \"vnfd_id\",\"location\": \"location\",\"dr_location\": \"dr_location\",\"nfvo_id\": \"nfvo_id\"}";
+ JSONObject vnfObj = JSONObject.fromObject(data);
+ VnfResourceMgr vnfResourceMgr = new VnfResourceMgr();
+ JSONObject result = vnfResourceMgr.grantVnfResource(vnfObj, "", "vnfmId");
+
+ JSONObject retJson = new JSONObject();
+ retJson.put("retCode", Constant.REST_FAIL);
+ retJson.put("errorMsg", "basic params error");
+ assertEquals(retJson, result);
+ }
+
+ @Test
+ public void testgrantVnfResourceByRequestTypeIsEmpty() {
+ String data =
+ "{\"type\": \"instantiation\",\"operation_right\": \"\",\"vnf_name\": \"vnf_name\",\"vm_list\": [{\"vm_flavor\": {\"storage\": [{\"vol_type\": \"local_volume\",\"vol_size\": \"2\",\"storage_type\": \"local_image\",\"disk_size\": \"100\"}],\"num_cpus\": \"6\",\"mem_size\": \"8\"},\"init_number\": \"1\"}],\"version\": \"version\",\"template_id\": \"template_id\",\"template_name\": \"template_name\",\"plan_id\": \"plan_id\",\"plan_name\": \"plan_name\",\"project_id\": \"project_id\",\"project_name\": \"project_name\",\"creator\": \"creator\",\"status\": \"status\",\"tenant\": \"tenant\",\"parent_tenant\": \"parent_tenant\",\"vnfd_id\": \"vnfd_id\",\"location\": \"location\",\"dr_location\": \"dr_location\",\"nfvo_id\": \"nfvo_id\"}";
+ JSONObject vnfObj = JSONObject.fromObject(data);
+ VnfResourceMgr vnfResourceMgr = new VnfResourceMgr();
+ JSONObject result = vnfResourceMgr.grantVnfResource(vnfObj, "vnfId", "vnfmId");
+
+ JSONObject retJson = new JSONObject();
+ retJson.put("retCode", Constant.REST_FAIL);
+ retJson.put("errorMsg", "basic params error");
+ assertEquals(retJson, result);
+ }
+
+ @Test
+ public void testgrantVnfResourceByJSONException() {
+ String data =
+ "{\"operation_right\": \"increase\",\"vnf_name\": \"vnf_name\",\"vm_list\": [{\"vm_flavor\": {\"storage\": [{\"vol_type\": \"local_volume\",\"vol_size\": \"2\",\"storage_type\": \"local_image\",\"disk_size\": \"100\"}],\"num_cpus\": \"6\",\"mem_size\": \"8\"},\"init_number\": \"1\"}],\"version\": \"version\",\"template_id\": \"template_id\",\"template_name\": \"template_name\",\"plan_id\": \"plan_id\",\"plan_name\": \"plan_name\",\"project_id\": \"project_id\",\"project_name\": \"project_name\",\"creator\": \"creator\",\"status\": \"status\",\"tenant\": \"tenant\",\"parent_tenant\": \"parent_tenant\",\"vnfd_id\": \"vnfd_id\",\"location\": \"location\",\"dr_location\": \"dr_location\",\"nfvo_id\": \"nfvo_id\"}";
+ JSONObject vnfObj = JSONObject.fromObject(data);
+ VnfResourceMgr vnfResourceMgr = new VnfResourceMgr();
+ JSONObject result = vnfResourceMgr.grantVnfResource(vnfObj, "vnfId", "vnfmId");
+
+ JSONObject retJson = new JSONObject();
+ retJson.put("retCode", Constant.REST_FAIL);
+ retJson.put("errorMsg", "params parse exception");
+ assertEquals(retJson, result);
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/AuthRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/AuthRoaTest.java
new file mode 100644
index 00000000..558d43ed
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/AuthRoaTest.java
@@ -0,0 +1,203 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.rest;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.nfvo.vnfmadapter.common.VnfmJsonUtil;
+import org.openo.nfvo.vnfmadapter.service.constant.Constant;
+import org.openo.nfvo.vnfmadapter.service.process.AuthMgr;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+public class AuthRoaTest {
+
+ private AuthRoa authRoa;
+
+ private AuthMgr authMgr;
+
+ @Before
+ public void setUp() {
+ authRoa = new AuthRoa();
+ authMgr = new AuthMgr();
+ authRoa.setAuthMgr(authMgr);
+ }
+
+ @After
+ public void tearDown() {
+ authRoa = null;
+ authMgr = null;
+ }
+
+ @Test
+ public void testAuthTokenBySubJsonObjectNull() {
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+ new MockUp<VnfmJsonUtil>() {
+
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest context) {
+ return null;
+ }
+ };
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ String result = authRoa.authToken(mockInstance, mockResInstance);
+
+ assertEquals("Login params insufficient", result);
+ }
+
+ @Test
+ public void testAuthTokenByFail() {
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest context) {
+ JSONObject subJsonObject = new JSONObject();
+ return (T)subJsonObject;
+ }
+ };
+ new MockUp<AuthMgr>() {
+
+ @Mock
+ public JSONObject authToken(JSONObject params) {
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_FAIL);
+ restJson.put("data", "Fail!");
+ return restJson;
+ }
+ };
+ String result = authRoa.authToken(mockInstance, mockResInstance);
+
+ assertEquals("{\"Information\": \"Fail!\"}", result);
+ }
+
+ @Test
+ public void testAuthTokenByHttpInnerError() {
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest context) {
+ JSONObject subJsonObject = new JSONObject();
+ return (T)subJsonObject;
+ }
+ };
+ new MockUp<AuthMgr>() {
+
+ @Mock
+ public JSONObject authToken(JSONObject params) {
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.HTTP_INNERERROR);
+ restJson.put("data", "HttpInnerError!");
+ return restJson;
+ }
+ };
+ String result = authRoa.authToken(mockInstance, mockResInstance);
+
+ assertEquals("{\"Information\": \"HttpInnerError!\"}", result);
+ }
+
+ @Test
+ public void testAuthToken() {
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest context) {
+ JSONObject subJsonObject = new JSONObject();
+ return (T)subJsonObject;
+ }
+ };
+ new MockUp<AuthMgr>() {
+
+ @Mock
+ public JSONObject authToken(JSONObject params) {
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_SUCCESS);
+ JSONObject data = new JSONObject();
+ data.put("accessSession", "accessSession");
+ data.put("userName", "userName");
+ data.put("roaRand", "roaRand");
+ restJson.put("data", data);
+ return restJson;
+ }
+ };
+ String result = authRoa.authToken(mockInstance, mockResInstance);
+
+ assertEquals(
+ "{\"token\": {\"methods\": [\"password\"],\"expires_at\": \"\",\"user\": {\"id\": \"userName\",\"name\": \"userName\"},\"roa_rand\": \"roaRand\"}}",
+ result);
+ }
+
+ @Test
+ public void testDelAuthToken() {
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+ String result = authRoa.delAuthToken(mockInstance, null, null, mockResInstance);
+
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("Information", "Operation success");
+ assertEquals(resultJson.toString(), result);
+ }
+
+ @Test
+ public void testShakehand() {
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+ String result = authRoa.shakehand(mockInstance, null, mockResInstance);
+
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("status", "running");
+ resultJson.put("description", "Operation success");
+ assertEquals(resultJson.toString(), result);
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/SwaggerRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/SwaggerRoaTest.java
new file mode 100644
index 00000000..ba68ed82
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/SwaggerRoaTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.rest;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Jan 13, 2017
+ */
+public class SwaggerRoaTest {
+
+ @Test
+ public void testApidoc() throws IOException {
+ SwaggerRoa swaggerRoa = new SwaggerRoa();
+ String result = swaggerRoa.apidoc();
+ assertNotNull(result);
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/VnfAdapterResourceRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/VnfAdapterResourceRoaTest.java
new file mode 100644
index 00000000..75b37f69
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/VnfAdapterResourceRoaTest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.rest;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.openo.nfvo.vnfmadapter.service.adapter.impl.AdapterResourceManager;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Jan 13, 2017
+ */
+public class VnfAdapterResourceRoaTest {
+
+ @Test
+ public void testGetAllCloudInfo() {
+ new MockUp<AdapterResourceManager>() {
+
+ @Mock
+ public JSONObject getAllCloud(String url) {
+ JSONObject resultObj = new JSONObject();
+ resultObj.put("dn", "test");
+ return resultObj;
+ }
+ };
+
+ VnfAdapterResourceRoa vnfAdapter = new VnfAdapterResourceRoa();
+ String result = vnfAdapter.getAllCloudInfo(null);
+ assertEquals("test", result);
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/VnfResourceRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/VnfResourceRoaTest.java
new file mode 100644
index 00000000..016d373b
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/VnfResourceRoaTest.java
@@ -0,0 +1,268 @@
+/*
+ * Copyright 2016-2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.rest;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.nfvo.vnfmadapter.common.VnfmJsonUtil;
+import org.openo.nfvo.vnfmadapter.common.VnfmUtil;
+import org.openo.nfvo.vnfmadapter.service.constant.Constant;
+import org.openo.nfvo.vnfmadapter.service.process.VnfResourceMgr;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+public class VnfResourceRoaTest {
+
+ private VnfResourceRoa vnfResourceRoa;
+
+ private VnfResourceMgr vnfResourceMgr;
+
+ @Before
+ public void setUp() {
+ vnfResourceRoa = new VnfResourceRoa();
+ vnfResourceMgr = new VnfResourceMgr();
+ vnfResourceRoa.setVnfResourceMgr(vnfResourceMgr);
+ }
+
+ @After
+ public void tearDown() {
+ vnfResourceRoa = null;
+ vnfResourceMgr = null;
+ }
+
+ @Test
+ public void testGrantVnfResByDataObjectNull() {
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+ new MockUp<VnfmJsonUtil>() {
+
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest context) {
+ return null;
+ }
+ };
+
+ String result = vnfResourceRoa.grantVnfRes(mockInstance, "vnfId");
+
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_FAIL);
+ restJson.put("data", "Params error");
+ assertEquals(restJson.toString(), result);
+ }
+
+ @Test
+ public void testGrantVnfResByGrantObjNull() {
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+ final JSONObject dataObject = new JSONObject();
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest context) {
+ return (T)dataObject;
+ }
+ };
+ new MockUp<JSONObject>() {
+
+ @Mock
+ public JSONObject getJSONObject(String key) {
+ if(key == "grant") {
+ return null;
+ }
+ return dataObject;
+ }
+ };
+
+ String result = vnfResourceRoa.grantVnfRes(mockInstance, "vnfId");
+
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_FAIL);
+ restJson.put("data", "Grant param error");
+ assertEquals(restJson.toString(), result);
+ }
+
+ @Test
+ public void testGrantVnfRes() {
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {
+
+ @Mock
+ public String getHeader(String name) {
+ return "127.0.0.1";
+ }
+ };
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+ final JSONObject dataObject = new JSONObject();
+ JSONObject grant = new JSONObject();
+ grant.put("project_id", "project_id");
+ dataObject.put("grant", grant);
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest context) {
+ return (T)dataObject;
+ }
+ };
+ new MockUp<VnfmUtil>() {
+
+ @Mock
+ public String getVnfmIdByIp(String ip) {
+ return "vnfmId";
+ }
+ };
+
+ new MockUp<VnfResourceMgr>() {
+
+ @Mock
+ public JSONObject grantVnfResource(JSONObject vnfObj, String vnfId, String vnfmId) {
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("retCode", Constant.REST_SUCCESS);
+ JSONObject data = new JSONObject();
+ data.put("data", "success");
+ resultJson.put("data", data);
+ return resultJson;
+ }
+ };
+ String result = vnfResourceRoa.grantVnfRes(mockInstance, "vnfId");
+
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_SUCCESS);
+ JSONObject data = new JSONObject();
+ data.put("data", "success");
+ restJson.put("data", data);
+ assertEquals(restJson.toString(), result);
+ }
+
+ @Test
+ public void testGrantVnfResByFail() {
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {
+
+ @Mock
+ public String getHeader(String name) {
+ return "127.0.0.1";
+ }
+ };
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+ final JSONObject dataObject = new JSONObject();
+ JSONObject grant = new JSONObject();
+ grant.put("project_id", "project_id");
+ dataObject.put("grant", grant);
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest context) {
+ return (T)dataObject;
+ }
+ };
+ new MockUp<VnfmUtil>() {
+
+ @Mock
+ public String getVnfmIdByIp(String ip) {
+ return "vnfmId";
+ }
+ };
+
+ new MockUp<VnfResourceMgr>() {
+
+ @Mock
+ public JSONObject grantVnfResource(JSONObject vnfObj, String vnfId, String vnfmId) {
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("retCode", Constant.REST_FAIL);
+ resultJson.put("data", "Fail!");
+ return resultJson;
+ }
+ };
+ String result = vnfResourceRoa.grantVnfRes(mockInstance, "vnfId");
+
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_FAIL);
+ restJson.put("data", "Fail!");
+ assertEquals(restJson.toString(), result);
+ }
+
+ @Test
+ public void testGrantVnfResByDataNull() {
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {
+
+ @Mock
+ public String getHeader(String name) {
+ return "127.0.0.1";
+ }
+ };
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+ final JSONObject dataObject = new JSONObject();
+ JSONObject grant = new JSONObject();
+ grant.put("project_id", "project_id");
+ dataObject.put("grant", grant);
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest context) {
+ return (T)dataObject;
+ }
+ };
+ new MockUp<VnfmUtil>() {
+
+ @Mock
+ public String getVnfmIdByIp(String ip) {
+ return "vnfmId";
+ }
+ };
+
+ new MockUp<VnfResourceMgr>() {
+
+ @Mock
+ public JSONObject grantVnfResource(JSONObject vnfObj, String vnfId, String vnfmId) {
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("retCode", Constant.REST_FAIL);
+ return resultJson;
+ }
+ };
+ String result = vnfResourceRoa.grantVnfRes(mockInstance, "vnfId");
+
+ JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_FAIL);
+ assertEquals(restJson.toString(), result);
+ }
+
+ @Test
+ public void testNotify() {
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {
+
+ @Mock
+ public String getHeader(String name) {
+ return "127.0.0.1";
+ }
+ };
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+ String result = vnfResourceRoa.notify(mockInstance);
+
+ JSONObject restJson = new JSONObject();
+ restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
+ assertEquals(restJson.toString(), result);
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/VnfRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/VnfRoaTest.java
new file mode 100644
index 00000000..08e28bca
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/VnfRoaTest.java
@@ -0,0 +1,579 @@
+/*
+ * Copyright 2016-2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.rest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.vnfmadapter.common.VnfmJsonUtil;
+import org.openo.nfvo.vnfmadapter.service.constant.Constant;
+import org.openo.nfvo.vnfmadapter.service.process.VnfMgr;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+public class VnfRoaTest {
+
+ private VnfRoa vnfRoa;
+
+ private VnfMgr vnfMgr;
+
+ @Before
+ public void setUp() {
+ vnfRoa = new VnfRoa();
+ vnfMgr = new VnfMgr();
+ vnfRoa.setVnfMgr(vnfMgr);
+ }
+
+ @After
+ public void tearDown() {
+ vnfRoa = null;
+ vnfMgr = null;
+ }
+
+ @Test
+ public void testAddVnf() throws ServiceException {
+ final JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_SUCCESS);
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject addVnf(JSONObject subJsonObject, String vnfmId) {
+ JSONObject retJson = new JSONObject();
+ retJson.put("id", "123");
+ restJson.put("data", retJson);
+ return restJson;
+ }
+ };
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+ return (T)restJson;
+ }
+ };
+
+ String result = vnfRoa.addVnf(mockInstance, mockResInstance, "vnfmId");
+
+ JSONObject retJson = new JSONObject();
+ retJson.put("id", "123");
+ assertEquals(retJson.toString(), result);
+
+ }
+
+ @Test
+ public void testAddVnfFail() throws ServiceException {
+ final JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_FAIL);
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject addVnf(JSONObject subJsonObject, String vnfmId) {
+ return restJson;
+ }
+ };
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+ return (T)restJson;
+ }
+ };
+
+ String result = vnfRoa.addVnf(mockInstance, mockResInstance, "vnfmId");
+
+ assertEquals(restJson.toString(), result);
+
+ }
+
+ @Test
+ public void testAddVnfBySubJsonObjectNull() throws ServiceException {
+ final JSONObject restJson = new JSONObject();
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ new MockUp<VnfmJsonUtil>() {
+
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest context) {
+ return null;
+ }
+ };
+
+ String result = vnfRoa.addVnf(mockInstance, mockResInstance, "vnfmId");
+
+ assertEquals(restJson.toString(), result);
+
+ }
+
+ @Test
+ public void testDelVnf() throws ServiceException {
+ final JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_SUCCESS);
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject deleteVnf(String vnfId, String vnfmId, JSONObject vnfObject) {
+ JSONObject retJson = new JSONObject();
+ retJson.put("id", "123");
+ restJson.put("data", retJson);
+ return restJson;
+ }
+ };
+
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+ return (T)restJson;
+ }
+ };
+
+ String result = vnfRoa.delVnf("vnfmId", mockResInstance, "vnfId", mockInstance);
+ JSONObject retJson = new JSONObject();
+ retJson.put("id", "123");
+ assertEquals(retJson.toString(), result);
+ }
+
+ @Test
+ public void testDelVnfByVnfIdIsEmpty() throws ServiceException {
+ final JSONObject restJson = new JSONObject();
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+ return (T)restJson;
+ }
+ };
+
+ String result = vnfRoa.delVnf("vnfmId", mockResInstance, "", mockInstance);
+
+ assertEquals(restJson.toString(), result);
+ }
+
+ @Test
+ public void testDelVnfByVnfmIdIsEmpty() throws ServiceException {
+ final JSONObject restJson = new JSONObject();
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+ return (T)restJson;
+ }
+ };
+
+ String result = vnfRoa.delVnf("", mockResInstance, "vnfId", mockInstance);
+
+ assertEquals(restJson.toString(), result);
+ }
+
+ @Test
+ public void testDelVnfByVnfIdVnfmIdEmpty() throws ServiceException {
+ final JSONObject restJson = new JSONObject();
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+ return (T)restJson;
+ }
+ };
+
+ String result = vnfRoa.delVnf("", mockResInstance, "", mockInstance);
+
+ assertEquals(restJson.toString(), result);
+ }
+
+ @Test
+ public void testDelVnfFail() throws ServiceException {
+ final JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_FAIL);
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject deleteVnf(String vnfId, String vnfmId, JSONObject vnfObject) {
+ return restJson;
+ }
+ };
+
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+ return (T)restJson;
+ }
+ };
+
+ String result = vnfRoa.delVnf("vnfmId", mockResInstance, "vnfId", mockInstance);
+ assertEquals(restJson.toString(), result);
+ }
+
+ @Test
+ public void testGetVnfByVnfIdIsEmpty() throws ServiceException {
+ final JSONObject restJson = new JSONObject();
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+ return (T)restJson;
+ }
+ };
+
+ String result = vnfRoa.getVnf("vnfmId", mockResInstance, "", mockInstance);
+
+ assertEquals(restJson.toString(), result);
+ }
+
+ @Test
+ public void testGetVnfByVnfmIdIsEmpty() throws ServiceException {
+ final JSONObject restJson = new JSONObject();
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+ return (T)restJson;
+ }
+ };
+
+ String result = vnfRoa.getVnf("", mockResInstance, "vnfId", mockInstance);
+
+ assertEquals(restJson.toString(), result);
+ }
+
+ @Test
+ public void testGetVnfFail() throws ServiceException {
+ final JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_FAIL);
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject getVnf(String vnfId, String vnfmId) {
+ return restJson;
+ }
+ };
+
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+ return (T)restJson;
+ }
+ };
+
+ String result = vnfRoa.getVnf("vnfmId", mockResInstance, "vnfId", mockInstance);
+ assertEquals(restJson.toString(), result);
+ }
+
+ @Test
+ public void testGetVnf() throws ServiceException {
+ final JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_SUCCESS);
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject getVnf(String vnfId, String vnfmId) {
+ JSONObject retJson = new JSONObject();
+ JSONObject basicInfoJson = new JSONObject();
+ basicInfoJson.put("vnfInstanceId", "123");
+ basicInfoJson.put("vnfInstanceName", "1");
+ basicInfoJson.put("vnfInstanceDescription", "vFW");
+ basicInfoJson.put("vnfdId", "1");
+ basicInfoJson.put("vnfdPackageId", "vFW");
+ basicInfoJson.put("version", "vFW");
+ basicInfoJson.put("vnfProvider", "hw");
+ basicInfoJson.put("vnfType", "fw");
+ basicInfoJson.put("vnfStatus", "active");
+ retJson.put("vnfInfo", basicInfoJson);
+ retJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
+ return retJson;
+ }
+ };
+
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+ return (T)restJson;
+ }
+ };
+
+ String result = vnfRoa.getVnf("vnfmId", mockResInstance, "vnfId", mockInstance);
+ JSONObject basicInfoJson = new JSONObject();
+ JSONObject retJson = new JSONObject();
+ basicInfoJson.put("vnfInstanceId", "123");
+ basicInfoJson.put("vnfInstanceName", "1");
+ basicInfoJson.put("vnfInstanceDescription", "vFW");
+ basicInfoJson.put("vnfdId", "1");
+ basicInfoJson.put("vnfdPackageId", "vFW");
+ basicInfoJson.put("version", "vFW");
+ basicInfoJson.put("vnfProvider", "hw");
+ basicInfoJson.put("vnfType", "fw");
+ basicInfoJson.put("vnfStatus", "active");
+ retJson.put("vnfInfo", basicInfoJson);
+ assertEquals(retJson.toString(), result);
+ }
+
+ @Test
+ public void testGetJobByJobIdNull() throws ServiceException {
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ String result = vnfRoa.getJob(null, null, mockResInstance, "1111");
+ assertEquals("{}", result);
+ }
+
+ @Test
+ public void testGetJobByVnfmIdNull() throws ServiceException {
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ String result = vnfRoa.getJob("123", null, mockResInstance, "1111");
+ assertEquals("{}", result);
+ }
+
+ @Test
+ public void testGetJobByVnfMgrFail() throws ServiceException {
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject getJob(String jobId, String vnfmId) {
+ JSONObject restJson = new JSONObject();
+ restJson.put(Constant.RETCODE, Constant.REST_FAIL);
+ return restJson;
+ }
+ };
+ String result = vnfRoa.getJob("123", "1234", mockResInstance, "1111");
+ assertEquals("{\"retCode\":-1}", result);
+ }
+
+ @Test
+ public void testGetJob() throws ServiceException {
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject getJob(String jobId, String vnfmId) {
+ JSONObject restJson = new JSONObject();
+ JSONArray data = new JSONArray();
+ JSONObject obj = new JSONObject();
+ obj.put("id", "11111");
+ obj.put("status", "Active");
+ data.add(obj);
+ restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
+ restJson.put("data", data);
+ return restJson;
+ }
+ };
+
+ String result = vnfRoa.getJob("123", "1234", null, "1111");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testScaleVnf() throws ServiceException {
+ final JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_SUCCESS);
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject scaleVNF(JSONObject vnfObject, String vnfmId, String vnfInstanceId) {
+ JSONObject retJson = new JSONObject();
+ retJson.put("id", "123");
+ restJson.put("data", retJson);
+ return restJson;
+ }
+ };
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+ return (T)restJson;
+ }
+ };
+
+ String result = vnfRoa.scaleVnf(mockInstance,mockResInstance,"id","id");
+
+ JSONObject retJson = new JSONObject();
+ retJson.put("id", "123");
+ assertEquals(retJson.toString(), result);
+
+ }
+ @Test
+ public void testScaleVnfFail() throws ServiceException {
+ final JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_FAIL);
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject scaleVNF(JSONObject vnfObject, String vnfmId, String vnfInstanceId) {
+ JSONObject retJson = new JSONObject();
+ retJson.put("id", "123");
+ restJson.put("data", retJson);
+ return restJson;
+ }
+ };
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+ return (T)restJson;
+ }
+ };
+ String result = vnfRoa.scaleVnf(mockInstance,mockResInstance,"id","id");
+
+ assertEquals(restJson.toString(), result);
+
+ }
+
+ @Test
+ public void testScaleVnfFail2() throws ServiceException {
+ final JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_FAIL);
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject scaleVNF(JSONObject vnfObject, String vnfmId, String vnfInstanceId) {
+ JSONObject retJson = new JSONObject();
+ retJson.put("id", "123");
+ restJson.put("data", retJson);
+ return restJson;
+ }
+ };
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+ return null;
+ }
+ };
+ String result = vnfRoa.scaleVnf(mockInstance,mockResInstance,"id","id");
+
+ assertEquals(restJson.toString(), result);
+
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/exceptionmapper/ExceptionMessageTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/exceptionmapper/ExceptionMessageTest.java
new file mode 100644
index 00000000..ca660581
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/exceptionmapper/ExceptionMessageTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.rest.exceptionmapper;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Jan 13, 2017
+ */
+public class ExceptionMessageTest {
+
+ @Test
+ public void testToString() {
+ ExceptionMessage message = new ExceptionMessage();
+ message.setErrorCode("1");
+ message.setHttpCode(200);
+ message.setMessage("Success!");
+ String str = message.toString();
+ assertNotNull(str);
+ }
+
+ @Test
+ public void testGetErrorCode() {
+ ExceptionMessage message = new ExceptionMessage();
+ message.setErrorCode("1");
+ String str = message.getErrorCode();
+ assertEquals("1", str);
+ }
+
+ @Test
+ public void testHttpCode() {
+ ExceptionMessage message = new ExceptionMessage();
+ message.setHttpCode(200);
+ int str = message.getHttpCode();
+ assertEquals(200, str);
+ }
+
+ @Test
+ public void testGetMessage() {
+ ExceptionMessage message = new ExceptionMessage();
+ message.setMessage("Success!");
+ String str = message.getMessage();
+ assertEquals("Success!", str);
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/exceptionmapper/GenericExceptionMapperTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/exceptionmapper/GenericExceptionMapperTest.java
new file mode 100644
index 00000000..370cbc81
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/exceptionmapper/GenericExceptionMapperTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.rest.exceptionmapper;
+
+import static org.junit.Assert.assertNotNull;
+
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Jan 13, 2017
+ */
+public class GenericExceptionMapperTest {
+
+ @Test
+ public void testToResponse() {
+ GenericExceptionMapper excep = new GenericExceptionMapper();
+ Exception exception = new Exception("message");
+ Response res = excep.toResponse(exception);
+ assertNotNull(res);
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/exceptionmapper/ServiceExceptionMapperTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/exceptionmapper/ServiceExceptionMapperTest.java
new file mode 100644
index 00000000..c9deb393
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/service/rest/exceptionmapper/ServiceExceptionMapperTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.service.rest.exceptionmapper;
+
+import static org.junit.Assert.assertNotNull;
+
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Jan 13, 2017
+ */
+public class ServiceExceptionMapperTest {
+
+ @Test
+ public void testToResponse() {
+ ServiceExceptionMapper mapper = new ServiceExceptionMapper();
+ ServiceException exception = new ServiceException();
+ Response res = mapper.toResponse(exception);
+ assertNotNull(res);
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/testutils/JsonUtil.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/testutils/JsonUtil.java
new file mode 100644
index 00000000..c3f88547
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/openo/nfvo/vnfmadapter/testutils/JsonUtil.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.nfvo.vnfmadapter.testutils;
+
+
+import java.io.IOException;
+
+import org.codehaus.jackson.map.DeserializationConfig.Feature;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.type.TypeReference;
+
+import net.sf.json.JSON;
+
+public final class JsonUtil {
+ private static final ObjectMapper MAPPER = new ObjectMapper();
+
+ public static <T> T unMarshal(String jsonstr, Class<T> type) throws IOException {
+ return MAPPER.readValue(jsonstr, type);
+ }
+
+ public static <T> T unMarshal(String jsonstr, TypeReference<T> type) throws IOException {
+ return MAPPER.readValue(jsonstr, type);
+ }
+
+ public static String marshal(Object srcObj) throws IOException {
+ return srcObj instanceof JSON ? srcObj.toString() : MAPPER.writeValueAsString(srcObj);
+ }
+
+ public static ObjectMapper getMapper() {
+ return MAPPER;
+ }
+
+ static {
+ MAPPER.setDeserializationConfig(
+ MAPPER.getDeserializationConfig().without(new Feature[] { Feature.FAIL_ON_UNKNOWN_PROPERTIES }));
+ }
+} \ No newline at end of file