diff options
author | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2018-02-26 11:09:10 +0530 |
---|---|---|
committer | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2018-02-26 11:14:31 +0530 |
commit | 3bb98db80eedfa13cbe41ccd14cd151a2ef17d07 (patch) | |
tree | bf0a032a77b7b8ce3668abb09a506b166c3890df /huawei/vnfmadapter | |
parent | a4996ef65017d8e296d040fe50aa05d417509e63 (diff) |
Improve coverage
Issue-ID: VFC-764
Change-Id: I02ecd6eaeefc298bce133adce65a6751459ad1c0
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'huawei/vnfmadapter')
4 files changed, 55 insertions, 14 deletions
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapter2DriverMgrService.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapter2DriverMgrService.java index 83652b70..b3ba1760 100644 --- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapter2DriverMgrService.java +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapter2DriverMgrService.java @@ -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)){ diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapterMgrService.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapterMgrService.java index dabaf380..8df2c796 100644 --- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapterMgrService.java +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapterMgrService.java @@ -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(); diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java index 12910c8e..d61c3b1c 100644 --- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java @@ -16,12 +16,15 @@ 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(); + } + } } diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java index 84a7c914..56e1eea3 100644 --- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java @@ -16,14 +16,15 @@ 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(); + } + } } |