diff options
author | luxin <luxin7@huawei.com> | 2018-02-26 11:27:47 +0800 |
---|---|---|
committer | luxin <luxin7@huawei.com> | 2018-02-26 11:27:47 +0800 |
commit | a4996ef65017d8e296d040fe50aa05d417509e63 (patch) | |
tree | e776c1a6be9cfc79f059458d013a392e0aa1e017 | |
parent | 46d52ae5507a47ad0178fc1ee29e8c3d43b8a450 (diff) |
Add UT test
Change-Id: I5dfe4227d920fc9078263fed9aeb30e1965e1bbd
Issue-ID: VFC-747
Signed-off-by: luxin <luxin7@huawei.com>
2 files changed, 93 insertions, 7 deletions
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java index 0dc6751b..3e93f2c2 100644 --- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java @@ -16,10 +16,9 @@ package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; 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; @@ -29,14 +28,15 @@ import net.sf.json.JSONObject; public class ResultRequestUtilTest { @Test - public void callTestInternalError(){ - new MockUp<ConnectMgrVnfm>(){ + public void callTestInternalError() { + new MockUp<ConnectMgrVnfm>() { + @Mock public int connect(JSONObject vnfmObj) { return 500; } }; - JSONObject vnfmObject = new JSONObject();; + JSONObject vnfmObject = new JSONObject(); String path = "http://localhost:8080"; String methodName = "get"; String paramsJson = ""; @@ -45,8 +45,9 @@ public class ResultRequestUtilTest { } @Test - public void callTestConnectionErrot(){ - new MockUp<ConnectMgrVnfm>(){ + public void callTestConnectionErrot() { + new MockUp<ConnectMgrVnfm>() { + @Mock public int connect(JSONObject vnfmObj) { return 200; @@ -61,4 +62,34 @@ public class ResultRequestUtilTest { assertTrue(resp.get("data").equals("get connection error")); } + @Test + public void callTest() { + new MockUp<ConnectMgrVnfm>() { + + @Mock + public int connect(JSONObject vnfmObj) { + return 200; + } + + @Mock + public String getRoaRand() { + return "1234"; + } + + @Mock + public String getAccessSession() { + return "1234"; + } + + }; + + JSONObject vnfmObject = new JSONObject(); + vnfmObject.put("url", "/test/123"); + String path = "https://localhost:8080/%s"; + 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/service/rest/VnfRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java index b82c26af..8012b5cb 100644 --- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java @@ -26,6 +26,7 @@ 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.common.restclient.ServiceException; import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant; import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.VnfMgr; @@ -577,4 +578,58 @@ public class VnfRoaTest { } + @Test + public void testGetVnfmById() throws ServiceException { + new MockUp<VnfmUtil>() { + + @Mock + public JSONObject getVnfmById(String vnfmId) { + JSONObject json = new JSONObject(); + json.put("vnfm", "1234"); + return json; + } + }; + String result = vnfRoa.getVnfmById("1234", null); + assertNotNull(result); + } + + @Test + public void testGetJobFromVnfm() throws ServiceException { + new MockUp<VnfMgr>() { + + @Mock + public JSONObject getJobFromVnfm(String jobId, String vnfmId) { + JSONObject json = new JSONObject(); + json.put("retCode", "1"); + return json; + } + + @Mock + public String transferToLcm(JSONObject restJson) { + return "success"; + } + }; + String result = vnfRoa.getJobFromVnfm("jobId", "vnfmId", null, "responseId"); + assertNotNull(result); + } + + @Test + public void testGetJobFromVnfmFail() throws ServiceException { + + new MockUp<VnfMgr>() { + + @Mock + public JSONObject getJobFromVnfm(String jobId, String vnfmId) { + JSONObject json = new JSONObject(); + json.put("retCode", "-1"); + return json; + } + + }; + MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + String result = vnfRoa.getJobFromVnfm("jobId", "vnfmId", mockResInstance, "responseId"); + assertNotNull(result); + } + } |