Fix nexus-iq issue 49/39949/1
authorluxin <luxin7@huawei.com>
Thu, 29 Mar 2018 03:09:47 +0000 (11:09 +0800)
committerluxin <luxin7@huawei.com>
Thu, 29 Mar 2018 03:11:09 +0000 (11:11 +0800)
Change-Id: I618eb41d6cb551450f0339edc883e6338b16add2
Issue-ID: VFC-833
Signed-off-by: luxin <luxin7@huawei.com>
juju/juju-vnfmadapter/Juju-vnfmadapterService/service/pom.xml
juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/ConfigRoa.java
juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/ConfigRoaTest.java

index 8b7757c..6dc7b69 100644 (file)
             <version>2.2.2</version>
         </dependency>
         <!--authorization.filter -->
+        <!-- UT coverage dependency start -->
         <dependency>
-            <groupId>org.jmockit</groupId>
-            <artifactId>jmockit</artifactId>
-            <version>1.19</version>
-            <type>jar</type>
+            <groupId>org.powermock</groupId>
+            <artifactId>powermock-core</artifactId>
+            <version>1.5.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.powermock</groupId>
+            <artifactId>powermock-api-mockito</artifactId>
+            <version>1.5.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.powermock</groupId>
+            <artifactId>powermock-module-junit4</artifactId>
+            <version>1.5.4</version>
         </dependency>
         <dependency>
             <groupId>org.jmockit</groupId>
-            <artifactId>jmockit-coverage</artifactId>
+            <artifactId>jmockit</artifactId>
             <version>1.19</version>
-            <type>jar</type>
+            <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
-            <version>4.11</version>
+            <version>4.12</version>
+        </dependency>
+        <dependency>
+            <groupId>org.jmockit</groupId>
+            <artifactId>jmockit-coverage</artifactId>
+            <version>1.19</version>
             <scope>test</scope>
         </dependency>
+
+        <!-- UT coverage dependency end -->
         <dependency>
             <groupId>cglib</groupId>
             <artifactId>cglib-nodep</artifactId>
index 613f5cc..1e6bf03 100644 (file)
 
 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;
-
 /**
  * <br/>
  * <p>
@@ -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<VnfmUtil>() {
-
-                @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<EntityUtils>() {
-
-                @Mock
-                public ExeRes execute(String dir, List<String> 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<AdapterResourceManager>() {
-                @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<VnfmUtil>() {
+     * @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<EntityUtils>() {
+     * @Mock
+     * public ExeRes execute(String dir, List<String> 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<AdapterResourceManager>() {
+     * @Mock
+     * public String fetchDownloadUrlFromCatalog(String csarId) {
+     * return JujuConfigUtil.getValue("catalog_download_url");
+     * }
+     * };
+     * }
+     * return true;
+     * }
+     */
 
     /**
      * <br/>
@@ -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<VnfmUtil>() {
-
-                @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<VnfmUtil>() {
+     * @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;
+     * }
+     */
 }
index 7531224..480f837 100644 (file)
  * 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<JujuConfigUtil>() {
-            @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<JujuConfigUtil>() {
+     * @Mock
+     * public String getValue(String key) {
+     * return null;
+     * }
+     * };
+     * roa.mock(methodName, context, resp);
+     * roa.unmock(methodName, context, resp);
+     * }
+     */
 }