From fc8de6b2b8cb9d7986f6f949b57569591a298549 Mon Sep 17 00:00:00 2001 From: luxin Date: Thu, 29 Mar 2018 11:09:47 +0800 Subject: Fix nexus-iq issue Change-Id: I618eb41d6cb551450f0339edc883e6338b16add2 Issue-ID: VFC-833 Signed-off-by: luxin --- .../Juju-vnfmadapterService/service/pom.xml | 31 +++- .../jujuvnfmadapter/service/rest/ConfigRoa.java | 165 ++++++++++----------- .../service/rest/ConfigRoaTest.java | 55 ++++--- 3 files changed, 124 insertions(+), 127 deletions(-) (limited to 'juju/juju-vnfmadapter/Juju-vnfmadapterService') diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/pom.xml b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/pom.xml index 8b7757c..6dc7b69 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/pom.xml +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/pom.xml @@ -214,24 +214,41 @@ 2.2.2 + - org.jmockit - jmockit - 1.19 - jar + org.powermock + powermock-core + 1.5.4 + + + org.powermock + powermock-api-mockito + 1.5.4 + + + org.powermock + powermock-module-junit4 + 1.5.4 org.jmockit - jmockit-coverage + jmockit 1.19 - jar + test junit junit - 4.11 + 4.12 + + + org.jmockit + jmockit-coverage + 1.19 test + + cglib cglib-nodep diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/ConfigRoa.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/ConfigRoa.java index 613f5cc..1e6bf03 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/ConfigRoa.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/ConfigRoa.java @@ -16,9 +16,11 @@ package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.rest; -import java.io.File; -import java.io.IOException; -import java.util.List; +import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.EntityUtils; +import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.SwitchController; +import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -30,26 +32,6 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.EntityUtils; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.FileUtils; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.JujuConfigUtil; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.SwitchController; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.VnfmUtil; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.EntityUtils.ExeRes; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.servicetoken.JujuVnfmRestfulUtil; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.servicetoken.VnfmRestfulUtil; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.adapter.impl.AdapterResourceManager; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.constant.Constant; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.constant.UrlConstant; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient.ServiceException; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient.RestfulResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - /** *
*

@@ -112,52 +94,53 @@ public class ConfigRoa { * @throws ServiceException * @since NFVO 0.5 */ - @GET - @Path("/mock/{methodName}") - public boolean mock(@PathParam("methodName") String methodName, @Context HttpServletRequest context, - @Context HttpServletResponse resp) throws ServiceException { - if("getVnfmById".equals(methodName)) { - new MockUp() { - - @Mock - public JSONObject getVnfmById(String vnfmId) { - JSONObject json = new JSONObject(); - json.put("vnfmId", vnfmId); - json.put("vnfdId", "testVnfdId"); - json.put("vnfPackageId", "testPackageId"); - json.put("version", "1"); - json.put("url", JujuConfigUtil.getValue("jujuvnfm_server_url")); - return json; - } - }; - } else if("execute".equals(methodName)) { - new MockUp() { - - @Mock - public ExeRes execute(String dir, List command) { - ExeRes er = new ExeRes(); - String resContent = null; - try { - resContent = new String( - FileUtils.readFile(new File(JujuConfigUtil.getValue("juju_cmd_res_file")), "UTF-8")); - } catch(Exception e) { - LOG.error("mock fail",e); - resContent = "mock fail"; - } - er.setBody(resContent); - return er; - } - }; - }else if("fetchDownloadUrlFromCatalog".equals(methodName)) { - new MockUp() { - @Mock - public String fetchDownloadUrlFromCatalog(String csarId){ - return JujuConfigUtil.getValue("catalog_download_url"); - } - }; - } - return true; - } + /* + * @GET + * @Path("/mock/{methodName}") + * public boolean mock(@PathParam("methodName") String methodName, @Context HttpServletRequest + * context, + * @Context HttpServletResponse resp) throws ServiceException { + * if("getVnfmById".equals(methodName)) { + * new MockUp() { + * @Mock + * public JSONObject getVnfmById(String vnfmId) { + * JSONObject json = new JSONObject(); + * json.put("vnfmId", vnfmId); + * json.put("vnfdId", "testVnfdId"); + * json.put("vnfPackageId", "testPackageId"); + * json.put("version", "1"); + * json.put("url", JujuConfigUtil.getValue("jujuvnfm_server_url")); + * return json; + * } + * }; + * } else if("execute".equals(methodName)) { + * new MockUp() { + * @Mock + * public ExeRes execute(String dir, List command) { + * ExeRes er = new ExeRes(); + * String resContent = null; + * try { + * resContent = new String( + * FileUtils.readFile(new File(JujuConfigUtil.getValue("juju_cmd_res_file")), "UTF-8")); + * } catch(Exception e) { + * LOG.error("mock fail", e); + * resContent = "mock fail"; + * } + * er.setBody(resContent); + * return er; + * } + * }; + * } else if("fetchDownloadUrlFromCatalog".equals(methodName)) { + * new MockUp() { + * @Mock + * public String fetchDownloadUrlFromCatalog(String csarId) { + * return JujuConfigUtil.getValue("catalog_download_url"); + * } + * }; + * } + * return true; + * } + */ /** *
@@ -169,25 +152,27 @@ public class ConfigRoa { * @throws ServiceException * @since NFVO 0.5 */ - @GET - @Path("/unmock/{methodName}") - public boolean unmock(@PathParam("methodName") String methodName, @Context HttpServletRequest context, - @Context HttpServletResponse resp) throws ServiceException { - if("getVnfmById".equals(methodName)) { - new MockUp() { - - @Mock - public JSONObject getVnfmById(String vnfmId) { - RestfulResponse rsp = VnfmRestfulUtil.getRemoteResponse( - String.format(UrlConstant.REST_ESRINFO_GET, vnfmId), JujuVnfmRestfulUtil.GET_TYPE, null); - if(rsp == null || rsp.getStatus() != Constant.HTTP_OK) { - return null; - } - LOG.error("funtion=getVnfmById, status={}", rsp.getStatus()); - return JSONObject.fromObject(rsp.getResponseContent()); - } - }; - } - return true; - } + /* + * @GET + * @Path("/unmock/{methodName}") + * public boolean unmock(@PathParam("methodName") String methodName, @Context HttpServletRequest + * context, + * @Context HttpServletResponse resp) throws ServiceException { + * if("getVnfmById".equals(methodName)) { + * new MockUp() { + * @Mock + * public JSONObject getVnfmById(String vnfmId) { + * RestfulResponse rsp = VnfmRestfulUtil.getRemoteResponse( + * String.format(UrlConstant.REST_ESRINFO_GET, vnfmId), JujuVnfmRestfulUtil.GET_TYPE, null); + * if(rsp == null || rsp.getStatus() != Constant.HTTP_OK) { + * return null; + * } + * LOG.error("funtion=getVnfmById, status={}", rsp.getStatus()); + * return JSONObject.fromObject(rsp.getResponseContent()); + * } + * }; + * } + * return true; + * } + */ } diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/ConfigRoaTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/ConfigRoaTest.java index 7531224..480f837 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/ConfigRoaTest.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/ConfigRoaTest.java @@ -13,27 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.rest; - -import static org.junit.Assert.*; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.rest; import org.junit.Before; import org.junit.Test; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.JujuConfigUtil; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.servicetoken.VnfmRestfulUtil; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.rest.ConfigRoa; import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient.ServiceException; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient.RestfulResponse; import org.springframework.mock.web.MockHttpServletResponse; -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class ConfigRoaTest { + ConfigRoa roa; @Before @@ -65,22 +61,21 @@ public class ConfigRoaTest { assertFalse(res); } - @Test - public void testmock() throws ServiceException { - HttpServletRequest context = null; - HttpServletResponse resp = new MockHttpServletResponse(); - String methodName = "getVnfmById"; - JSONObject json = new JSONObject(); - - new MockUp() { - @Mock - public String getValue(String key) { - return null; - } - - }; - roa.mock(methodName, context, resp); - roa.unmock(methodName, context, resp); - - } + /* + * @Test + * public void testmock() throws ServiceException { + * HttpServletRequest context = null; + * HttpServletResponse resp = new MockHttpServletResponse(); + * String methodName = "getVnfmById"; + * JSONObject json = new JSONObject(); + * new MockUp() { + * @Mock + * public String getValue(String key) { + * return null; + * } + * }; + * roa.mock(methodName, context, resp); + * roa.unmock(methodName, context, resp); + * } + */ } -- cgit 1.2.3-korg