Fix the lack of test coverage reported by sonar 58/99558/3
authorDmitry Puzikov <d.puzikov2@partner.samsung.com>
Mon, 9 Dec 2019 08:36:35 +0000 (09:36 +0100)
committerOren Kleks <oren.kleks@amdocs.com>
Sun, 15 Dec 2019 11:54:47 +0000 (11:54 +0000)
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

common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/impl/ConfigurationRepositoryTest.java

index d604d1e..a045ecd 100644 (file)
 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));
+    }
 }