Improve coverage of SitesImpl 55/67255/2
authorThamlurRaju <thamlurraju468@gmail.com>
Tue, 18 Sep 2018 10:30:07 +0000 (16:00 +0530)
committerThamlur Raju <thamlurraju468@gmail.com>
Wed, 19 Sep 2018 06:08:15 +0000 (06:08 +0000)
7 breaches need to cover to reach 65% Coverage
Sonar Link:
https://sonar.onap.org/project/issues?assignees=ThamlurRaju&id=org.onap.vfc.nfvo.resmanagement%3Avfc-nfvo-resmanagement&open=AV8lpe6i-08if2a6pmA7&resolved=false&severities=MAJOR&types=CODE_SMELL
Location:
src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/SitesImpl.java

Change-Id: Ief517154f1c5dc20b746e1f01793a25878bae971
Issue-ID: VFC-1081
Signed-off-by: ThamlurRaju <thamlurraju468@gmail.com>
ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/SitesImplTest.java

index ee63537..48075d3 100644 (file)
@@ -25,8 +25,10 @@ import java.util.Map;
 
 import org.junit.Test;
 import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.SitesImpl;
+import org.onap.vfc.nfvo.resmanagement.service.business.impl.LimitsBusinessImpl;
 import org.onap.vfc.nfvo.resmanagement.service.business.impl.SitesBusinessImpl;
 import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity;
+import org.onap.vfc.nfvo.resmanagement.common.VimUtil;
 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
 
 import mockit.Mock;
