diff options
author | Dmitry Puzikov <d.puzikov2@partner.samsung.com> | 2019-11-13 12:51:41 +0100 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2019-12-01 15:25:43 +0000 |
commit | 4a9ddb2618b8dde8820c08d934c708216b0ebca9 (patch) | |
tree | 1dba2999d87ef1717b9f8211b137188e1cefb08a /common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/ConfigurationUtilsTest.java | |
parent | 5b1f9a16f823c31d26f9306ea1ee540120f6780e (diff) |
Fixing sonar issue
Getting rid of nested ifs-fors
Change-Id: I71ef686683b7070614c27aabbf6cd058b5d35ffd
Issue-ID: SDC-2654
Signed-off-by: Dmitry Puzikov <d.puzikov2@partner.samsung.com>
Diffstat (limited to 'common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/ConfigurationUtilsTest.java')
-rw-r--r-- | common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/ConfigurationUtilsTest.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/ConfigurationUtilsTest.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/ConfigurationUtilsTest.java index d0b0a12297..dab8946883 100644 --- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/ConfigurationUtilsTest.java +++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/ConfigurationUtilsTest.java @@ -26,8 +26,12 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertFalse; +import java.io.File; +import java.io.IOException; import java.lang.reflect.Array; import java.lang.reflect.Field; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; @@ -54,11 +58,13 @@ import org.apache.commons.configuration2.CompositeConfiguration; import org.apache.commons.configuration2.Configuration; import org.apache.commons.configuration2.PropertiesConfiguration; import org.junit.Test; +import org.onap.config.util.TestUtil; import org.onap.config.api.Hint; import org.onap.config.impl.ConfigurationRepository; public class ConfigurationUtilsTest { + public static final String TMP_DIR_PREFIX = "sdc-testing-"; private static final String TEST_NAME_SPACE = "testNameSpaceOne"; private static final String TEST_COMPOSITE_NAMESPACE = "testCOmpositeConfig"; @@ -134,6 +140,53 @@ public class ConfigurationUtilsTest { } @Test + public void testGetAllFilesRecursiveIncludeAll() throws IOException { + Path tmpRoot = TestUtil.createTestDirsStructure(TMP_DIR_PREFIX); + Collection<File> allFiles = ConfigurationUtils.getAllFiles(tmpRoot.toFile(), true, false); + assertEquals(7, allFiles.size()); + TestUtil.deleteTestDirsStrucuture(tmpRoot); + } + + @Test + public void testGetAllFilesRecursiveIncludeDirsOnly() throws IOException { + Path tmpRoot = TestUtil.createTestDirsStructure(TMP_DIR_PREFIX); + Collection<File> allFiles = ConfigurationUtils.getAllFiles(tmpRoot.toFile(), true, true); + assertEquals(3, allFiles.size()); + TestUtil.deleteTestDirsStrucuture(tmpRoot); + } + + @Test + public void testGetAllFilesNonRecursiveIncludeAll() throws IOException { + Path tmpRoot = TestUtil.createTestDirsStructure(TMP_DIR_PREFIX); + Collection<File> allFiles = ConfigurationUtils.getAllFiles(tmpRoot.toFile(), false, false); + assertEquals(2, allFiles.size()); + TestUtil.deleteTestDirsStrucuture(tmpRoot); + } + + @Test + public void testGetAllFilesNonRecursiveIncludeDirsOnly() throws IOException { + Path tmpRoot = TestUtil.createTestDirsStructure(TMP_DIR_PREFIX); + Collection<File> allFiles = ConfigurationUtils.getAllFiles(tmpRoot.toFile(), false, true); + assertEquals(1, allFiles.size()); + TestUtil.deleteTestDirsStrucuture(tmpRoot); + } + + @Test + public void testGetAllFilesEmptyDir() throws IOException { + Path tmpRoot = TestUtil.createEmptyTmpDir(TMP_DIR_PREFIX); + Collection<File> allFiles = ConfigurationUtils.getAllFiles(tmpRoot.toFile(), true, true); + assertEquals(0, allFiles.size()); + TestUtil.deleteTestDirsStrucuture(tmpRoot); + } + + @Test + public void testGetAllFilesNonExistentDir() throws IOException { + Path nonExistentDir = Paths.get("/tmp/nonexistentdir"); + Collection<File> allFiles = ConfigurationUtils.getAllFiles(nonExistentDir.toFile(), false, true); + assertEquals(0, allFiles.size()); + } + + @Test public void testGetConfigPropertyBaseConfig() throws Exception { ConfigurationRepository repo = populateTestBaseConfig(); Configuration config = repo.getConfigurationFor(Constants.DEFAULT_TENANT, TEST_NAME_SPACE); |