From 0523050a87a5f0a1801c9cd9dcf8b67b5818b4e1 Mon Sep 17 00:00:00 2001 From: "victor.gao" Date: Thu, 17 Aug 2017 22:39:16 +0800 Subject: Update vfc svnfm driver pom Update groupid and re-trigger vnfm driver build job Change-Id: Ib5d52c98eb03d357636a2ba7b9fa5121ed1d0525 Issue-Id:VFC-81 Signed-off-by: victor.gao --- .../common/DownloadCsarManagerTest.java | 76 +++ .../vnfm/svnfm/vnfmadapter/common/FileUtil.java | 50 ++ .../vnfmadapter/common/ResultRequestUtilTest.java | 64 +++ .../svnfm/vnfmadapter/common/VnfmUtilTest.java | 114 ++++ .../common/servicetoken/HttpRestfulHelpTest.java | 47 ++ .../common/servicetoken/VNFRestfulUtilTest.java | 323 ++++++++++++ .../common/servicetoken/VnfmRestfulUtilTest.java | 241 +++++++++ .../activator/RoaVnfmServicePostProcessorTest.java | 53 ++ .../activator/TestRoaVnfmService2DriverMgr.java | 53 ++ .../adapter/impl/AdapterResourceManagerTest.java | 312 +++++++++++ .../adapter/impl/Driver2MSBManagerTest.java | 282 ++++++++++ .../impl/VnfmAdapter2DriverManagerTest.java | 282 ++++++++++ .../impl/VnfmAdapter2DriverMgrServiceTest.java | 51 ++ .../impl/VnfmAdapterMgrServiceTest.java | 45 ++ .../vnfmadapter/service/constant/TestConstant.java | 41 ++ .../service/csm/api/ConnectInfoTest.java | 90 ++++ .../csm/connect/AbstractSslContextTest.java | 47 ++ .../service/csm/connect/HttpRequestsTest.java | 99 ++++ .../csm/connect/SslAnonymousSocketTest.java | 52 ++ .../csm/connect/SslCertificateSocketTest.java | 80 +++ .../csm/connect/SslProtocolSocketFactoryTest.java | 48 ++ .../service/csm/vnf/VnfMgrVnfmTest.java | 308 +++++++++++ .../service/dao/impl/VnfmDaoImplTest.java | 65 +++ .../svnfm/vnfmadapter/service/entity/VnfmTest.java | 78 +++ .../vnfmadapter/service/process/AuthMgrTest.java | 65 +++ .../service/process/RegisterMgrTest.java | 67 +++ .../vnfmadapter/service/process/VnfMgrTest.java | 498 ++++++++++++++++++ .../service/process/VnfResourceMgrTest.java | 236 +++++++++ .../vnfmadapter/service/rest/AuthRoaTest.java | 204 ++++++++ .../vnfmadapter/service/rest/SwaggerRoaTest.java | 43 ++ .../service/rest/VnfAdapterResourceRoaTest.java | 56 ++ .../service/rest/VnfResourceRoaTest.java | 269 ++++++++++ .../svnfm/vnfmadapter/service/rest/VnfRoaTest.java | 580 +++++++++++++++++++++ .../rest/exceptionmapper/ExceptionMessageTest.java | 69 +++ .../GenericExceptionMapperTest.java | 44 ++ .../ServiceExceptionMapperTest.java | 45 ++ .../vnfm/svnfm/vnfmadapter/testutils/JsonUtil.java | 51 ++ 37 files changed, 5128 insertions(+) create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManagerTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/FileUtil.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmUtilTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/HttpRestfulHelpTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VNFRestfulUtilTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/activator/RoaVnfmServicePostProcessorTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/activator/TestRoaVnfmService2DriverMgr.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManagerTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/Driver2MSBManagerTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/VnfmAdapter2DriverManagerTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/TestConstant.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/api/ConnectInfoTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/AbstractSslContextTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/HttpRequestsTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/SslAnonymousSocketTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/SslCertificateSocketTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/SslProtocolSocketFactoryTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfmTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/dao/impl/VnfmDaoImplTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/entity/VnfmTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/AuthMgrTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/RegisterMgrTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgrTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfResourceMgrTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/AuthRoaTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/SwaggerRoaTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfAdapterResourceRoaTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfResourceRoaTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/exceptionmapper/ExceptionMessageTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/exceptionmapper/GenericExceptionMapperTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/exceptionmapper/ServiceExceptionMapperTest.java create mode 100644 huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/testutils/JsonUtil.java (limited to 'huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap') diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManagerTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManagerTest.java new file mode 100644 index 00000000..6d396d54 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManagerTest.java @@ -0,0 +1,76 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.DownloadCsarManager; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmJsonUtil; +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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/FileUtil.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/FileUtil.java new file mode 100644 index 00000000..d5a0e7e4 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/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.onap.vfc.nfvo.vnfm.svnfm.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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java new file mode 100644 index 00000000..0dc6751b --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.ResultRequestUtil; +import org.onap.vfc.nfvo.vnfm.svnfm.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(){ + @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(){ + @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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmUtilTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmUtilTest.java new file mode 100644 index 00000000..d3f773e9 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmUtilTest.java @@ -0,0 +1,114 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmUtil; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.VnfmRestfulUtil; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; + +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(){ + @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(){ + @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(){ + @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(){ + @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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/HttpRestfulHelpTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/HttpRestfulHelpTest.java new file mode 100644 index 00000000..62f3f212 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/HttpRestfulHelpTest.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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.HttpRestfulHelp; +import org.openo.baseservice.roa.util.restclient.Restful; + +/** + *
+ *

+ *

+ * + * @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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VNFRestfulUtilTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VNFRestfulUtilTest.java new file mode 100644 index 00000000..cd6c0df2 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VNFRestfulUtilTest.java @@ -0,0 +1,323 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.VNFRestfulUtil; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.testutils.JsonUtil; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @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(){ + @Mock + public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) { + RestfulResponse resp = new RestfulResponse(); + resp.setStatus(200); + Map 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(){ + @Mock + public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) { + RestfulResponse resp = new RestfulResponse(); + resp.setStatus(200); + Map 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(){ + @Mock + public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) { + RestfulResponse resp = new RestfulResponse(); + resp.setStatus(500); + Map 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 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 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 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 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 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 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 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 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 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 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 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 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 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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java new file mode 100644 index 00000000..6c19feaa --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java @@ -0,0 +1,241 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.VnfmRestfulUtil; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; + +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() { + + @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() { + + @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() { + + @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 result = VnfmRestfulUtil.generateParamsMap("url", "methodType", "path", "authMode"); + Map paramsMap = new HashMap(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 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 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 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 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 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 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 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 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 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 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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/activator/RoaVnfmServicePostProcessorTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/activator/RoaVnfmServicePostProcessorTest.java new file mode 100644 index 00000000..7235be74 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/activator/RoaVnfmServicePostProcessorTest.java @@ -0,0 +1,53 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.activator; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.activator.RoaVnfmServicePostProcessor; +import org.onap.vfc.nfvo.vnfm.svnfm.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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/activator/TestRoaVnfmService2DriverMgr.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/activator/TestRoaVnfmService2DriverMgr.java new file mode 100644 index 00000000..7f0da0c0 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/activator/TestRoaVnfmService2DriverMgr.java @@ -0,0 +1,53 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.activator; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.activator.RoaVnfmService2DriverMgr; +import org.onap.vfc.nfvo.vnfm.svnfm.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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManagerTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManagerTest.java new file mode 100644 index 00000000..e6e0b23f --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManagerTest.java @@ -0,0 +1,312 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.DownloadCsarManager; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.VNFRestfulUtil; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.adapter.impl.AdapterResourceManager; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.testutils.JsonUtil; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; + +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 paramsMap = new HashMap<>(); + JSONObject res = manager.uploadVNFPackage(vnfpkg, paramsMap); + assertTrue(res != null); + + } + + @Test(expected = JSONException.class) + public void uploadVNFPackageTestJsonException2() { + JSONObject vnfpkg = new JSONObject(); + Map 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 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 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 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 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 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 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 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 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse resp = new RestfulResponse(); + resp.setStatus(200); + Map objMap = new HashMap(); + objMap.put("id", "test123"); + + String responseString = toJson(objMap); + resp.setResponseJson(responseString); + return resp; + } + + }; + Map paramsMap = new HashMap(); + JSONObject res = manager.getVnfmConnInfo(paramsMap); + assertTrue(res.get("id").equals("test123")); + } + + @Test + public void getVnfmConnInfoTestNullResp() { + new MockUp() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + + return null; + } + + }; + Map paramsMap = new HashMap(); + JSONObject res = manager.getVnfmConnInfo(paramsMap); + assertTrue(res.get("reason").equals("RestfulResponse is null.")); + } + + @Test + public void getVnfmConnInfoTestServerError() { + new MockUp() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse resp = new RestfulResponse(); + resp.setStatus(500); + Map objMap = new HashMap(); + objMap.put("id", "test123"); + + String responseString = toJson(objMap); + resp.setResponseJson(responseString); + return resp; + } + + }; + Map paramsMap = new HashMap(); + 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(){ + @Mock + public int unzipCSAR(String fileName,String filePath){ + return 0; + } + }; + manager.unzipCSAR("vCpe.zip","/opt"); + } + @Test + public void testUnzipCSAR5(){ + new MockUp(){ + @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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/Driver2MSBManagerTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/Driver2MSBManagerTest.java new file mode 100644 index 00000000..10e0305d --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/Driver2MSBManagerTest.java @@ -0,0 +1,282 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.VNFRestfulUtil; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.adapter.impl.Driver2MSBManager; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.testutils.JsonUtil; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Jan 24, 2017 + */ +public class Driver2MSBManagerTest { + + Driver2MSBManager manager = new Driver2MSBManager(); + + Map vim = new HashMap(); + + @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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + + return null; + } + }; + Map 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + response.setStatus(201); + + String vimStr = toJson(vim); + response.setResponseJson(vimStr); + return response; + } + }; + Map 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + response.setStatus(200); + + String vimStr = toJson(vim); + response.setResponseJson(vimStr); + return response; + } + }; + Map 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + response.setStatus(415); + + String vimStr = toJson(vim); + response.setResponseJson(vimStr); + return response; + } + }; + Map 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + response.setStatus(500); + + String vimStr = toJson(vim); + response.setResponseJson(vimStr); + return response; + } + }; + Map 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + + return null; + } + }; + Map 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + response.setStatus(204); + + String vimStr = toJson(vim); + response.setResponseJson(vimStr); + return response; + } + }; + Map 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + response.setStatus(404); + + String vimStr = toJson(vim); + response.setResponseJson(vimStr); + return response; + } + }; + Map 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + response.setStatus(415); + + String vimStr = toJson(vim); + response.setResponseJson(vimStr); + return response; + } + }; + Map 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + response.setStatus(500); + + String vimStr = toJson(vim); + response.setResponseJson(vimStr); + return response; + } + }; + Map 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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/VnfmAdapter2DriverManagerTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/VnfmAdapter2DriverManagerTest.java new file mode 100644 index 00000000..dc0431c5 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/VnfmAdapter2DriverManagerTest.java @@ -0,0 +1,282 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.VNFRestfulUtil; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.adapter.impl.VnfmAdapter2DriverManager; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.testutils.JsonUtil; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Jan 24, 2017 + */ +public class VnfmAdapter2DriverManagerTest { + + VnfmAdapter2DriverManager manager = new VnfmAdapter2DriverManager(); + + Map vim = new HashMap(); + + @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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + + return null; + } + }; + Map 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + response.setStatus(201); + + String vimStr = toJson(vim); + response.setResponseJson(vimStr); + return response; + } + }; + Map 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + response.setStatus(200); + + String vimStr = toJson(vim); + response.setResponseJson(vimStr); + return response; + } + }; + Map 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + response.setStatus(415); + + String vimStr = toJson(vim); + response.setResponseJson(vimStr); + return response; + } + }; + Map 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + response.setStatus(500); + + String vimStr = toJson(vim); + response.setResponseJson(vimStr); + return response; + } + }; + Map 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + + return null; + } + }; + Map 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + response.setStatus(204); + + String vimStr = toJson(vim); + response.setResponseJson(vimStr); + return response; + } + }; + Map 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + response.setStatus(404); + + String vimStr = toJson(vim); + response.setResponseJson(vimStr); + return response; + } + }; + Map 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + response.setStatus(415); + + String vimStr = toJson(vim); + response.setResponseJson(vimStr); + return response; + } + }; + Map 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() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse response = new RestfulResponse(); + response.setStatus(500); + + String vimStr = toJson(vim); + response.setResponseJson(vimStr); + return response; + } + }; + Map 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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java new file mode 100644 index 00000000..12910c8e --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.ai.internalsvc.impl; + +import mockit.Mock; +import mockit.MockUp; +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.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(){ + @Mock + public String readVnfmAdapterInfoFromJson() throws IOException { + return "{'url':'http://127.0.0.1'}"; + + } + }; + VnfmAdapter2DriverMgrService mgr = new VnfmAdapter2DriverMgrService(); + mgr.register(); + mgr.unregister(); + } +} diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java new file mode 100644 index 00000000..84a7c914 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.ai.internalsvc.impl; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.api.internalsvc.impl.VnfmAdapterMgrService; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.VnfMgr; + +import java.io.IOException; + +/** + * Created by QuanZhong on 2017/3/20. + */ +public class VnfmAdapterMgrServiceTest { + @Test + public void testRegister(){ + new MockUp(){ + + @Mock + public String readVnfmAdapterInfoFromJson() throws IOException { + return "{'abc':'123'}"; + } + }; + VnfmAdapterMgrService mgr = new VnfmAdapterMgrService(); + mgr.register(); + + } +} diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/TestConstant.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/TestConstant.java new file mode 100644 index 00000000..7780c648 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/TestConstant.java @@ -0,0 +1,41 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant; + +import junit.framework.Assert; +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.ParamConstants; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.UrlConstant; + +import static org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant.AUTHLIST; + +import java.util.List; + +/** + * Created by QuanZhong on 2017/3/17. + */ +public class TestConstant { + @Test + public void testCreate(){ + List 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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/api/ConnectInfoTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/api/ConnectInfoTest.java new file mode 100644 index 00000000..93e9e39f --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/api/ConnectInfoTest.java @@ -0,0 +1,90 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.api; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.api.ConnectInfo; + +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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/AbstractSslContextTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/AbstractSslContextTest.java new file mode 100644 index 00000000..d89c3e8d --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/AbstractSslContextTest.java @@ -0,0 +1,47 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.connect; + +import net.sf.json.JSONObject; +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.connect.AbstractSslContext; + +/** + * 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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/HttpRequestsTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/HttpRequestsTest.java new file mode 100644 index 00000000..185f2b28 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/HttpRequestsTest.java @@ -0,0 +1,99 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmException; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.connect.HttpRequests; + +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
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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/SslAnonymousSocketTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/SslAnonymousSocketTest.java new file mode 100644 index 00000000..1e382a4e --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/SslAnonymousSocketTest.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.onap.vfc.nfvo.vnfm.svnfm.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; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.connect.SslAnonymousSocket; + +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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/SslCertificateSocketTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/SslCertificateSocketTest.java new file mode 100644 index 00000000..658b6dc0 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/SslCertificateSocketTest.java @@ -0,0 +1,80 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.connect; + +import org.apache.commons.httpclient.params.HttpConnectionParams; +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmException; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.connect.SslCertificateSocket; + +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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/SslProtocolSocketFactoryTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/SslProtocolSocketFactoryTest.java new file mode 100644 index 00000000..27236ca7 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/SslProtocolSocketFactoryTest.java @@ -0,0 +1,48 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.connect; + +import static org.junit.Assert.*; + +import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmException; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.connect.SslProtocolSocketFactory; + +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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfmTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfmTest.java new file mode 100644 index 00000000..863c5bee --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfmTest.java @@ -0,0 +1,308 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.vnf; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.ResultRequestUtil; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.vnf.VnfMgrVnfm; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 10, 2016 + */ +public class VnfMgrVnfmTest { + + @Test + public void testCreateVnf() { + new MockUp() { + + @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() { + + @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() { + + @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() { + + @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() { + + @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() { + + @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(){ + @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(){ + @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(){ + @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(){ + @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() { + + @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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/dao/impl/VnfmDaoImplTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/dao/impl/VnfmDaoImplTest.java new file mode 100644 index 00000000..6a2604d5 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/dao/impl/VnfmDaoImplTest.java @@ -0,0 +1,65 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.dao.impl; + +import junit.framework.Assert; +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.dao.impl.VnfmDaoImpl; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.entity.Vnfm; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +/** + * 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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/entity/VnfmTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/entity/VnfmTest.java new file mode 100644 index 00000000..7da877ac --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/entity/VnfmTest.java @@ -0,0 +1,78 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.entity; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.entity.Vnfm; + +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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/AuthMgrTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/AuthMgrTest.java new file mode 100644 index 00000000..d19889cd --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/AuthMgrTest.java @@ -0,0 +1,65 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.VnfmRestfulUtil; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.AuthMgr; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; + +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() { + + @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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/RegisterMgrTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/RegisterMgrTest.java new file mode 100644 index 00000000..7273878c --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/RegisterMgrTest.java @@ -0,0 +1,67 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process; + +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.VnfmRestfulUtil; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.RegisterMgr; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; + +import mockit.Mock; +import mockit.MockUp; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Jan 13, 2017 + */ +public class RegisterMgrTest { + + @Test + public void testRegister() { + new MockUp() { + + @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() { + + @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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgrTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgrTest.java new file mode 100644 index 00000000..60d11b0b --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgrTest.java @@ -0,0 +1,498 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process; + +import static org.junit.Assert.assertEquals; + +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.ResultRequestUtil; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmUtil; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.adapter.impl.AdapterResourceManager; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.vnf.VnfMgrVnfm; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.dao.impl.VnfmDaoImpl; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.dao.inf.VnfmDao; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.entity.Vnfm; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.VnfMgr; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +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() { + + @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() { + + @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() { + + @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() { + + @Mock + public JSONObject createVnf(JSONObject subJsonObject, JSONObject vnfmObjcet) { + JSONObject restJson = new JSONObject(); + restJson.put("retCode", Constant.REST_SUCCESS); + return restJson; + } + }; + + new MockUp() { + + @Mock + public JSONObject uploadVNFPackage(JSONObject subJsonObject, Map 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() { + + @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() { + + @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() { + + @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() { + + @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() { + + @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() { + + @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() { + + @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() { + + @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() { + + @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() { + + @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() { + + @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() { + + @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() { + + @Mock + public JSONObject getVnfmById(String vnfmId) { + JSONObject obj = new JSONObject(); + obj.put("test", "success"); + return obj; + } + }; + + new MockUp() { + + @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() { + + @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() { + + @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() { + + @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() { + + @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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfResourceMgrTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfResourceMgrTest.java new file mode 100644 index 00000000..eb5719e1 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfResourceMgrTest.java @@ -0,0 +1,236 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.VnfmRestfulUtil; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.VnfResourceMgr; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @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() { + + @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() { + + @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() { + + @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() { + + @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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/AuthRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/AuthRoaTest.java new file mode 100644 index 00000000..5fc05c4c --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/AuthRoaTest.java @@ -0,0 +1,204 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmJsonUtil; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.AuthMgr; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest.AuthRoa; + +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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + new MockUp() { + + @Mock + public T getJsonFromContexts(HttpServletRequest context) { + return null; + } + }; + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + String result = authRoa.authToken(mockInstance, mockResInstance); + + assertEquals("Login params insufficient", result); + } + + @Test + public void testAuthTokenByFail() { + MockUp proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + new MockUp() { + + @SuppressWarnings("unchecked") + @Mock + public T getJsonFromContexts(HttpServletRequest context) { + JSONObject subJsonObject = new JSONObject(); + return (T)subJsonObject; + } + }; + new MockUp() { + + @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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + new MockUp() { + + @SuppressWarnings("unchecked") + @Mock + public T getJsonFromContexts(HttpServletRequest context) { + JSONObject subJsonObject = new JSONObject(); + return (T)subJsonObject; + } + }; + new MockUp() { + + @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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + new MockUp() { + + @SuppressWarnings("unchecked") + @Mock + public T getJsonFromContexts(HttpServletRequest context) { + JSONObject subJsonObject = new JSONObject(); + return (T)subJsonObject; + } + }; + new MockUp() { + + @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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + 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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + 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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/SwaggerRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/SwaggerRoaTest.java new file mode 100644 index 00000000..a8cd72e0 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/SwaggerRoaTest.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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest; + +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; + +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest.SwaggerRoa; + +/** + *
+ *

+ *

+ * + * @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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfAdapterResourceRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfAdapterResourceRoaTest.java new file mode 100644 index 00000000..6e5f2888 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfAdapterResourceRoaTest.java @@ -0,0 +1,56 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.adapter.impl.AdapterResourceManager; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest.VnfAdapterResourceRoa; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Jan 13, 2017 + */ +public class VnfAdapterResourceRoaTest { + + @Test + public void testGetAllCloudInfo() { + new MockUp() { + + @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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfResourceRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfResourceRoaTest.java new file mode 100644 index 00000000..ca70691b --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfResourceRoaTest.java @@ -0,0 +1,269 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmJsonUtil; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmUtil; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.VnfResourceMgr; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest.VnfResourceRoa; + +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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + new MockUp() { + + @Mock + public 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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + final JSONObject dataObject = new JSONObject(); + new MockUp() { + + @SuppressWarnings("unchecked") + @Mock + public T getJsonFromContexts(HttpServletRequest context) { + return (T)dataObject; + } + }; + new MockUp() { + + @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 proxyStub = new MockUp() { + + @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() { + + @SuppressWarnings("unchecked") + @Mock + public T getJsonFromContexts(HttpServletRequest context) { + return (T)dataObject; + } + }; + new MockUp() { + + @Mock + public String getVnfmIdByIp(String ip) { + return "vnfmId"; + } + }; + + new MockUp() { + + @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 proxyStub = new MockUp() { + + @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() { + + @SuppressWarnings("unchecked") + @Mock + public T getJsonFromContexts(HttpServletRequest context) { + return (T)dataObject; + } + }; + new MockUp() { + + @Mock + public String getVnfmIdByIp(String ip) { + return "vnfmId"; + } + }; + + new MockUp() { + + @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 proxyStub = new MockUp() { + + @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() { + + @SuppressWarnings("unchecked") + @Mock + public T getJsonFromContexts(HttpServletRequest context) { + return (T)dataObject; + } + }; + new MockUp() { + + @Mock + public String getVnfmIdByIp(String ip) { + return "vnfmId"; + } + }; + + new MockUp() { + + @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 proxyStub = new MockUp() { + + @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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java new file mode 100644 index 00000000..411e6adc --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java @@ -0,0 +1,580 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmJsonUtil; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.VnfMgr; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest.VnfRoa; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + new MockUp() { + + @Mock + public JSONObject addVnf(JSONObject subJsonObject, String vnfmId) { + JSONObject retJson = new JSONObject(); + retJson.put("id", "123"); + restJson.put("data", retJson); + return restJson; + } + }; + new MockUp() { + + @SuppressWarnings("unchecked") + @Mock + public 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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + new MockUp() { + + @Mock + public JSONObject addVnf(JSONObject subJsonObject, String vnfmId) { + return restJson; + } + }; + new MockUp() { + + @SuppressWarnings("unchecked") + @Mock + public 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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + new MockUp() { + + @Mock + public 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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + new MockUp() { + + @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() { + + @SuppressWarnings("unchecked") + @Mock + public 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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + new MockUp() { + + @SuppressWarnings("unchecked") + @Mock + public 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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + new MockUp() { + + @SuppressWarnings("unchecked") + @Mock + public 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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + new MockUp() { + + @SuppressWarnings("unchecked") + @Mock + public 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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + new MockUp() { + + @Mock + public JSONObject deleteVnf(String vnfId, String vnfmId, JSONObject vnfObject) { + return restJson; + } + }; + + new MockUp() { + + @SuppressWarnings("unchecked") + @Mock + public 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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + new MockUp() { + + @SuppressWarnings("unchecked") + @Mock + public 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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + new MockUp() { + + @SuppressWarnings("unchecked") + @Mock + public 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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + new MockUp() { + + @Mock + public JSONObject getVnf(String vnfId, String vnfmId) { + return restJson; + } + }; + + new MockUp() { + + @SuppressWarnings("unchecked") + @Mock + public 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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + new MockUp() { + + @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() { + + @SuppressWarnings("unchecked") + @Mock + public 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 proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + String result = vnfRoa.getJob(null, null, mockResInstance, "1111"); + assertEquals("{}", result); + } + + @Test + public void testGetJobByVnfmIdNull() throws ServiceException { + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + String result = vnfRoa.getJob("123", null, mockResInstance, "1111"); + assertEquals("{}", result); + } + + @Test + public void testGetJobByVnfMgrFail() throws ServiceException { + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + new MockUp() { + + @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() { + + @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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + new MockUp() { + + @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() { + + @SuppressWarnings("unchecked") + @Mock + public 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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + new MockUp() { + + @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() { + + @SuppressWarnings("unchecked") + @Mock + public 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 proxyStub = new MockUp() {}; + HttpServletRequest mockInstance = proxyStub.getMockInstance(); + + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + + new MockUp() { + + @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() { + + @SuppressWarnings("unchecked") + @Mock + public 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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/exceptionmapper/ExceptionMessageTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/exceptionmapper/ExceptionMessageTest.java new file mode 100644 index 00000000..8ec144fe --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/exceptionmapper/ExceptionMessageTest.java @@ -0,0 +1,69 @@ +/* + * 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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest.exceptionmapper; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest.exceptionmapper.ExceptionMessage; + +/** + *
+ *

+ *

+ * + * @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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/exceptionmapper/GenericExceptionMapperTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/exceptionmapper/GenericExceptionMapperTest.java new file mode 100644 index 00000000..e0cdc6f8 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/exceptionmapper/GenericExceptionMapperTest.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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest.exceptionmapper; + +import static org.junit.Assert.assertNotNull; + +import javax.ws.rs.core.Response; + +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest.exceptionmapper.GenericExceptionMapper; + +/** + *
+ *

+ *

+ * + * @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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/exceptionmapper/ServiceExceptionMapperTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/exceptionmapper/ServiceExceptionMapperTest.java new file mode 100644 index 00000000..cf4c56e9 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/exceptionmapper/ServiceExceptionMapperTest.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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest.exceptionmapper; + +import static org.junit.Assert.assertNotNull; + +import javax.ws.rs.core.Response; + +import org.junit.Test; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest.exceptionmapper.ServiceExceptionMapper; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +/** + *
+ *

+ *

+ * + * @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/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/testutils/JsonUtil.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/testutils/JsonUtil.java new file mode 100644 index 00000000..2de19983 --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/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.onap.vfc.nfvo.vnfm.svnfm.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 unMarshal(String jsonstr, Class type) throws IOException { + return MAPPER.readValue(jsonstr, type); + } + + public static T unMarshal(String jsonstr, TypeReference 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 -- cgit 1.2.3-korg