From 4a9ddb2618b8dde8820c08d934c708216b0ebca9 Mon Sep 17 00:00:00 2001 From: Dmitry Puzikov Date: Wed, 13 Nov 2019 12:51:41 +0100 Subject: Fixing sonar issue Getting rid of nested ifs-fors Change-Id: I71ef686683b7070614c27aabbf6cd058b5d35ffd Issue-ID: SDC-2654 Signed-off-by: Dmitry Puzikov --- .../org/onap/config/ConfigurationUtilsTest.java | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/ConfigurationUtilsTest.java') 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"; @@ -133,6 +139,53 @@ public class ConfigurationUtilsTest { } + @Test + public void testGetAllFilesRecursiveIncludeAll() throws IOException { + Path tmpRoot = TestUtil.createTestDirsStructure(TMP_DIR_PREFIX); + Collection 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 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 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 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 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 allFiles = ConfigurationUtils.getAllFiles(nonExistentDir.toFile(), false, true); + assertEquals(0, allFiles.size()); + } + @Test public void testGetConfigPropertyBaseConfig() throws Exception { ConfigurationRepository repo = populateTestBaseConfig(); -- cgit 1.2.3-korg