diff options
author | Dmitry Puzikov <d.puzikov2@partner.samsung.com> | 2019-11-19 09:55:27 +0100 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2019-11-25 08:50:03 +0000 |
commit | 1d3f7e44c9773db172694e8abe0c1ffea1538e37 (patch) | |
tree | abface10322ef57211f016621b84c2090eef8394 /common/onap-common-configuration-management/onap-configuration-management-core/src/test | |
parent | 60be4e21f1ada02fbbdb39cc47ff1c69c098a00a (diff) |
Fixing sonar issues
Simplified method ConfigurationUtils::getProperty.
Added unit tests for method.
Change-Id: I521661b464e7f60101ee51ccbc9d915bf5030f31
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')
-rw-r--r-- | common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/ConfigurationUtilsTest.java | 58 |
1 files changed, 58 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 b32c1d81df..d0b0a12297 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 @@ -49,10 +49,19 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; +import org.apache.commons.configuration2.BaseConfiguration; +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.api.Hint; +import org.onap.config.impl.ConfigurationRepository; public class ConfigurationUtilsTest { + private static final String TEST_NAME_SPACE = "testNameSpaceOne"; + private static final String TEST_COMPOSITE_NAMESPACE = "testCOmpositeConfig"; + @Test public void testCommaList() { List<?> list = Arrays.asList("1", "2", 3); @@ -123,4 +132,53 @@ public class ConfigurationUtilsTest { ConfigurationUtils.getCompatibleCollectionForAbstractDef(Collection.class); } + + @Test + public void testGetConfigPropertyBaseConfig() throws Exception { + ConfigurationRepository repo = populateTestBaseConfig(); + Configuration config = repo.getConfigurationFor(Constants.DEFAULT_TENANT, TEST_NAME_SPACE); + assertEquals(TEST_NAME_SPACE, ConfigurationUtils.getProperty(config, Constants.NAMESPACE_KEY, Hint.DEFAULT.value())); + } + + @Test + public void testGetCompositeConfigPropertyDefaultHints() throws Exception { + ConfigurationRepository repo = populateTestCompositeConfig(); + Configuration config = repo.getConfigurationFor(Constants.DEFAULT_TENANT, TEST_COMPOSITE_NAMESPACE); + assertEquals(TEST_NAME_SPACE, ConfigurationUtils.getProperty(config, Constants.NAMESPACE_KEY, Hint.DEFAULT.value())); + } + + @Test + public void testGetCompositeConfigPropertyNodeSpecificHints() throws Exception { + ConfigurationRepository repo = populateTestCompositeConfig(); + Configuration config = repo.getConfigurationFor(Constants.DEFAULT_TENANT, TEST_COMPOSITE_NAMESPACE); + assertEquals(TEST_NAME_SPACE, ConfigurationUtils.getProperty(config, Constants.NAMESPACE_KEY, Hint.NODE_SPECIFIC.value())); + } + + private ConfigurationRepository populateTestBaseConfig() { + BaseConfiguration inputConfig = new PropertiesConfiguration(); + inputConfig.setProperty(Constants.NAMESPACE_KEY, TEST_NAME_SPACE); + ConfigurationRepository repo = ConfigurationRepository.lookup(); + + repo.populateConfiguration( + Constants.DEFAULT_TENANT + Constants.KEY_ELEMENTS_DELIMITER + TEST_NAME_SPACE, inputConfig); + + return repo; + } + + private ConfigurationRepository populateTestCompositeConfig() { + CompositeConfiguration inputCompositeConfig = new CompositeConfiguration(); + Configuration inputConfig1= new BaseConfiguration(); + Configuration inputConfig2= new BaseConfiguration(); + inputConfig1.setProperty(Constants.NAMESPACE_KEY, TEST_NAME_SPACE); + inputCompositeConfig.addConfiguration(inputConfig1); + inputCompositeConfig.addConfigurationFirst(inputConfig2); + + ConfigurationRepository repo = ConfigurationRepository.lookup(); + repo.populateConfiguration( + Constants.DEFAULT_TENANT + Constants.KEY_ELEMENTS_DELIMITER + TEST_COMPOSITE_NAMESPACE, + inputCompositeConfig + ); + + return repo; + } } |