Fix unstable TCs 68/119268/1
authorvasraz <vasyl.razinkov@est.tech>
Fri, 12 Mar 2021 18:53:01 +0000 (18:53 +0000)
committerVasyl Razinkov <vasyl.razinkov@est.tech>
Fri, 12 Mar 2021 18:55:06 +0000 (18:55 +0000)
 - Migrate to Junit 5
 - log exception instead of failing

Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Issue-ID: SDC-3490
Change-Id: I75bbf4ffb991b75cd38ba91ca480851b9daf8093

17 files changed:
common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/test/CliFallbackAndLookupTest.java
common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/test/CliTest.java
common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/test/ConfigSourceLocationTest.java
common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/test/ConfigurationQueryTest.java
common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/test/FallbackConfigTest.java
common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/test/FallbackToGlobalNamespaceTest.java
common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/test/GlobalAndNamespaceConfigTest.java
common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/test/JavaPropertiesConfigTest.java
common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/test/JsonConfigTest.java
common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/test/LoadOrderMergeAndOverrideTest.java
common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/test/ModeAsConfigPropTest.java
common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/test/MultiTenancyConfigTest.java
common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/test/NodeSpecificCliTest.java
common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/test/ValidateDefaultModeTest.java
common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/test/XmlConfigTest.java
common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/test/YamlConfigTest.java
common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/util/TestUtil.java

index 4383124..d0fba69 100644 (file)
 
 package org.onap.config.test;
 
-import java.io.IOException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 import java.util.HashMap;
 import java.util.Map;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.onap.config.api.ConfigurationManager;
 import org.onap.config.impl.CliConfigurationImpl;
 import org.onap.config.util.ConfigTestConstant;
@@ -33,19 +33,18 @@ import org.onap.config.util.TestUtil;
  * Scenario 17
  * Verify Configuration Management System - Command Line Interface for query, update and list operations
  */
