Improve coverage 19/31919/6
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Mon, 26 Feb 2018 05:39:10 +0000 (11:09 +0530)
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Mon, 26 Feb 2018 05:44:31 +0000 (11:14 +0530)
Issue-ID: VFC-764

Change-Id: I02ecd6eaeefc298bce133adce65a6751459ad1c0
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapter2DriverMgrService.java
huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapterMgrService.java
huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java
huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java

index 83652b7..b3ba176 100644 (file)
@@ -82,12 +82,16 @@ public class VnfmAdapter2DriverMgrService implements IVnfmAdapter2DriverMgrServi
      * @throws IOException
      */
     public static String readVnfmAdapterInfoFromJson() throws IOException {
-        String fileContent = "";
-
         String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot()
                 + System.getProperty(Constant.FILE_SEPARATOR) + "etc" + System.getProperty(Constant.FILE_SEPARATOR)
                 + "adapterInfo" + System.getProperty(Constant.FILE_SEPARATOR) + VNFMADAPTER2DRIVERMGR;
 
+        return readJson(fileName);
+    }
+
+    public static String readJson(String fileName) throws IOException {
+        String fileContent = "";
+
         try (InputStream ins = new FileInputStream(fileName)){
             try(BufferedInputStream bins = new BufferedInputStream(ins)){
 
index dabaf38..8df2c79 100644 (file)
@@ -81,14 +81,19 @@ public class VnfmAdapterMgrService implements IVnfmAdapterMgrService {
      * @throws IOException
      */
     public String readVnfmAdapterInfoFromJson() throws IOException {
-        String fileContent = "";
-
         String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot()
                 + System.getProperty(Constant.FILE_SEPARATOR) + "etc" + System.getProperty(Constant.FILE_SEPARATOR)
                 + "adapterInfo" + System.getProperty(Constant.FILE_SEPARATOR) + VNFMADAPTERINFO;
 
-        try (InputStream ins = new FileInputStream(fileName)) {
-            try (BufferedInputStream bins = new BufferedInputStream(ins)){
+
+        return readJson(fileName);
+    }
+
+    public static String readJson(String fileName) throws IOException {
+        String fileContent = "";
+
+        try (InputStream ins = new FileInputStream(fileName)){
+            try(BufferedInputStream bins = new BufferedInputStream(ins)){
 
                 byte[] contentByte = new byte[ins.available()];
                 int num = bins.read(contentByte);
@@ -104,6 +109,7 @@ public class VnfmAdapterMgrService implements IVnfmAdapterMgrService {
         return fileContent;
     }
 
+
     private static class RegisterVnfmAdapterThread implements Runnable {
 
         private IDriver2MSBManager adapter2MSBMgr = new Driver2MSBManager();
index 12910c8..d61c3b1 100644 (file)
 
 package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.ai.internalsvc.impl;
 
-import mockit.Mock;
-import mockit.MockUp;
+import java.io.File;
+import java.io.IOException;
+
 import org.junit.Test;
 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.api.internalsvc.impl.VnfmAdapter2DriverMgrService;
 
-import java.io.IOException;
+import junit.framework.Assert;
+import mockit.Mock;
+import mockit.MockUp;
 
 /**
  * Created by QuanZhong on 2017/3/20.
@@ -48,4 +51,17 @@ public class VnfmAdapter2DriverMgrServiceTest {
         mgr.register();
         mgr.unregister();
     }
+
+    @Test
+    public void testReadJson() {
+        File file = new File("./demo.json");
+        try {
+            file.createNewFile();
+            String content = VnfmAdapter2DriverMgrService.readJson("./demo.json");
+            Assert.assertEquals(content,  "");
+            file.delete();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 }
index 84a7c91..56e1eea 100644 (file)
 
 package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.ai.internalsvc.impl;
 
-import mockit.Mock;
-import mockit.MockUp;
-import net.sf.json.JSONObject;
+import java.io.File;
+import java.io.IOException;
+
 import org.junit.Test;
 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.api.internalsvc.impl.VnfmAdapterMgrService;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.VnfMgr;
 
-import java.io.IOException;
+import junit.framework.Assert;
+import mockit.Mock;
+import mockit.MockUp;
 
 /**
  * Created by QuanZhong on 2017/3/20.
@@ -42,4 +43,18 @@ public class VnfmAdapterMgrServiceTest {
         mgr.register();
 
     }
+
+
+    @Test
+    public void testReadJson() {
+        File file = new File("./demo.json");
+        try {
+            file.createNewFile();
+            String content = VnfmAdapterMgrService.readJson("./demo.json");
+            Assert.assertEquals(content,  "");
+            file.delete();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 }