From f803d286777f68f01d96f771927babbc2b70706b Mon Sep 17 00:00:00 2001 From: Dmitry Puzikov Date: Mon, 9 Dec 2019 09:36:35 +0100 Subject: Fix the lack of test coverage reported by sonar Added tests to increase coverage. Fixed test faiulures. Issue-ID: SDC-2710 Signed-off-by: Dmitry Puzikov Change-Id: I3fb49f2fc794411347780a904837d8d0c61aa7bf --- .../config/impl/ConfigurationRepositoryTest.java | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/impl/ConfigurationRepositoryTest.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/impl/ConfigurationRepositoryTest.java index d604d1e757..a045ecdff3 100644 --- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/impl/ConfigurationRepositoryTest.java +++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/impl/ConfigurationRepositoryTest.java @@ -22,24 +22,53 @@ package org.onap.config.impl; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.file.Paths; +import java.util.Properties; import java.util.Set; import org.apache.commons.configuration2.BaseConfiguration; import org.apache.commons.configuration2.Configuration; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.onap.config.Constants; +import org.onap.config.util.ConfigTestConstant; +import org.onap.config.util.TestUtil; public class ConfigurationRepositoryTest { private static final String[] EMPTY_ARRAY_OF_STRING = new String[0]; private static final String TEST_NAME_SPACE = "testNameSpace"; + private static final String TEST_CONFIG_FILE = TestUtil.jsonSchemaLoc + "config.properties"; private ConfigurationRepository repository; + @BeforeClass + public static void setUp() throws Exception { + Properties props = new Properties(); + props.setProperty(ConfigTestConstant.ARTIFACT_MAXSIZE, "10240"); + File dir = new File(TestUtil.jsonSchemaLoc); + dir.mkdirs(); + File f = new File(TEST_CONFIG_FILE); + try (OutputStream out = new FileOutputStream(f)) { + props.store(out, "Config Property at Conventional Resource"); + } + } + + @AfterClass + public static void tearDown() throws IOException { + TestUtil.deleteTestDirsStrucuture(Paths.get(TestUtil.jsonSchemaLoc)); + } + @Before public void init() { repository = ConfigurationRepository.lookup(); @@ -80,4 +109,23 @@ public class ConfigurationRepositoryTest { // then assertEquals(inputConfig, outputConfig); } + + @Test + public void testPopulateOverrideConfiguration() throws Exception { + // given + BaseConfiguration inputConfig = new BaseConfiguration(); + repository.populateConfiguration(Constants.DEFAULT_TENANT + Constants.KEY_ELEMENTS_DELIMITER + + TEST_NAME_SPACE, inputConfig); + + // when + repository.populateOverrideConfiguration(Constants.DEFAULT_TENANT + Constants.KEY_ELEMENTS_DELIMITER + + TEST_NAME_SPACE, new File(TEST_CONFIG_FILE)); + final Configuration outputConfig = repository.getConfigurationFor(Constants.DEFAULT_TENANT, TEST_NAME_SPACE); + + // then + assertNotEquals(inputConfig, outputConfig); + assertEquals(0, inputConfig.size()); + assertEquals(1, outputConfig.size()); + assertEquals("10240", outputConfig.getString(ConfigTestConstant.ARTIFACT_MAXSIZE)); + } } -- cgit 1.2.3-korg