@@ -35,24 +37,21 @@ import net.sf.json.JSONObject;
 
 public class SitesImplTest {
 
-
-
         @Test
         public void testUpdate1() throws ServiceException {
-            SitesImpl sitesImpl = new SitesImpl();
-            sitesImpl.setSitesBusiness(new SitesBusinessImpl());
-            SitesEntity sitesEntity = new SitesEntity();
-            sitesEntity.setId("123");
-            new MockUp<SitesBusinessImpl>() {
-
-                @Mock
-                public int updateSiteSelective(SitesEntity sitesEntity) throws ServiceException {
-                    return 1;
-                }
-            };
-            int result = sitesImpl.update(sitesEntity);
-            int exceptedResult = 1;
-            assertEquals(exceptedResult, result);
+          SitesImpl sitesImpl = new SitesImpl();
+          sitesImpl.setSitesBusiness(new SitesBusinessImpl());
+          SitesEntity sitesEntity = new SitesEntity();
+          sitesEntity.setId("123");
+          new MockUp<SitesBusinessImpl>() {
+            @Mock
+              public int updateSiteSelective(SitesEntity sitesEntity) throws ServiceException {
+              return 1;
+            }
+          };
+          int result = sitesImpl.update(sitesEntity);
+          int exceptedResult = 1;
+          assertEquals(exceptedResult, result);
         }
 
     @Test
@@ -146,4 +145,176 @@ public class SitesImplTest {
         SitesEntity result = sitesImpl.get(condition);
     }
 
+    SitesImpl sitesImpl = new SitesImpl();
+    @Test
+    public void testGetWithData() throws ServiceException {
+        Map<String, Object> condition = new HashMap<>();
+        sitesImpl.setSitesBusiness(new SitesBusinessImpl());
+        new MockUp<SitesBusinessImpl>() {
+
+            @Mock
+            public List<SitesEntity> getSites(Map<String, Object> condition) {
+                List<SitesEntity> list = new ArrayList<SitesEntity>();
+                SitesEntity se = new SitesEntity();
+                se.setId("id_123");
+                se.setName("name_123");
+                list.add(se);
+                return list;
+            }
+        };
+        SitesEntity sitesEntity = new SitesEntity();
+        sitesEntity.setId("id_123");
+        sitesImpl.deleteResByVimId("vimId");
+        SitesEntity result = sitesImpl.get(condition);
+        SitesEntity exceptedResult = new SitesEntity();
+        exceptedResult.setId("id_123");
+        assertEquals(exceptedResult.getId(), result.getId());
+    }
+
+    @Test(expected=ServiceException.class)
+    public void testUpdate() throws ServiceException{
+        this.testGetWithData();
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("id", "id_123");
+        jsonObject.put("name", "name_123");
+        jsonObject.put("location", "location_123");
+        jsonObject.put("country", "country_123");
+        jsonObject.put("vimId", "vimId_123");
+        jsonObject.put("vimName", "vimName_123");
+        jsonObject.put("status", "success");
+        jsonObject.put("totalCPU", "05");
+        jsonObject.put("totalMemory", "100");
+        jsonObject.put("totalDisk", "03");
+        jsonObject.put("usedCPU", "0");
+        jsonObject.put("usedMemory", "13");
+        jsonObject.put("usedDisk", "01");
+        jsonObject.put("action", "Started");
+        sitesImpl.update(jsonObject);
+    }
+
+    @Test(expected=NullPointerException.class)
+    public void testUpdateSiteNull() throws ServiceException{
+      this.testGet();
+      JSONObject jsonObject = new JSONObject();
+      jsonObject.put("id", "id_123");
+      jsonObject.put("name", "name_123");
+      jsonObject.put("location", "location_123");
+      jsonObject.put("country", "country_123");
+      jsonObject.put("vimId", "vimId_123");
+      jsonObject.put("vimName", "vimName_123");
+      jsonObject.put("status", "success");
+      jsonObject.put("totalCPU", "05");
+      jsonObject.put("totalMemory", "1000");
+      jsonObject.put("totalDisk", "03");
+      jsonObject.put("usedCPU", "0");
+      jsonObject.put("usedMemory", "13");
+      jsonObject.put("usedDisk", "01");
+      jsonObject.put("action", "Started");
+      sitesImpl.update(jsonObject);
+    }
+
+    @Test(expected=ServiceException.class)
+    public void testUpdateAction() throws ServiceException{
+      this.testGetWithData();
+      JSONObject jsonObject = new JSONObject();
+      jsonObject.put("id", "id_123");
+      jsonObject.put("name", "name_123");
+      jsonObject.put("location", "location_123");
+      jsonObject.put("country", "country_123");
+      jsonObject.put("vimId", "vimId_123");
+      jsonObject.put("vimName", "vimName_123");
+      jsonObject.put("status", "success");
+      jsonObject.put("totalCPU", "05");
+      jsonObject.put("totalMemory", "100");
+      jsonObject.put("totalDisk", "03");
+      jsonObject.put("usedCPU", "0");
+      jsonObject.put("usedMemory", "13");
+      jsonObject.put("usedDisk", "01");
+      jsonObject.put("action", "online");
+      sitesImpl.update(jsonObject);
+    }
+
+    @Test(expected=NullPointerException.class)
+    public void testUpdateActionMemory() throws ServiceException{
+      this.testGetWithData();
+      JSONObject jsonObject = new JSONObject();
+      jsonObject.put("id", "id_123");
+      jsonObject.put("name", "name_123");
+      jsonObject.put("location", "location_123");
+      jsonObject.put("country", "country_123");
+      jsonObject.put("vimId", "vimId_123");
+      jsonObject.put("vimName", "vimName_123");
+      jsonObject.put("status", "success");
+      jsonObject.put("totalCPU", "05");
+      jsonObject.put("totalMemory", "1000");
+      jsonObject.put("totalDisk", "03");
+      jsonObject.put("usedCPU", "0");
+      jsonObject.put("usedMemory", "0");
+      jsonObject.put("usedDisk", "0");
+      jsonObject.put("action", "online");
+      sitesImpl.update(jsonObject);
+    }
+
+    @Test(expected=NullPointerException.class)
+    public void testUpdateMemory() throws ServiceException{
+      this.testGetWithData();
+      JSONObject jsonObject = new JSONObject();
+      jsonObject.put("id", "id_123");
+      jsonObject.put("name", "name_123");
+      jsonObject.put("location", "location_123");
+      jsonObject.put("country", "country_123");
+      jsonObject.put("vimId", "vimId_123");
+      jsonObject.put("vimName", "vimName_123");
+      jsonObject.put("status", "success");
+      jsonObject.put("totalCPU", "05");
+      jsonObject.put("totalMemory", "1000");
+      jsonObject.put("totalDisk", "03");
+      jsonObject.put("usedCPU", "0");
+      jsonObject.put("usedMemory", "0");
+      jsonObject.put("usedDisk", "0");
+      jsonObject.put("action", "Started");
+      sitesImpl.update(jsonObject);
+    }
+
+    @Test(expected=NullPointerException.class)
+    public void testAdd() throws ServiceException{
+      new MockUp<VimUtil>(){
+        @Mock
+          public String getVimIdByName(String name) {
+          return "Vim_Id_123";
+        }
+      };
+      new MockUp<LimitsBusinessImpl>(){
+        @Mock
+          public JSONObject getLimits(String vimId) throws ServiceException {
+          JSONObject json = new JSONObject();
+          json.put("vimId", "vim_id_123");
+          json.put("vimName", "vim_name_123");
+          json.put("totalCPU", "12");
+          json.put("totalMemory", "13");
+          json.put("totalDisk", "05");
+          json.put("usedCPU", "0");
+          json.put("usedMemory", "0");
+          json.put("usedDisk", "0");
+          return json;
+        }
+      };
+    this.testGetWithData();
+    JSONObject jsonObject = new JSONObject();
+    jsonObject.put("id", "id_123");
+    jsonObject.put("name", "name_123");
+    jsonObject.put("location", "location_123");
+    jsonObject.put("country", "country_123");
+    jsonObject.put("vimId", "vimId_123");
+    jsonObject.put("vimName", "vimName_123");
+    jsonObject.put("status", "success");
+    jsonObject.put("totalCPU", "05");
+    jsonObject.put("totalMemory", "1000");
+    jsonObject.put("totalDisk", "03");
+    jsonObject.put("usedCPU", "0");
+    jsonObject.put("usedMemory", "0");
+    jsonObject.put("usedDisk", "0");
+    jsonObject.put("action", "online");
+    sitesImpl.add(jsonObject);
+    }
 }