-public class CliTest {
+class CliTest {
 
     private static final String NAMESPACE = "CLI";
     private static final String TENANT = "OPENECOMP";
 
-    @Before
-    public void setUp() throws IOException {
-        String data = "{name:\"SCM\"}";
-        TestUtil.writeFile(data);
+    @BeforeEach
+    public void setUp() throws Exception {
+        TestUtil.cleanUp();
     }
 
     @Test
-    public void testCliApi() throws Exception {
+    void testCliApi() throws Exception {
         //Verify without fallback
         Map<String, Object> input = new HashMap<>();
         input.put("ImplClass", "org.onap.config.type.ConfigurationQuery");
@@ -55,7 +54,7 @@ public class CliTest {
 
         ConfigurationManager conf = new CliConfigurationImpl();
         String maxLength = conf.getConfigurationValue(input);
-        Assert.assertEquals("14", maxLength);
+        assertEquals("14", maxLength);
 
         Map<String, String> outputMap = conf.listConfiguration(input);
         validateCliListConfig(outputMap);
@@ -63,23 +62,20 @@ public class CliTest {
 
     private void validateCliListConfig(Map<String, String> outputMap) {
 
-        Assert.assertEquals("@" + System.getProperty("user.home") + "/TestResources/GeneratorsList.json",
-                outputMap.get(ConfigTestConstant.ARTIFACT_JSON_SCHEMA));
-        Assert.assertEquals("appc,catalog", outputMap.get(ConfigTestConstant.ARTIFACT_CONSUMER));
-        Assert.assertEquals("6", outputMap.get(ConfigTestConstant.ARTIFACT_NAME_MINLENGTH));
-        Assert.assertEquals("true", outputMap.get(ConfigTestConstant.ARTIFACT_ENCODED));
-        Assert.assertEquals("14", outputMap.get(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
-        Assert.assertEquals("pdf,zip,xml,pdf,tgz,xls", outputMap.get(ConfigTestConstant.ARTIFACT_EXT));
-        Assert.assertEquals("Base64,MD5", outputMap.get(ConfigTestConstant.ARTIFACT_ENC));
-        Assert.assertEquals("@" + TestUtil.getenv(ConfigTestConstant.PATH) + "/myschema.json",
-                outputMap.get(ConfigTestConstant.ARTIFACT_XML_SCHEMA));
-        Assert.assertEquals("a-zA-Z_0-9", outputMap.get(ConfigTestConstant.ARTIFACT_NAME_UPPER));
-        Assert.assertEquals("/opt/spool," + System.getProperty("user.home") + "/asdc",
-                outputMap.get(ConfigTestConstant.ARTIFACT_LOC));
-        Assert.assertEquals("deleted,Deleted", outputMap.get(ConfigTestConstant.ARTIFACT_STATUS));
+        assertEquals("@" + System.getProperty("user.home") + "/TestResources/GeneratorsList.json", outputMap.get(ConfigTestConstant.ARTIFACT_JSON_SCHEMA));
+        assertEquals("appc,catalog", outputMap.get(ConfigTestConstant.ARTIFACT_CONSUMER));
+        assertEquals("6", outputMap.get(ConfigTestConstant.ARTIFACT_NAME_MINLENGTH));
+        assertEquals("true", outputMap.get(ConfigTestConstant.ARTIFACT_ENCODED));
+        assertEquals("14", outputMap.get(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
+        assertEquals("pdf,zip,xml,pdf,tgz,xls", outputMap.get(ConfigTestConstant.ARTIFACT_EXT));
+        assertEquals("Base64,MD5", outputMap.get(ConfigTestConstant.ARTIFACT_ENC));
+        assertEquals("@" + TestUtil.getenv(ConfigTestConstant.PATH) + "/myschema.json", outputMap.get(ConfigTestConstant.ARTIFACT_XML_SCHEMA));
+        assertEquals("a-zA-Z_0-9", outputMap.get(ConfigTestConstant.ARTIFACT_NAME_UPPER));
+        assertEquals("/opt/spool," + System.getProperty("user.home") + "/asdc", outputMap.get(ConfigTestConstant.ARTIFACT_LOC));
+        assertEquals("deleted,Deleted", outputMap.get(ConfigTestConstant.ARTIFACT_STATUS));
     }
 
-    @After
+    @AfterEach
     public void tearDown() throws Exception {
         TestUtil.cleanUp();
     }
index f291f8e..897ed35 100644 (file)
 
 package org.onap.config.test;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Properties;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.onap.config.api.Configuration;
 import org.onap.config.api.ConfigurationManager;
 import org.onap.config.util.ConfigTestConstant;
@@ -36,14 +36,13 @@ import org.onap.config.util.TestUtil;
  * Validate conventional and configurational source location.
  * Pre-requisite - set -Dconfig.location=${"user.home"}/TestResources/ while running test
  */
-public class ConfigSourceLocationTest {
+class ConfigSourceLocationTest {
 
     private static final String NAMESPACE = "SourceLocation";
 
-    @Before
-    public void setUp() throws IOException {
-        String data = "{name:\"SCM\"}";
-        TestUtil.writeFile(data);
+    @BeforeEach
+    public void setUp() throws Exception {
+        TestUtil.cleanUp();
 
         Properties props = new Properties();
         props.setProperty("maxCachedBufferSize", "1024");
@@ -55,13 +54,13 @@ public class ConfigSourceLocationTest {
     }
 
     @Test
-    public void testMergeStrategyInConfig() {
+    void testMergeStrategyInConfig() {
         Configuration config = ConfigurationManager.lookup();
-        Assert.assertEquals("a-zA-Z_0-9", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_UPPER));
-        Assert.assertEquals("1024", config.getAsString(ConfigTestConstant.ARTIFACT_MAXSIZE));
+        assertEquals("a-zA-Z_0-9", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_UPPER));
+        assertEquals("1024", config.getAsString(ConfigTestConstant.ARTIFACT_MAXSIZE));
     }
 
-    @After
+    @AfterEach
     public void tearDown() throws Exception {
         TestUtil.cleanUp();
     }
index 7a468ce..8f9076c 100644 (file)
 
 package org.onap.config.test;
 
-import org.junit.Test;
-import org.onap.config.type.ConfigurationQuery;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
-public class ConfigurationQueryTest {
+import org.junit.jupiter.api.Test;
+import org.onap.config.type.ConfigurationQuery;
+
+class ConfigurationQueryTest {
+
     private static String TENANT = "OPENECOMP";
     private static String NAMESPACE = "tetsNamepspace";
     private static String KEY = "testKey";
 
     @Test
-    public void testConfigurationQueryBuild() {
+    void testConfigurationQueryBuild() {
         // given
         ConfigurationQuery configurationQuery = new ConfigurationQuery();
 
         // when
         configurationQuery = configurationQuery
-                .externalLookup(true)
-                .fallback(true)
-                .latest(true)
-                .nodeSpecific(true)
-                .namespace(NAMESPACE)
-                .tenant(TENANT)
-                .key(KEY);
+            .externalLookup(true)
+            .fallback(true)
+            .latest(true)
+            .nodeSpecific(true)
+            .namespace(NAMESPACE)
+            .tenant(TENANT)
+            .key(KEY);
 
         // then
         assertEquals(TENANT.toUpperCase(), configurationQuery.getTenant());
index 876aed0..27f6343 100644 (file)
 package org.onap.config.test;
 
 import static org.onap.config.util.TestUtil.validateConfiguration;
-import static org.onap.config.util.TestUtil.writeFile;
 
-import java.io.IOException;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.onap.config.util.TestUtil;
 
 /**
  * Created by ARR on 10/14/2016.
  * Validate configuration with properties,xml,json,yaml file format with mode.
  */
-public class FallbackConfigTest {
+class FallbackConfigTest {
 
     private static final String NAMESPACE = "fallback";
 
-    @Before
-    public void setUp() throws IOException {
-        String data = "{name:\"SCM\"}";
-        writeFile(data);
+    @BeforeEach
+    public void setUp() throws Exception {
+        TestUtil.cleanUp();
     }
 
     @Test
-    public void testConfigurationWithFallbackFileFormat() {
+    void testConfigurationWithFallbackFileFormat() {
         validateConfiguration(NAMESPACE);
     }
 
-    @After
+    @AfterEach
     public void tearDown() throws Exception {
-        String data = "{name:\"SCM\"}";
-        writeFile(data);
+        TestUtil.cleanUp();
     }
 }
index b398a70..ab36b60 100644 (file)
 
 package org.onap.config.test;
 
-import java.io.IOException;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.onap.config.api.Configuration;
 import org.onap.config.api.ConfigurationManager;
 import org.onap.config.util.ConfigTestConstant;
@@ -32,24 +32,23 @@ import org.onap.config.util.TestUtil;
  * not exist in the namespace configuration.
  * Created by sheetalm on 10/14/2016.
  */
-public class FallbackToGlobalNamespaceTest {
+class FallbackToGlobalNamespaceTest {
 
     private static final String NAMESPACE = "FallbackToGlobalNS";
 
-    @Before
-    public void setUp() throws IOException {
-        String data = "{name:\"SCM\"}";
-        TestUtil.writeFile(data);
+    @BeforeEach
+    public void setUp() throws Exception {
+        TestUtil.cleanUp();
     }
 
     @Test
-    public void testFallbackToGlobalNamespace() {
+    void testFallbackToGlobalNamespace() {
         Configuration config = ConfigurationManager.lookup();
-        Assert.assertEquals("14", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
-        Assert.assertEquals("1024", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_MAXSIZE));
+        assertEquals("14", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
+        assertEquals("1024", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_MAXSIZE));
     }
 
-    @After
+    @AfterEach
     public void tearDown() throws Exception {
         TestUtil.cleanUp();
     }
index d66165c..5180d0a 100644 (file)
 
 package org.onap.config.test;
 
-import java.io.IOException;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.onap.config.api.Configuration;
 import org.onap.config.api.ConfigurationManager;
 import org.onap.config.util.ConfigTestConstant;
@@ -30,24 +30,23 @@ import org.onap.config.util.TestUtil;
  * Created by sheetalm on 10/13/2016.
  * Scenario 10 Verify configuration present in both global and defined namespace
  */
-public class GlobalAndNamespaceConfigTest {
+class GlobalAndNamespaceConfigTest {
 
     private static final String NAMESPACE = "GlobalAndNSConfig";
 
-    @Before
-    public void setUp() throws IOException {
-        String data = "{name:\"SCM\"}";
-        TestUtil.writeFile(data);
+    @BeforeEach
+    public void setUp() throws Exception {
+        TestUtil.cleanUp();
     }
 
     @Test
-    public void testNamespaceInConfig() {
+    void testNamespaceInConfig() {
         Configuration config = ConfigurationManager.lookup();
-        Assert.assertEquals("a-zA-Z", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_UPPER));
-        Assert.assertEquals("a-zA-Z_0-9", config.getAsString(ConfigTestConstant.ARTIFACT_NAME_UPPER));
+        assertEquals("a-zA-Z", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_UPPER));
+        assertEquals("a-zA-Z_0-9", config.getAsString(ConfigTestConstant.ARTIFACT_NAME_UPPER));
     }
 
-    @After
+    @AfterEach
     public void tearDown() throws Exception {
         TestUtil.cleanUp();
     }
index 0c82fe4..5055f37 100644 (file)
 package org.onap.config.test;
 
 import static org.onap.config.util.TestUtil.validateConfiguration;
-import static org.onap.config.util.TestUtil.writeFile;
 
-import java.io.IOException;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.onap.config.util.TestUtil;
 
 /**
@@ -30,23 +28,22 @@ import org.onap.config.util.TestUtil;
  * Scenario 1
  * Validate configuration with Java Properties file format with mode
  */
-public class JavaPropertiesConfigTest {
+class JavaPropertiesConfigTest {
 
     private static final String NAMESPACE = "javaProperties";
 
-    @Before
-    public void setUp() throws IOException {
-        String data = "{name:\"SCM\"}";
-        writeFile(data);
+    @BeforeEach
+    public void setUp() throws Exception {
+        TestUtil.cleanUp();
     }
 
     @Test
-    public void testConfigurationWithPropertiesFileFormat() {
+    void testConfigurationWithPropertiesFileFormat() {
         validateConfiguration(NAMESPACE);
     }
 
 
-    @After
+    @AfterEach
     public void tearDown() throws Exception {
         TestUtil.cleanUp();
     }
index cd3eb6a..67a9d05 100644 (file)
 package org.onap.config.test;
 
 import static org.onap.config.util.TestUtil.validateConfiguration;
-import static org.onap.config.util.TestUtil.writeFile;
 
-import java.io.IOException;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.onap.config.util.TestUtil;
 
 /**
  * Created by ARR on 10/14/2016.
  * Scenario 3 Validate configuration with JSON file format with mode.
  */
-public class JsonConfigTest {
+class JsonConfigTest {
 
     private static final String NAMESPACE = "JSONConfig";
 
-    @Before
-    public void setUp() throws IOException {
-        String data = "{name:\"SCM\"}";
-        writeFile(data);
+    @BeforeEach
+    public void setUp() throws Exception {
+        TestUtil.cleanUp();
     }
 
     @Test
-    public void testConfigurationWithJsonFileFormat() {
+    void testConfigurationWithJsonFileFormat() {
         validateConfiguration(NAMESPACE);
     }
 
 
-    @After
+    @AfterEach
     public void tearDown() throws Exception {
         TestUtil.cleanUp();
     }
index 6d189a0..2b9f0f9 100644 (file)
 
 package org.onap.config.test;
 
-import static org.onap.config.util.TestUtil.writeFile;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
-import java.io.IOException;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.onap.config.api.Configuration;
 import org.onap.config.api.ConfigurationManager;
 import org.onap.config.util.ConfigTestConstant;
@@ -33,27 +31,25 @@ import org.onap.config.util.TestUtil;
  * Check load order for merge and override. Higher load order takes precedence for override
  * Lower load order takes precedence for merge.
  */
-public class LoadOrderMergeAndOverrideTest {
+class LoadOrderMergeAndOverrideTest {
 
     private static final String NAMESPACE = "LoadOrderConfiguration";
 
-    @Before
-    public void setUp() throws IOException {
-        String data = "{name:\"SCM\"}";
-        writeFile(data);
+    @BeforeEach
+    public void setUp() throws Exception {
+        TestUtil.cleanUp();
     }
 
     @Test
-    public void testConfigurationWithPropertiesFileFormat() {
+    void testConfigurationWithPropertiesFileFormat() {
         Configuration config = ConfigurationManager.lookup();
 
-        Assert.assertEquals(config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH), "14");
-        Assert.assertEquals("5", config.getAsString(NAMESPACE, "artifact.length"));
-        Assert.assertEquals("56", config.getAsString(NAMESPACE, "artifact.size"));
+        assertEquals("14", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
+        assertEquals("5", config.getAsString(NAMESPACE, "artifact.length"));
+        assertEquals("56", config.getAsString(NAMESPACE, "artifact.size"));
     }
 
-
-    @After
+    @AfterEach
     public void tearDown() throws Exception {
         TestUtil.cleanUp();
     }
index 57f632a..172d324 100644 (file)
 
 package org.onap.config.test;
 
-import java.io.IOException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import java.util.ArrayList;
 import java.util.List;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.onap.config.api.Configuration;
 import org.onap.config.api.ConfigurationManager;
 import org.onap.config.util.ConfigTestConstant;
@@ -31,23 +32,22 @@ import org.onap.config.util.TestUtil;
 /**
  * Scenario 8 Validate configuration with mode specified as a configuration property.
  */
-public class ModeAsConfigPropTest {
+class ModeAsConfigPropTest {
 
     private static final String NAMESPACE = "ModeAsConfigProp";
 
-    @Before
-    public void setUp() throws IOException {
-        String data = "{name:\"SCM\"}";
-        TestUtil.writeFile(data);
+    @BeforeEach
+    public void setUp() throws Exception {
+        TestUtil.cleanUp();
     }
 
     @Test
-    public void testMergeStrategyInConfig() {
+    void testMergeStrategyInConfig() {
         Configuration config = ConfigurationManager.lookup();
 
-        Assert.assertEquals("14", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
+        assertEquals("14", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
 
-        Assert.assertEquals("1048", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_MAXSIZE));
+        assertEquals("1048", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_MAXSIZE));
 
         List<String> expectedExtList = new ArrayList<>();
         expectedExtList.add("pdf");
@@ -57,41 +57,41 @@ public class ModeAsConfigPropTest {
         expectedExtList.add("tgz");
         expectedExtList.add("xls");
         List<String> extList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_EXT);
-        Assert.assertEquals(expectedExtList, extList);
+        assertEquals(expectedExtList, extList);
 
         List<String> expectedEncList = new ArrayList<>();
         expectedEncList.add("Base64");
         expectedEncList.add("MD5");
         List<String> encList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_ENC);
-        Assert.assertEquals(expectedEncList, encList);
+        assertEquals(expectedEncList, encList);
 
-        Assert.assertEquals("{name:\"SCM\"}", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_JSON_SCHEMA));
+        assertEquals("{name:\"SCM\"}", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_JSON_SCHEMA));
 
-        Assert.assertEquals("a-zA-Z_0-9", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_UPPER));
+        assertEquals("a-zA-Z_0-9", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_UPPER));
 
-        Assert.assertEquals("Deleted", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_STATUS));
+        assertEquals("Deleted", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_STATUS));
 
         List<String> expectedLocList = new ArrayList<>();
         expectedLocList.add("/opt/spool");
         expectedLocList.add(System.getProperty("user.home") + "/asdc");
         List<String> locList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_LOC);
-        Assert.assertEquals(expectedLocList, locList);
+        assertEquals(expectedLocList, locList);
 
-        Assert.assertEquals("@" + TestUtil.getenv(ConfigTestConstant.PATH) + "/myschema.json",
-                config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_XML_SCHEMA));
+        assertEquals("@" + TestUtil.getenv(ConfigTestConstant.PATH) + "/myschema.json",
+            config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_XML_SCHEMA));
 
         List<String> artifactConsumer = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_CONSUMER);
-        Assert.assertEquals(config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_CONSUMER_APPC),
-                artifactConsumer);
+        assertEquals(config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_CONSUMER_APPC),
+            artifactConsumer);
 
-        Assert.assertEquals(config.getAsBooleanValue(NAMESPACE, ConfigTestConstant.ARTIFACT_MANDATORY_NAME), true);
+        assertTrue(config.getAsBooleanValue(NAMESPACE, ConfigTestConstant.ARTIFACT_MANDATORY_NAME));
 
-        Assert.assertEquals(config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MINLENGTH), "6");
+        assertEquals("6", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MINLENGTH));
 
-        Assert.assertEquals(config.getAsBooleanValue(NAMESPACE, ConfigTestConstant.ARTIFACT_ENCODED), true);
+        assertTrue(config.getAsBooleanValue(NAMESPACE, ConfigTestConstant.ARTIFACT_ENCODED));
     }
 
-    @After
+    @AfterEach
     public void tearDown() throws Exception {
         TestUtil.cleanUp();
     }
index 03c6356..c128cfc 100644 (file)
 
 package org.onap.config.test;
 
-import java.io.IOException;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.onap.config.api.Configuration;
 import org.onap.config.api.ConfigurationManager;
 import org.onap.config.util.ConfigTestConstant;
@@ -30,30 +30,26 @@ import org.onap.config.util.TestUtil;
  * Created by ARR on 10/14/2016.
  * Scenario 17 - Verify Configuration management System - Support for Multi-Tenancy.
  */
-public class MultiTenancyConfigTest {
+class MultiTenancyConfigTest {
 
     private static final String NAMESPACE = "tenancy";
 
-    @Before
-    public void setUp() throws IOException {
-        String data = "{name:\"SCM\"}";
-        TestUtil.writeFile(data);
+    @BeforeEach
+    public void setUp() throws Exception {
+        TestUtil.cleanUp();
     }
 
     @Test
-    public void testConfigurationWithMultiTenancyFileFormat() {
+    void testConfigurationWithMultiTenancyFileFormat() {
         Configuration config = ConfigurationManager.lookup();
 
-        Assert.assertEquals(config.getAsString("OPENECOMP", NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH),
-                "20");
-
-        Assert.assertEquals(config.getAsString("Telefonica", NAMESPACE, ConfigTestConstant.ARTIFACT_STATUS), "Deleted");
-
-        Assert.assertEquals(config.getAsString("TID", NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH), "14");
+        assertEquals("20", config.getAsString("OPENECOMP", NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
+        assertEquals("Deleted", config.getAsString("Telefonica", NAMESPACE, ConfigTestConstant.ARTIFACT_STATUS));
+        assertEquals("14", config.getAsString("TID", NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
 
     }
 
-    @After
+    @AfterEach
     public void tearDown() throws Exception {
         TestUtil.cleanUp();
     }
index cba1739..c0db95a 100644 (file)
@@ -27,7 +27,8 @@ import java.io.OutputStream;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
-import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import org.onap.config.api.ConfigurationManager;
@@ -36,8 +37,10 @@ import org.onap.config.util.ConfigTestConstant;
 import org.onap.config.util.TestUtil;
 
 /**
- * Created by sheetalm on 10/19/2016. Scenario 19 Pre-requisite - set -Dnode.config.location=${"user.home"}/TestResources/ while running test Verify
- * node specific override using CLI
+ * Created by sheetalm on 10/19/2016.
+ * Scenario 19
+ * Pre-requisite - set -Dnode.config.location=${"user.home"}/TestResources/ while running test
+ * Verify node specific override using CLI
  */
 @Disabled("Investigate instability (random failures)"
     + "[ERROR]   NodeSpecificCliTest.testCliApi:73 ยป FileNotFound /home/jenkins/TestResources/c...")
@@ -46,12 +49,9 @@ class NodeSpecificCliTest {
     private static final String NAMESPACE = "NodeCLI";
     private static final File FILE = new File(TestUtil.jsonSchemaLoc + "config.properties");
 
-    @AfterAll
-    public static void tearDown() throws Exception {
+    @BeforeEach
+    public void setUp() throws Exception {
         TestUtil.cleanUp();
-        if (FILE.exists()) {
-            assertTrue(FILE.delete());
-        }
     }
 
     @Test
@@ -87,4 +87,13 @@ class NodeSpecificCliTest {
             assertTrue(FILE.delete());
         }
     }
+
+    @AfterEach
+    public void tearDown() throws Exception {
+        TestUtil.cleanUp();
+        if (FILE.exists()) {
+            assertTrue(FILE.delete());
+        }
+    }
+
 }
index d53bf27..3d7533f 100644 (file)
 
 package org.onap.config.test;
 
-import static org.onap.config.util.TestUtil.writeFile;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.onap.config.api.Configuration;
 import org.onap.config.api.ConfigurationManager;
 import org.onap.config.util.ConfigTestConstant;
+import org.onap.config.util.TestUtil;
 
 /**
  * Created by ARR on 10/17/2016.
  * Scenario 22 - Validate the default mode if the mode is not set
  */
-public class ValidateDefaultModeTest {
+class ValidateDefaultModeTest {
 
     private static final String NAMESPACE = "defaultmode";
 
-    @Before
-    public void setUp() throws IOException {
-        String data = "{name:\"SCM\"}";
-        writeFile(data);
+    @BeforeEach
+    public void setUp() throws Exception {
+        TestUtil.cleanUp();
     }
 
     @Test
-    public void testConfigurationWithValidateDefaultMode() {
+    void testConfigurationWithValidateDefaultMode() {
         Configuration config = ConfigurationManager.lookup();
 
-        Assert.assertEquals(config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH), "14");
+        assertEquals("14", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
 
-        Assert.assertEquals(config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_MAXSIZE), "1048");
+        assertEquals("1048", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_MAXSIZE));
 
         List<String> expectedExtList = new ArrayList<>();
         expectedExtList.add("pdf");
         expectedExtList.add("tgz");
         expectedExtList.add("xls");
         List<String> extList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_EXT);
-        Assert.assertEquals(expectedExtList, extList);
+        assertEquals(expectedExtList, extList);
 
-        Assert.assertEquals(config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MINLENGTH), "6");
+        assertEquals("6", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MINLENGTH));
 
     }
 
-    @After
+    @AfterEach
     public void tearDown() throws Exception {
-        String data = "{name:\"SCM\"}";
-        writeFile(data);
+        TestUtil.cleanUp();
     }
 }
index 79a917d..32ac272 100644 (file)
 package org.onap.config.test;
 
 import static org.onap.config.util.TestUtil.validateConfiguration;
-import static org.onap.config.util.TestUtil.writeFile;
 
-import java.io.IOException;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.onap.config.util.TestUtil;
 
 /**
  * Created by ARR on 10/14/2016.
  * Scenario 2 - Validate configuration with XML file format with mode
  */
-public class XmlConfigTest {
+class XmlConfigTest {
 
     private static final String NAMESPACE = "XMLConfig";
 
-    @Before
-    public void setUp() throws IOException {
-        String data = "{name:\"SCM\"}";
-        writeFile(data);
+    @BeforeEach
+    public void setUp() throws Exception {
+        TestUtil.cleanUp();
     }
 
     @Test
-    public void testConfigurationWithXmlFileFormat() {
+    void testConfigurationWithXmlFileFormat() {
         validateConfiguration(NAMESPACE);
     }
 
 
-    @After
+    @AfterEach
     public void tearDown() throws Exception {
         TestUtil.cleanUp();
     }
index b2954f1..784e61b 100644 (file)
 package org.onap.config.test;
 
 import static org.onap.config.util.TestUtil.validateConfiguration;
-import static org.onap.config.util.TestUtil.writeFile;
 
-import java.io.IOException;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.onap.config.util.TestUtil;
 
 /**
  * Created by ARR on 10/14/2016.
  * Scenario 4 - Validate configuration with YAML file format with mode
  */
-public class YamlConfigTest {
+class YamlConfigTest {
 
     private static final String NAMESPACE = "YAMLConfig";
 
-    @Before
-    public void setUp() throws IOException {
-        String data = "{name:\"SCM\"}";
-        writeFile(data);
+    @BeforeEach
+    public void setUp() throws Exception {
+        TestUtil.cleanUp();
     }
 
     @Test
-    public void testConfigurationWithYamlFileFormat() {
+    void testConfigurationWithYamlFileFormat() {
         validateConfiguration(NAMESPACE);
     }
 
-    @After
+    @AfterEach
     public void tearDown() throws Exception {
         TestUtil.cleanUp();
     }
index 3f19cec..85da0d5 100644 (file)
@@ -19,8 +19,8 @@ package org.onap.config.util;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.nio.file.Files;
 import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.SimpleFileVisitor;
@@ -30,27 +30,33 @@ import java.util.List;
 import org.junit.Assert;
 import org.onap.config.api.Configuration;
 import org.onap.config.api.ConfigurationManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Created by sheetalm on 10/13/2016.
  */
 public class TestUtil {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(TestUtil.class);
+
     public static final String jsonSchemaLoc = System.getProperty("user.home") + "/TestResources/";
 
     public static void cleanUp() throws Exception {
-        String data = "{name:\"SCM\"}";
-        TestUtil.writeFile(data);
+        writeFile("{name:\"SCM\"}");
     }
 
-    public static void writeFile(String data) throws IOException {
-        File dir = new File(jsonSchemaLoc);
+    private static void writeFile(final String data) {
+        final File dir = new File(jsonSchemaLoc);
         dir.mkdirs();
-        File file = new File(jsonSchemaLoc + "/GeneratorsList.json");
-        file.createNewFile();
-        FileWriter fileWriter = new FileWriter(file);
-        fileWriter.write(data);
-        fileWriter.close();
+        final File file = new File(jsonSchemaLoc + "/GeneratorsList.json");
+        String canonicalPath = "";
+        try (final FileWriter fileWriter = new FileWriter(file)) {
+            canonicalPath = file.getCanonicalPath();
+            fileWriter.write(data);
+        } catch (final IOException e) {
+            LOGGER.warn("Failed to write file {}", canonicalPath, e);
+        }
     }
 
     public static void validateConfiguration(String nameSpace) {
@@ -88,14 +94,14 @@ public class TestUtil {
         Assert.assertEquals(expectedLocList, locList);
 
         Assert.assertEquals("@GeneratorList.json",
-                config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_JSON_SCHEMA));
+            config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_JSON_SCHEMA));
 
         Assert.assertEquals("@" + getenv(ConfigTestConstant.PATH) + "/myschema.json",
-                config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_XML_SCHEMA));
+            config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_XML_SCHEMA));
 
         List<String> artifactConsumer = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_CONSUMER);
         Assert.assertEquals(config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_CONSUMER_APPC),
-                artifactConsumer);
+            artifactConsumer);
 
         Assert.assertEquals("6", config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_MINLENGTH));
         Assert.assertEquals("true", config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_MANDATORY_NAME));
@@ -122,13 +128,13 @@ public class TestUtil {
         Path tmpPath = Files.createTempDirectory(tmpDirPrefix);
         Path dir0 = Paths.get(tmpPath.toString(), "dir0", "dir1", "dir2");
         Files.createDirectories(dir0);
-        Path[] files= {
-                Paths.get(tmpPath.toString(), "file001"),
-                Paths.get(tmpPath.toString(), "dir0", "file002"),
-                Paths.get(tmpPath.toString(), "dir0", "dir1", "file003"),
-                Paths.get(tmpPath.toString(), "dir0", "dir1", "dir2", "file004"),
+        Path[] files = {
+            Paths.get(tmpPath.toString(), "file001"),
+            Paths.get(tmpPath.toString(), "dir0", "file002"),
+            Paths.get(tmpPath.toString(), "dir0", "dir1", "file003"),
+            Paths.get(tmpPath.toString(), "dir0", "dir1", "dir2", "file004"),
         };
-        for (Path file : files ) {
+        for (Path file : files) {
             Files.createFile(file);
         }
         return tmpPath;