Junit coverage increased 53/111553/1
authorarun chapagain <arun.chapagain@huawei.com>
Fri, 21 Aug 2020 14:52:00 +0000 (20:22 +0530)
committerarun chapagain <arun.chapagain@huawei.com>
Fri, 21 Aug 2020 14:52:00 +0000 (20:22 +0530)
Issue-ID: VFC-1726

Signed-off-by: arun chapagain <arun.chapagain@huawei.com>
Change-Id: Ia0e3c2ea3ae429e286e9151f2e6de9e3f639c868

huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java
huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmUtilTest.java
huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java

index 3e93f2c..8792f52 100644 (file)
 
 package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common;
 
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
+import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.connect.ConnectMgrVnfm;
 
 import mockit.Mock;
@@ -36,10 +38,15 @@ public class ResultRequestUtilTest {
                 return 500;
             }
         };
+       
+       
         JSONObject vnfmObject = new JSONObject();
         String path = "http://localhost:8080";
         String methodName = "get";
         String paramsJson = "";
+        vnfmObject.put("url", path);
+        vnfmObject.put(Constant.USERNAME, Constant.USERNAME);
+        vnfmObject.put(Constant.PASSWORD, Constant.PASSWORD);
         JSONObject resp = ResultRequestUtil.call(vnfmObject, path, methodName, paramsJson);
         assertTrue(resp.get("data").equals("connect fail."));
     }
@@ -91,5 +98,33 @@ public class ResultRequestUtilTest {
         JSONObject resp = ResultRequestUtil.call(vnfmObject, path, methodName, paramsJson);
         assertTrue(resp.get("data").equals("get connection error"));
     }
+    
+    
+    @Test
+    public void call() {
+    
+       JSONObject vnfmObject = new JSONObject();
+       vnfmObject.put("url","https://localhost:8080/%s" );
+       vnfmObject.put(Constant.USERNAME, Constant.USERNAME);
+       vnfmObject.put(Constant.PASSWORD, Constant.PASSWORD);
+        String path = "https://localhost:8080/%s";
+        String methodName = "get";
+        String paramsJson = "";
+         assertNotNull(ResultRequestUtil.call( vnfmObject, path,  methodName,  paramsJson,
+            "authModel"));
+       
+    }
+    
+       @Test
+       public void callSouth() {
+               JSONObject vnfmObject = new JSONObject();
+               vnfmObject.put("url", "https://localhost:8080/%s");
+               vnfmObject.put(Constant.USERNAME, Constant.USERNAME);
+               vnfmObject.put(Constant.PASSWORD, Constant.PASSWORD);
+               String path = "https://localhost:8080/%s";
+               String methodName = "get";
+               String paramsJson = "";
+               assertNotNull(ResultRequestUtil.callSouth(vnfmObject, path, methodName, paramsJson, "authModel"));
+       }
 
 }
index e95e957..3cd28d7 100644 (file)
@@ -38,14 +38,14 @@ public class VnfmUtilTest {
 
     @Test
     public void getVnfmByIdTestSuccess(){
-        new MockUp<VnfmRestfulUtil>(){
-            @Mock
-            public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
-                RestfulResponse resp = new RestfulResponse();
-                resp.setStatus(200);
-                return resp;
-            }
-        };
+//        new MockUp<VnfmRestfulUtil>(){
+//            @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);
     }
@@ -58,55 +58,56 @@ public class VnfmUtilTest {
 
     @Test
     public void getVnfmIdByIpTestSuccess(){
-        new MockUp<VnfmRestfulUtil>(){
-            @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;
-            }
-        };
+//        new MockUp<VnfmRestfulUtil>(){
+//            @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<VnfmRestfulUtil>(){
-            @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;
-            }
-        };
+//        new MockUp<VnfmRestfulUtil>(){
+//            @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<VnfmRestfulUtil>(){
-            @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;
-            }
-        };
+//        new MockUp<VnfmRestfulUtil>(){
+//            @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;
+//            }
+//        };
+       VnfmUtil.mockForTest("Vfnid");
         String resp = VnfmUtil.getVnfmIdByIp("localhost");
         assertTrue("".equals(resp));
     }
index fec9844..60b5f63 100644 (file)
@@ -53,51 +53,51 @@ public class VnfmRestfulUtilTest {
 
     @Test
     public void testSendReqToApp() {
-        new MockUp<VnfmRestfulUtil>() {
-
-            @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;
-            }
-        };
+//        new MockUp<VnfmRestfulUtil>() {
+//
+//            @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<VnfmRestfulUtil>() {
-
-            @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;
-            }
-        };
+//        new MockUp<VnfmRestfulUtil>() {
+//
+//            @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<VnfmRestfulUtil>() {
-
-            @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;
-            }
-        };
+//        new MockUp<VnfmRestfulUtil>() {
+//
+//            @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"));
     }
@@ -238,4 +238,17 @@ public class VnfmRestfulUtilTest {
         RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse("/test/123", "", "test123");
         assertNull(resp);
     }
+    
+    @Test
+    public void getRemoteResponse() {
+       Map <String, String > headerMap = new HashMap<String, String>();
+       
+       VnfmRestfulUtil.getRemoteResponse( "url",  "get",  headerMap,"params");
+       VnfmRestfulUtil.getRemoteResponse( "url",  "post",  headerMap,"params");
+       VnfmRestfulUtil.getRemoteResponse( "url",  "put",  headerMap,"params");
+       assertNull(VnfmRestfulUtil.getRemoteResponse( "url",  "delete",  headerMap,"params"));
+
+
+
+    }
 }