diff options
author | Kailun Qin <kailun.qin@intel.com> | 2018-09-15 02:59:13 +0800 |
---|---|---|
committer | Kailun Qin <kailun.qin@intel.com> | 2018-09-15 04:23:36 +0800 |
commit | 8c6e31f75f82db7d9e685b62b41521a8992fa3de (patch) | |
tree | 30165aae11a40d6b614fb1a6ecbef4a94ff29106 /vnf-sdk-function-test/src/test | |
parent | e27e96cecfd2f0e370436fa040a5771245684301 (diff) |
Sonar: add coverage for unit test
Change-Id: I5828f116cb21885a70679c3e98e47e91f393e8f0
Issue-ID: VNFSDK-320
Signed-off-by: Kailun Qin <kailun.qin@intel.com>
Diffstat (limited to 'vnf-sdk-function-test/src/test')
4 files changed, 96 insertions, 1 deletions
diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/FileUtilTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/FileUtilTest.java index 01e2c0b..67b701c 100644 --- a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/FileUtilTest.java +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/FileUtilTest.java @@ -16,9 +16,13 @@ package org.onap.vnfsdk.functest; +import org.junit.Before; import org.junit.Test; import java.io.File; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Modifier; import static org.junit.Assert.assertTrue; @@ -30,9 +34,21 @@ public class FileUtilTest { private String zipFileName = "src/test/resources/RobotScript.zip"; + @Before + public void setUp() { + FileUtil.createDirectory(createDirPath); + } + @Test - public void testCreateDirectory() { + public void testConstructorIsPrivate() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { + Constructor<FileUtil> constructor = FileUtil.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } + @Test + public void testCreateDirectory() { assertTrue(FileUtil.createDirectory(createDirPath)); } @@ -47,12 +63,31 @@ public class FileUtilTest { } @Test + public void testUnzip() { + try { + FileUtil.unzip(zipFileName, createDirPath); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test public void testGetDirectory() { FileUtil.getDirectory("."); assertTrue(true); } @Test + public void testCheckFileExist() { + assertTrue(FileUtil.checkFileExist(deleteDirPath)); + } + + @Test + public void testDeleteFileWithPath() { + assertTrue(FileUtil.deleteFile(deleteDirPath)); + } + + @Test public void testConvertZipFiletoByteArray() { byte[] byteArrayFile = FileUtil.convertZipFiletoByteArray(zipFileName); // assertNotNull(byteArrayFile); diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/common/TestConfig.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/common/TestConfig.java index 132fdf8..1732c74 100644 --- a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/common/TestConfig.java +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/common/TestConfig.java @@ -21,7 +21,12 @@ import org.junit.Before; import org.junit.Test; import org.onap.vnfsdk.functest.VnfSdkFuncTestAppConfiguration; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Modifier; + import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class TestConfig { @@ -33,6 +38,14 @@ public class TestConfig { } @Test + public void testConstructorIsPrivate() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { + Constructor<Config> constructor = Config.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } + + @Test public void testVnfSdkConfigBean() { vnfSdkBean.setTemplate(""); vnfSdkBean.setServiceIp("127.0.0.1"); diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/ServiceRegisterEntityTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/ServiceRegisterEntityTest.java index 493882f..c75308c 100644 --- a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/ServiceRegisterEntityTest.java +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/ServiceRegisterEntityTest.java @@ -42,6 +42,7 @@ public class ServiceRegisterEntityTest { serviceRegistry.setServiceName("nfvo"); serviceRegistry.setVersion("5.6"); + serviceRegistry.setUrl("http://localhost:8080"); serviceRegistry.setProtocol("http"); serviceRegistry.setVisualRange("range"); @@ -55,6 +56,7 @@ public class ServiceRegisterEntityTest { assertNotNull(serviceRegistry); assertNotNull(serviceRegistry.getServiceName()); assertNotNull(serviceRegistry.getVersion()); + assertNotNull(serviceRegistry.getUrl()); assertNotNull(serviceRegistry.getProtocol()); assertNotNull(serviceRegistry.getVisualRange()); assertNotNull(serviceRegistry.getNodes()); @@ -65,4 +67,9 @@ public class ServiceRegisterEntityTest { public void testSetSingleNode() { serviceRegistry.setSingleNode("192.168.4.47", "8080", 10); } + + @Test + public void testSetSingleNodeEmptyIp() { + serviceRegistry.setSingleNode("", "8080", 10); + } } diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandlerTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandlerTest.java index 26007e3..2cbd48d 100644 --- a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandlerTest.java +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandlerTest.java @@ -18,13 +18,19 @@ package org.onap.vnfsdk.functest.responsehandler; import org.junit.Test; +import javax.ws.rs.core.Response; import java.lang.reflect.Method; +import java.util.Map; +import java.util.UUID; import static org.junit.Assert.assertNotNull; public class VnfFuncTestResponseHandlerTest { private VnfFuncTestResponseHandler vnfSdkFuncHandler; + private Map<String, String> mapConfigValues; + private UUID taskID = UUID.fromString("59d1e651-df9f-4008-902f-e3b377e6ec30"); + private Response response = null; @Test public void testGetInstance() { @@ -33,6 +39,18 @@ public class VnfFuncTestResponseHandlerTest { } @Test + public void testSetConfigMap() { + try { + Object vnfFuncTestResponseHandlerObj = VnfFuncTestResponseHandler.getInstance(); + Method m = vnfFuncTestResponseHandlerObj.getClass().getDeclaredMethod("setConfigMap", new Class[]{Map.class}); + m.setAccessible(true); + m.invoke(vnfFuncTestResponseHandlerObj, mapConfigValues); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test public void testLoadConfigurations() { try { Object vnfFuncTestResponseHandlerObj = VnfFuncTestResponseHandler.getInstance(); @@ -43,4 +61,26 @@ public class VnfFuncTestResponseHandlerTest { e.printStackTrace(); } } + + /* TO DO: check whether getResponseByFuncTestId is still needed */ + @Test + public void testGetResponseByFuncTestId() { + try { + vnfSdkFuncHandler = VnfFuncTestResponseHandler.getInstance(); + response = vnfSdkFuncHandler.getResponseByFuncTestId(taskID.toString()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testDownloadResults() { + try { + vnfSdkFuncHandler = VnfFuncTestResponseHandler.getInstance(); + response = vnfSdkFuncHandler.downloadResults(taskID.toString()); + assertNotNull(response); + } catch (Exception e) { + e.printStackTrace(); + } + } } |