fixing major Sonar Issue 79/61279/1
authorThamlurRaju <thamlurraju468@gmail.com>
Mon, 20 Aug 2018 11:37:06 +0000 (17:07 +0530)
committerThamlurRaju <thamlurraju468@gmail.com>
Mon, 20 Aug 2018 11:53:21 +0000 (17:23 +0530)
18 more branches need to cover to reach the minimum 65% Coverage
Sonar Link:
https://sonar.onap.org/project/issues?assignees=ThamlurRaju&id=org.onap.vfc.nfvo.resmanagement%3Avfc-nfvo-resmanagement&open=AV8lpe3K-08if2a6pl_t&resolved=false&severities=MAJOR&types=CODE_SMELL
Location:
src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtil.java

Change-Id: Idb8e1138d92de8206115b51e76bb9c2652634d76
Issue-ID: VFC-1036
Signed-off-by: ThamlurRaju <thamlurraju468@gmail.com>
ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtilTest.java

index e75a823..f9b1fdb 100644 (file)
@@ -19,6 +19,12 @@ package org.onap.vfc.nfvo.resmanagement.common.util;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.HashMap;
+import java.util.Map;
+
 import org.junit.Test;
 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulOptions;
 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulParametes;
@@ -178,4 +184,209 @@ public class RestfulUtilTest {
         }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void getRemoteResponseTest(){
+       Map<String,String> paramMap = new HashMap<>();
+               paramMap.put("url", "https://127.0.0.1:80");
+               paramMap.put("methodType", "get");
+               paramMap.put("tenantId", "tenant_id_123");
+               String params = "This is Params Data";
+               RestfulResponse result = RestfulUtil.getRemoteResponse(paramMap, params);
+               assertEquals(result.getStatus(),200);
+    }
+    
+    @Test(expected=NullPointerException.class)
+    public void getRemoteResponseTestPut(){
+       Map<String,String> paramMap = new HashMap<>();
+               paramMap.put("url", "https://127.0.0.1:80");
+               paramMap.put("methodType", "put");
+               paramMap.put("tenantId", "tenant_id_123");
+               String params = "This is Params Data";
+               RestfulResponse result = RestfulUtil.getRemoteResponse(paramMap, params);
+               assertEquals(result.getStatus(),200);
+    }
+    
+    @Test(expected=NullPointerException.class)
+    public void getRemoteResponseTestPost(){
+       Map<String,String> paramMap = new HashMap<>();
+               paramMap.put("url", "https://127.0.0.1:80");
+               paramMap.put("methodType", "post");
+               paramMap.put("tenantId", "tenant_id_123");
+               String params = "This is Params Data";
+               RestfulResponse result = RestfulUtil.getRemoteResponse(paramMap, params);
+               assertEquals(result.getStatus(),200);
+    }
+    
+    @Test(expected=NullPointerException.class)
+    public void getRemoteResponseTestDel(){
+       Map<String,String> paramMap = new HashMap<>();
+               paramMap.put("url", "https://127.0.0.1:80");
+               paramMap.put("methodType", "delete");
+               paramMap.put("tenantId", "tenant_id_123");
+               String params = "This is Params Data";
+               RestfulResponse result = RestfulUtil.getRemoteResponse(paramMap, params);
+               assertEquals(result.getStatus(),200);
+    }
+    
+    @Test
+    public void testRestfulResponseDel() {
+       
+       RestfulParametes restParametes = new RestfulParametes();
+               Map<String,String> headerMap = new HashMap<>();
+               headerMap.put("Content-type", "Application/json");
+               headerMap.put("X-FromAppId", "Postman");
+               headerMap.put("X-TransactionId", "1234");
+               restParametes.setHeaderMap(headerMap);
+               String data = "This is Raw Data";
+               restParametes.setRawData(data);
+               String url = "https://127.0.0.1:80";
+        RestfulResponse result = RestfulUtil.getRestfulResponse(url, restParametes, "delete");
+        assertEquals(result.getStatus(),-1);
+    }
+    
+    @Test
+    public void testRestfulResponsehttp() {
+       
+       RestfulParametes restParametes = new RestfulParametes();
+               Map<String,String> headerMap = new HashMap<>();
+               headerMap.put("Content-type", "Application/json");
+               headerMap.put("X-FromAppId", "Postman");
+               headerMap.put("X-TransactionId", "1234");
+               restParametes.setHeaderMap(headerMap);
+               Map<String,String> paramMap = new HashMap<>();
+               paramMap.put("type", "Application");
+               paramMap.put("vimId", "vim_id_123");
+               paramMap.put("tenantId", "tenant_id_123");
+               restParametes.setParamMap(paramMap);
+               String data = "This is Raw Data";
+               restParametes.setRawData(data);
+               String url = "http://127.0.0.1:80";
+        RestfulResponse result = RestfulUtil.getRestfulResponse(url, restParametes, "delete");
+        assertEquals(result.getStatus(),-1);
+    }
+    
+    @Test
+    public void testRestfulResponsenull() {
+       
+       RestfulParametes restParametes = new RestfulParametes();
+               Map<String,String> headerMap = new HashMap<>();
+               headerMap.put("Content-type", "Application/json");
+               headerMap.put("X-FromAppId", "Postman");
+               headerMap.put("X-TransactionId", "1234");
+               restParametes.setHeaderMap(headerMap);
+               Map<String,String> paramMap = new HashMap<>();
+               paramMap.put("type", "Application");
+               paramMap.put("vimId", "vim_id_123");
+               paramMap.put("tenantId", "tenant_id_123");
+               restParametes.setParamMap(paramMap);
+               String data = "This is Raw Data";
+               restParametes.setRawData(data);
+               String url = "ftp://127.0.0.1:80";
+        RestfulResponse result = RestfulUtil.getRestfulResponse(url, restParametes, "delete");
+        assertEquals(result.getStatus(),-1);
+    }
+    
+  
+    @Test
+    public void testRestfulResponseGet() {
+       
+       RestfulParametes restParametes = new RestfulParametes();
+               Map<String,String> headerMap = new HashMap<>();
+               headerMap.put("Content-type", "Application/json");
+               headerMap.put("X-FromAppId", "Postman");
+               headerMap.put("X-TransactionId", "1234");
+               restParametes.setHeaderMap(headerMap);
+               Map<String,String> paramMap = new HashMap<>();
+               paramMap.put("type", "Application");
+               paramMap.put("vimId", "vim_id_123");
+               paramMap.put("tenantId", "tenant_id_123");
+               restParametes.setParamMap(paramMap);
+               String data = "This is Raw Data";
+               restParametes.setRawData(data);
+               String url = "https://127.0.0.1:80";
+        RestfulResponse result = RestfulUtil.getRestfulResponse(url, restParametes, "get");
+        assertEquals(result.getStatus(),-1);
+    }
+    
+    @Test(expected=NullPointerException.class)
+    public void testRestfulResponsePost() {
+       
+       RestfulParametes restParametes = new RestfulParametes();
+               Map<String,String> headerMap = new HashMap<>();
+               headerMap.put("Content-type", "Application/json");
+               headerMap.put("X-FromAppId", "Postman");
+               headerMap.put("X-TransactionId", "1234");
+               restParametes.setHeaderMap(headerMap);
+               Map<String,String> paramMap = new HashMap<>();
+               paramMap.put("type", "Application");
+               paramMap.put("vimId", "vim_id_123");
+               paramMap.put("tenantId", "tenant_id_123");
+               restParametes.setParamMap(paramMap);
+               String data = "This is Raw Data";
+               restParametes.setRawData(data);
+               String url = "https://127.0.0.1:80";
+        RestfulResponse result = RestfulUtil.getRestfulResponse(url, restParametes, "post");
+        assertEquals(result.getStatus(),-1);
+    }
+    
+    @Test
+    public void testRestfulResponsePut() {
+       
+       RestfulParametes restParametes = new RestfulParametes();
+               Map<String,String> headerMap = new HashMap<>();
+               headerMap.put("Content-type", "Application/json");
+               headerMap.put("X-FromAppId", "Postman");
+               headerMap.put("X-TransactionId", "1234");
+               restParametes.setHeaderMap(headerMap);
+               Map<String,String> paramMap = new HashMap<>();
+               paramMap.put("type", "Application");
+               paramMap.put("vimId", "vim_id_123");
+               paramMap.put("tenantId", "tenant_id_123");
+               restParametes.setParamMap(paramMap);
+               String data = "This is Raw Data";
+               restParametes.setRawData(data);
+               String url = "https://127.0.0.1:80";
+        RestfulResponse result = RestfulUtil.getRestfulResponse(url, restParametes, "put");
+        assertEquals(result.getStatus(),-1);
+    }
+    
+    @Test
+    public void testGetResponseContent() {
+       
+       RestfulParametes restParametes = new RestfulParametes();
+               Map<String,String> headerMap = new HashMap<>();
+               headerMap.put("Content-type", "Application/json");
+               headerMap.put("X-FromAppId", "Postman");
+               headerMap.put("X-TransactionId", "1234");
+               restParametes.setHeaderMap(headerMap);
+               Map<String,String> paramMap = new HashMap<>();
+               paramMap.put("type", "Application");
+               paramMap.put("vimId", "vim_id_123");
+               paramMap.put("tenantId", "tenant_id_123");
+               restParametes.setParamMap(paramMap);
+               String data = "This is Raw Data";
+               restParametes.setRawData(data);
+               String url = "https://127.0.0.1:80";
+       RestfulUtil.getResponseContent(url, restParametes, "GET");
+    }
+    
+    @Test
+    public void getResponseContentMapTest() {
+       String url = "https://127.0.0.1:80";
+       RestfulUtil.getResponseContentMap(url, "GET");
+    }
+    
+    @Test
+    public void testGetResponseObjWithNull() {
+        new MockUp<RestfulUtil>() {
+
+            @Mock
+            public String getResponseContent(String url, RestfulParametes restParametes, RestfulOptions opt,
+                    String type) {
+                return null;
+            }
+        };
+      RestfulUtil.getResponseObj(null, null, null);
+    }
+    
 }