summaryrefslogtreecommitdiffstats
path: root/common/onap-common-configuration-management/onap-configuration-management-core
diff options
context:
space:
mode:
authorDmitry Puzikov <d.puzikov2@partner.samsung.com>2019-12-09 09:36:35 +0100
committerOren Kleks <oren.kleks@amdocs.com>2019-12-15 11:54:47 +0000
commitf803d286777f68f01d96f771927babbc2b70706b (patch)
tree70fc40b293e56f43028a1a22f3ca84b9bfc358eb /common/onap-common-configuration-management/onap-configuration-management-core
parent95d6b878cf80483a8bad13f96566f7268b931ce7 (diff)
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 <d.puzikov2@partner.samsung.com> Change-Id: I3fb49f2fc794411347780a904837d8d0c61aa7bf
Diffstat (limited to 'common/onap-common-configuration-management/onap-configuration-management-core')
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/impl/ConfigurationRepositoryTest.java48
1 files changed, 48 insertions, 0 deletions
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));
+ }
}