From a4996ef65017d8e296d040fe50aa05d417509e63 Mon Sep 17 00:00:00 2001 From: luxin Date: Mon, 26 Feb 2018 11:27:47 +0800 Subject: Add UT test Change-Id: I5dfe4227d920fc9078263fed9aeb30e1965e1bbd Issue-ID: VFC-747 Signed-off-by: luxin --- .../vnfmadapter/common/ResultRequestUtilTest.java | 45 +++++++++++++++--- .../svnfm/vnfmadapter/service/rest/VnfRoaTest.java | 55 ++++++++++++++++++++++ 2 files changed, 93 insertions(+), 7 deletions(-) (limited to 'huawei/vnfmadapter') 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(){ + public void callTestInternalError() { + new MockUp() { + @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(){ + public void callTestConnectionErrot() { + new MockUp() { + @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() { + + @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() { + + @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() { + + @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() { + + @Mock + public JSONObject getJobFromVnfm(String jobId, String vnfmId) { + JSONObject json = new JSONObject(); + json.put("retCode", "-1"); + return json; + } + + }; + MockUp proxyResStub = new MockUp() {}; + HttpServletResponse mockResInstance = proxyResStub.getMockInstance(); + String result = vnfRoa.getJobFromVnfm("jobId", "vnfmId", mockResInstance, "responseId"); + assertNotNull(result); + } + } -- cgit 1.2.3-korg