diff options
author | 2018-04-27 13:28:57 +0530 | |
---|---|---|
committer | 2018-04-30 06:05:27 +0000 | |
commit | 42c920baf4dbb9fe8775843a6d4c9f70fa29f064 (patch) | |
tree | ac2aff977e2b129e61d2166c4832842676e4f5c3 /common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config | |
parent | f487427a32f410ab5c97a4092865d32beb88ee27 (diff) |
Rename packages from openecomp to onap.
This task is all about package name space change also make changes to pom for common module
Change-Id: Ie9bda0f958a9a05826c0374830cc9cb7d6d196b6
Issue-ID: SDC-1272
Signed-off-by: amitjai <amitjai@amdocs.com>
Diffstat (limited to 'common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config')
24 files changed, 1560 insertions, 0 deletions
diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/TestCMSuite.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/TestCMSuite.java new file mode 100644 index 0000000000..de265c7281 --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/TestCMSuite.java @@ -0,0 +1,76 @@ +package org.onap.config; + +import org.onap.config.test.CLIFallbackAndLookupTest; +import org.onap.config.test.CLITest; +import org.onap.config.test.ConfigSourceLocationTest; +import org.onap.config.test.DynamicConfigurationTest; +import org.onap.config.test.FallbackConfigTest; +import org.onap.config.test.FallbackToGlobalNSTest; +import org.onap.config.test.GlobalAndNSConfigTest; +import org.onap.config.test.JAVAPropertiesConfigTest; +import org.onap.config.test.JSONConfigTest; +import org.onap.config.test.LoadOrderMergeAndOverrideTest; +import org.onap.config.test.ModeAsConfigPropTest; +import org.onap.config.test.MultiTenancyConfigTest; +import org.onap.config.test.NodeSpecificCLITest; +import org.onap.config.test.NotificationForNodeConfigTest; +import org.onap.config.test.NotificationOnPropValTest; +import org.onap.config.test.ResourceChangeNotificationTest; +import org.onap.config.test.UnregisterNotificationTest; +import org.onap.config.test.ValidateDefaultModeTest; +import org.onap.config.test.ValidateNodeConfigTest; +import org.onap.config.test.XMLConfigTest; +import org.onap.config.test.YAMLConfigTest; +import org.onap.config.test.*; +import org.junit.AfterClass; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * Created by sheetalm on 10/25/2016. + */ + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + JAVAPropertiesConfigTest.class, + JSONConfigTest.class, + XMLConfigTest.class, + YAMLConfigTest.class, + CLIFallbackAndLookupTest.class, + CLITest.class, + ConfigSourceLocationTest.class, + DynamicConfigurationTest.class, + FallbackConfigTest.class, + FallbackToGlobalNSTest.class, + GlobalAndNSConfigTest.class, + ModeAsConfigPropTest.class, + MultiTenancyConfigTest.class, + NodeSpecificCLITest.class, + NotificationForNodeConfigTest.class, + NotificationOnPropValTest.class, + ResourceChangeNotificationTest.class, + UnregisterNotificationTest.class, + ValidateDefaultModeTest.class, + ValidateNodeConfigTest.class, + LoadOrderMergeAndOverrideTest.class + + +}) + +public class TestCMSuite extends junit.framework.TestSuite { + + private TestCMSuite() { + + } + + @AfterClass + public static void tearDown(){ + try { + ConfigurationUtils.executeDdlSql("truncate dox.configuration_change"); + ConfigurationUtils.executeDdlSql("truncate dox.configuration"); + } + catch(Exception e){ + e.printStackTrace(); + } + } +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/CLIFallbackAndLookupTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/CLIFallbackAndLookupTest.java new file mode 100644 index 0000000000..f4598be0d0 --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/CLIFallbackAndLookupTest.java @@ -0,0 +1,83 @@ +package org.onap.config.test; + +import org.onap.config.util.ConfigTestConstant; +import org.onap.config.Constants; +import org.onap.config.api.ConfigurationManager; +import org.onap.config.util.TestUtil; +import org.junit.Assert; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import javax.management.JMX; +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.util.HashMap; +import java.util.Map; + + + +/** + * Created by sheetalm on 10/18/2016. + * Scenario 21, Scenario 23 + * 21 - Verify the CLI fetches only the current value unless the fallback option is specified + * 23 - Fetch value using CLI for a key with underlying resource + */ +public class CLIFallbackAndLookupTest { + + public final static String NAMESPACE = "CLIFallback"; + public final static String TENANT = "OPENECOMP"; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + TestUtil.writeFile(data); + } + + @Test + public void testCLIFallbackAndLookup() throws Exception{ + + //Verify without fallback + Map<String, Object> input = new HashMap<>(); + input.put("ImplClass", "org.openecomp.config.type.ConfigurationQuery"); + input.put("tenant", TENANT); + input.put("namespace", NAMESPACE); + input.put("key", ConfigTestConstant.ARTIFACT_MAXSIZE); + + MBeanServerConnection mbsc = ManagementFactory.getPlatformMBeanServer(); + ObjectName mbeanName = new ObjectName(Constants.MBEAN_NAME); + ConfigurationManager conf = JMX.newMBeanProxy(mbsc, mbeanName, ConfigurationManager.class, true); + String maxSizeWithNoFallback = conf.getConfigurationValue(input); + Assert.assertEquals("",maxSizeWithNoFallback); + + //Verify underlying resource without lookup switch + input.put("key", ConfigTestConstant.ARTIFACT_JSON_SCHEMA); + String jsonSchema = conf.getConfigurationValue(input); + System.out.println("jsonSchema=="+jsonSchema); + Assert.assertEquals("@"+System.getProperty("user.home")+"/TestResources/GeneratorsList.json" , jsonSchema); + + //Verify underlying resource with lookup switch + input.put("externalLookup", true); + jsonSchema = conf.getConfigurationValue(input); + System.out.println("jsonSchema=="+jsonSchema); + Assert.assertEquals("{name:\"SCM\"}" , jsonSchema); + + //Verify with fallback + Map<String, Object> fallbackInput = new HashMap<>(); + fallbackInput.put("ImplClass", "org.openecomp.config.type.ConfigurationQuery"); + fallbackInput.put("fallback", true); + fallbackInput.put("tenant", TENANT); + fallbackInput.put("namespace", NAMESPACE); + fallbackInput.put("key", ConfigTestConstant.ARTIFACT_MAXSIZE); + + String maxSizeWithFallback = conf.getConfigurationValue(fallbackInput); + Assert.assertEquals("1024",maxSizeWithFallback); + } + + @After + public void tearDown() throws Exception { + TestUtil.cleanUp(); + } +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/CLITest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/CLITest.java new file mode 100644 index 0000000000..5a3f39fd16 --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/CLITest.java @@ -0,0 +1,108 @@ +package org.onap.config.test; + +import org.onap.config.util.ConfigTestConstant; +import org.onap.config.Constants; +import org.onap.config.api.ConfigurationChangeListener; +import org.onap.config.api.ConfigurationManager; +import org.onap.config.util.TestUtil; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import javax.management.JMX; +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.util.HashMap; +import java.util.Map; + +/** + * Created by sheetalm on 10/18/2016. + * Scenario 17 + * Verify Configuration Management System - Command Line Interface for query, update and list operations + */ +public class CLITest { + + public final static String NAMESPACE = "CLI"; + public final static String TENANT = "OPENECOMP"; + private String updatedValue = ""; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + TestUtil.writeFile(data); + } + + @Test + public void testCLIApi() throws Exception{ + //Verify without fallback + Map<String, Object> input = new HashMap<>(); + input.put("ImplClass", "org.openecomp.config.type.ConfigurationQuery"); + input.put("tenant", TENANT); + input.put("namespace", NAMESPACE); + input.put("key", ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH); + + MBeanServerConnection mbsc = ManagementFactory.getPlatformMBeanServer(); + ObjectName mbeanName = new ObjectName(Constants.MBEAN_NAME); + ConfigurationManager conf = JMX.newMBeanProxy(mbsc, mbeanName, ConfigurationManager.class, true); + String maxLength = conf.getConfigurationValue(input); + Assert.assertEquals("14",maxLength); + + conf.addConfigurationChangeListener(TENANT,NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, new CLIListener()); + + + //Update maxlength + input.put("ImplClass", "org.openecomp.config.type.ConfigurationUpdate"); + input.put("value", "24"); + conf.updateConfigurationValue(input); + + Thread.sleep(35000); + + Assert.assertEquals("24",updatedValue); + + //Reset value and fetch updated value again + input.put("value", ""); + input.put("ImplClass", "org.openecomp.config.type.ConfigurationQuery"); + String updatedMaxLength = conf.getConfigurationValue(input); + Assert.assertEquals("24",updatedMaxLength); + + Map<String, String> outputMap = conf.listConfiguration(input); + for(Map.Entry<String, String> entry : outputMap.entrySet()){ + System.out.println(entry.getKey()+" : "+entry.getValue()); + validateCLIListConfig(outputMap); + } + } + + private class CLIListener implements ConfigurationChangeListener { + @Override + public void notify(String key, Object oldValue, Object newValue) { + System.out.println("received notification::oldValue=="+oldValue+" newValue=="+newValue); + updatedValue = newValue.toString(); + } + } + + 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("24", 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("@"+System.getenv("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)); + } + + @After + public void tearDown() throws Exception { + TestUtil.cleanUp(); + } +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/ConfigSourceLocationTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/ConfigSourceLocationTest.java new file mode 100644 index 0000000000..6751a5cc31 --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/ConfigSourceLocationTest.java @@ -0,0 +1,53 @@ +package org.onap.config.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; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.Assert; + +import java.io.File; +import java.io.IOException; +import java.util.Properties; +import java.io.OutputStream; +import java.io.FileOutputStream; + +/** + * Created by sheetalm on 10/14/2016. + * Scenario 11 + * Validate conventional and configurational source location + * + * Pre-requisite - set -Dconfig.location=${"user.home"}/TestResources/ while running test + */ +public class ConfigSourceLocationTest { + public final static String NAMESPACE = "SourceLocation"; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + TestUtil.writeFile(data); + + Properties props = new Properties(); + props.setProperty("maxCachedBufferSize", "1024"); + props.setProperty("artifact.maxsize", "1024"); + File f = new File(TestUtil.jsonSchemaLoc + "config.properties"); + try (OutputStream out = new FileOutputStream(f)) { + props.store(out, "Config Property at Conventional Resource"); + } + } + + @Test + public void testMergeStrategyInConfig() throws IOException, InterruptedException { + 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)); + } + + @After + public void tearDown() throws Exception { + TestUtil.cleanUp(); + } +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/DynamicConfigurationTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/DynamicConfigurationTest.java new file mode 100644 index 0000000000..86422d2361 --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/DynamicConfigurationTest.java @@ -0,0 +1,66 @@ +package org.onap.config.test; + +import org.onap.config.api.Configuration; +import org.onap.config.api.ConfigurationManager; +import org.onap.config.api.DynamicConfiguration; +import org.onap.config.util.ConfigTestConstant; +import org.onap.config.util.TestUtil; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Properties; + +/** + * Created by sheetalm on 10/17/2016. + * Pre-requisite - set -Dconfig.location=${"user.home"}/TestResources/ while running test + * Scenario 20 + * Update the central configuration and fetch the Dynamic Configuration + */ +public class DynamicConfigurationTest { + + public final static String NAMESPACE = "DynamicConfiguration"; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + TestUtil.writeFile(data); + } + + @Test + public void testDynamicConfig() throws IOException, InterruptedException { + Configuration config = ConfigurationManager.lookup(); + Properties props = new Properties(); + props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "20"); + props.setProperty("_config.namespace",NAMESPACE); + props.setProperty("_config.mergeStrategy","override"); + File f = new File(TestUtil.jsonSchemaLoc + "config.properties"); + try (OutputStream out = new FileOutputStream(f)) { + props.store(out, "Override Config Property at Conventional Resource"); + } + + //Verify configuration with Configuration without wait. This should fetch cached value + Assert.assertEquals("14" , config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH)); + + Thread.sleep(10000); + + DynamicConfiguration dynaConfig = config.getDynamicConfiguration(NAMESPACE,ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH,String.class,"14"); + //Verify configuration with DynamicConfiguration This should fetch values from DB + Assert.assertEquals("20" , dynaConfig.get()); + + } + + @After + public void tearDown() throws Exception { + TestUtil.cleanUp(); + File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); + if(f.exists()) { + f.delete(); + } + } +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/FallbackConfigTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/FallbackConfigTest.java new file mode 100644 index 0000000000..17b4aee8b0 --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/FallbackConfigTest.java @@ -0,0 +1,38 @@ +package org.onap.config.test; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; + +import static org.onap.config.util.TestUtil.validateConfiguraton; +import static org.onap.config.util.TestUtil.writeFile; + +/** + * Created by ARR on 10/14/2016. + * + * Validate configuration with properties,xml,json,yaml file format with mode + */ +public class FallbackConfigTest { + + public static final String NAMESPACE = "fallback"; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + writeFile(data); + } + + @Test + public void testConfigurationWithFallbackFileFormat(){ + validateConfiguraton(NAMESPACE); + } + + @After + public void tearDown() throws Exception { + String data = "{name:\"SCM\"}"; + writeFile(data); + //ConfigurationUtils.executeDDLSQL("truncate dox.configuration"); + } +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/FallbackToGlobalNSTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/FallbackToGlobalNSTest.java new file mode 100644 index 0000000000..14d74fb040 --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/FallbackToGlobalNSTest.java @@ -0,0 +1,42 @@ +package org.onap.config.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; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.Assert; + +import java.io.IOException; + +/** + * Scenario 12 + * Verify configuration value fallback to the global namespace if the configuraton property doesnot exist in the namespace configuration + * Created by sheetalm on 10/14/2016. + */ +public class FallbackToGlobalNSTest { + + public final static String NAMESPACE = "FallbackToGlobalNS"; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + TestUtil.writeFile(data); + } + + @Test + public void testFallbackToGlobalNS() throws IOException, InterruptedException { + Configuration config = ConfigurationManager.lookup(); + Assert.assertEquals("14",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH)); + Assert.assertEquals("1024",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_MAXSIZE)); + } + + @After + public void tearDown() throws Exception { + TestUtil.cleanUp(); + } + + +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/GlobalAndNSConfigTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/GlobalAndNSConfigTest.java new file mode 100644 index 0000000000..a0bb51a73f --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/GlobalAndNSConfigTest.java @@ -0,0 +1,43 @@ +package org.onap.config.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; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; + +/** + * Created by sheetalm on 10/13/2016. + * Scenario 10 Verify configuration present in both global and defined namespace + */ +public class GlobalAndNSConfigTest { + + public final static String NAMESPACE = "GlobalAndNSConfig"; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + TestUtil.writeFile(data); + } + + @Test + public void testNamespaceInConfig() throws IOException, InterruptedException { + 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 )); + } + + @After + public void tearDown() throws Exception { + TestUtil.cleanUp(); + } + + + + +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/JAVAPropertiesConfigTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/JAVAPropertiesConfigTest.java new file mode 100644 index 0000000000..ab47765a1c --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/JAVAPropertiesConfigTest.java @@ -0,0 +1,40 @@ +package org.onap.config.test; + +import org.onap.config.util.TestUtil; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; + +import static org.onap.config.util.TestUtil.validateConfiguraton; +import static org.onap.config.util.TestUtil.writeFile; + +/** + * Created by ARR on 10/13/2016. + * + * Scenario 1 + * Validate configuration with Java Properties file format with mode + */ +public class JAVAPropertiesConfigTest { + + public static final String NAMESPACE = "javaProperties"; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + writeFile(data); + } + + @Test + public void testConfigurationWithPropertiesFileFormat(){ + validateConfiguraton(NAMESPACE); + } + + + + @After + public void tearDown() throws Exception { + TestUtil.cleanUp(); + } +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/JSONConfigTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/JSONConfigTest.java new file mode 100644 index 0000000000..b3fcb730fb --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/JSONConfigTest.java @@ -0,0 +1,40 @@ +package org.onap.config.test; + +import org.onap.config.util.TestUtil; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; + +import static org.onap.config.util.TestUtil.validateConfiguraton; +import static org.onap.config.util.TestUtil.writeFile; + +/** + * Created by ARR on 10/14/2016. + * + * Scenario 3 + * Validate configuration with JSON file format with mode + */ +public class JSONConfigTest { + + public static final String NAMESPACE = "JSONConfig"; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + writeFile(data); + } + + @Test + public void testConfigurationWithJSONFileFormat(){ + validateConfiguraton(NAMESPACE); + } + + + + @After + public void tearDown() throws Exception { + TestUtil.cleanUp(); + } +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/LoadOrderMergeAndOverrideTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/LoadOrderMergeAndOverrideTest.java new file mode 100644 index 0000000000..244511cbf0 --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/LoadOrderMergeAndOverrideTest.java @@ -0,0 +1,46 @@ +package org.onap.config.test; + +import static org.onap.config.util.TestUtil.writeFile; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.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; + +import java.io.IOException; + +/** + * Scenario + * Check loadorder for merge and overide. Higher loadorder takes precedence for override + * LoWer loadorder takes precedence for merge. + */ +public class LoadOrderMergeAndOverrideTest { + + public static final String NAMESPACE = "LoadOrderConfiguration"; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + writeFile(data); + } + + @Test + public 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")); + } + + + + @After + public void tearDown() throws Exception { + TestUtil.cleanUp(); + } +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/ModeAsConfigPropTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/ModeAsConfigPropTest.java new file mode 100644 index 0000000000..17130d37c1 --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/ModeAsConfigPropTest.java @@ -0,0 +1,87 @@ +package org.onap.config.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; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * Scenario 8 + * Validate configuration with mode specified as a configuration property + */ + +public class ModeAsConfigPropTest { + + String newValue = null; + + public final static String NAMESPACE = "ModeAsConfigProp"; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + TestUtil.writeFile(data); + } + + @Test + public void testMergeStrategyInConfig() throws IOException, InterruptedException { + Configuration config = ConfigurationManager.lookup(); + + Assert.assertEquals("14",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH)); + + Assert.assertEquals("1048",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_MAXSIZE)); + + List<String> expectedExtList = new ArrayList<String>(); + expectedExtList.add("pdf"); + expectedExtList.add("zip"); + expectedExtList.add("xml"); + expectedExtList.add("pdf"); + expectedExtList.add("tgz"); + expectedExtList.add("xls"); + List<String> extList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_EXT); + Assert.assertEquals(expectedExtList, extList); + + List<String> expectedEncList = new ArrayList<String>(); + expectedEncList.add("Base64"); + expectedEncList.add("MD5"); + List<String> encList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_ENC); + Assert.assertEquals(expectedEncList, encList); + + String newValue = config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_JSON_SCHEMA); + Assert.assertEquals("{name:\"SCM\"}",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_JSON_SCHEMA)); + + Assert.assertEquals("a-zA-Z_0-9",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_UPPER )); + + Assert.assertEquals("Deleted",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_STATUS) ); + + List<String> expectedLocList = new ArrayList<String>(); + expectedLocList.add("/opt/spool"); + expectedLocList.add(System.getProperty("user.home")+"/asdc"); + List<String> locList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_LOC); + Assert.assertEquals(expectedLocList, locList); + + Assert.assertEquals("@"+System.getenv("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); + + Assert.assertEquals(config.getAsBooleanValue(NAMESPACE, ConfigTestConstant.ARTIFACT_MANDATORY_NAME ), true); + + Assert.assertEquals(config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MINLENGTH ), "6"); + + Assert.assertEquals(config.getAsBooleanValue(NAMESPACE, ConfigTestConstant.ARTIFACT_ENCODED ), true); + } + + @After + public void tearDown() throws Exception { + TestUtil.cleanUp(); + } + +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/MultiTenancyConfigTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/MultiTenancyConfigTest.java new file mode 100644 index 0000000000..8cdd634794 --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/MultiTenancyConfigTest.java @@ -0,0 +1,46 @@ +package org.onap.config.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; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; + +/** + * Created by ARR on 10/14/2016. + * + * Scenario 17 + * Verify Configuration management System - Support for Multi-Tenancy + */ +public class MultiTenancyConfigTest { + + public static final String NAMESPACE = "tenancy"; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + TestUtil.writeFile(data); + } + + @Test + public 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"); + + } + + @After + public void tearDown() throws Exception { + TestUtil.cleanUp(); + } +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/NodeSpecificCLITest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/NodeSpecificCLITest.java new file mode 100644 index 0000000000..59848f1dba --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/NodeSpecificCLITest.java @@ -0,0 +1,117 @@ +package org.onap.config.test; + +import org.onap.config.util.ConfigTestConstant; +import org.onap.config.Constants; +import org.onap.config.api.ConfigurationChangeListener; +import org.onap.config.api.ConfigurationManager; +import org.onap.config.util.TestUtil; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Test; + +import javax.management.JMX; +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.lang.management.ManagementFactory; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +/** + * 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 + */ +public class NodeSpecificCLITest { + + public final static String NAMESPACE = "NodeCLI"; + private String updatedValue = ""; + + @Test + public void testCLIApi() throws Exception{ + //Verify without fallback + Map<String, Object> input = new HashMap<>(); + input.put("ImplClass", "org.openecomp.config.type.ConfigurationQuery"); + input.put("namespace", NAMESPACE); + input.put("key", ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH); + + MBeanServerConnection mbsc = ManagementFactory.getPlatformMBeanServer(); + ObjectName mbeanName = new ObjectName(Constants.MBEAN_NAME); + ConfigurationManager conf = JMX.newMBeanProxy(mbsc, mbeanName, ConfigurationManager.class, true); + String maxLength = conf.getConfigurationValue(input); + + //Verify Property from Namespace configurations + Assert.assertEquals("30",maxLength); + + //Add node specific configurations + Properties props = new Properties(); + props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "50"); + props.setProperty("_config.namespace",NAMESPACE); + File f = new File(TestUtil.jsonSchemaLoc + "config.properties"); + try (OutputStream out = new FileOutputStream(f)) { + props.store(out, "Node Config Property"); + } + + Thread.sleep(35000); + + //Verify property from node specific configuration + input.put("nodeSpecific", true); + String nodeVal = conf.getConfigurationValue(input); + Assert.assertEquals("50", nodeVal); + + //Add Change Listener + conf.addConfigurationChangeListener(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, new CLINodeListener()); + + //Update maxlength + input.put("ImplClass", "org.openecomp.config.type.ConfigurationUpdate"); + input.put("nodeOverride", true); + input.put("nodeSpecific", false); + input.put("value", "60"); + conf.updateConfigurationValue(input); + + Thread.sleep(35000); + + Assert.assertEquals("60",updatedValue); + + //Fetch the updated nodespecific value + input.put("nodeOverride", false); + input.put("nodeSpecific", true); + input.put("ImplClass", "org.openecomp.config.type.ConfigurationQuery"); + String updatedMaxLength = conf.getConfigurationValue(input); + Assert.assertEquals("60",updatedMaxLength); + + //Verify maxlength on other nodes by deleting node specific configuration + if(f.exists()) { + f.delete(); + } + + Thread.sleep(35000); + + input.put("ImplClass", "org.openecomp.config.type.ConfigurationQuery"); + input.put("nodeOverride", false); + input.put("nodeSpecific", false); + System.out.println("val on other node is::"+conf.getConfigurationValue(input)); + Assert.assertEquals("30",conf.getConfigurationValue(input)); + } + + @AfterClass + public static void tearDown() throws Exception { + TestUtil.cleanUp(); + File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); + if(f.exists()) { + f.delete(); + } + } + + private class CLINodeListener implements ConfigurationChangeListener { + @Override + public void notify(String key, Object oldValue, Object newValue) { + System.out.println("received notification::oldValue=="+oldValue+" newValue=="+newValue); + updatedValue = newValue.toString(); + } + } +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/NotificationForNodeConfigTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/NotificationForNodeConfigTest.java new file mode 100644 index 0000000000..55af6900a6 --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/NotificationForNodeConfigTest.java @@ -0,0 +1,85 @@ +package org.onap.config.test; + +import org.onap.config.api.Configuration; +import org.onap.config.api.ConfigurationChangeListener; +import org.onap.config.api.ConfigurationManager; +import org.onap.config.util.ConfigTestConstant; +import org.onap.config.util.TestUtil; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Properties; + +/** + * Scenario 15 + * Update and Verify Change Notifications for any change in the registered key for node specific configuration + * Pre-requisite - set -Dnode.config.location=${"user.home"}/TestResources/ while running test + * Created by sheetalm on 10/17/2016. + */ +public class NotificationForNodeConfigTest { + public final static String NAMESPACE = "NotificationForNodeConfig"; + + private String updatedValue = null; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + TestUtil.writeFile(data); + } + + @Test + public void testNotificationForNode() throws IOException, InterruptedException { + Configuration config = ConfigurationManager.lookup(); + + System.out.println(config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH)); + + Properties props = new Properties(); + props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "30"); + props.setProperty("_config.namespace",NAMESPACE); + File f = new File(TestUtil.jsonSchemaLoc + "config.properties"); + try (OutputStream out = new FileOutputStream(f)) { + props.store(out, "Node Config Property"); + } + + Thread.sleep(35000); + + //Verify property from node specific configuration + Assert.assertEquals("30", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH)); + + config.addConfigurationChangeListener(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, new NodePropValListener()); + + props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "80"); + try (OutputStream out = new FileOutputStream(f)) { + props.store(out, "Updated Node Config Property"); + } + + Thread.sleep(35000); + + //Verify change listenere is invoked when node specific configuration is changed. + Assert.assertEquals("80", updatedValue); + + } + + private class NodePropValListener implements ConfigurationChangeListener { + @Override + public void notify(String key, Object oldValue, Object newValue) { + System.out.println("received notification::oldValue=="+oldValue+" newValue=="+newValue); + updatedValue = newValue.toString(); + } + } + + @After + public void tearDown() throws Exception { + TestUtil.cleanUp(); + File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); + if(f.exists()) { + f.delete(); + } + } +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/NotificationOnPropValTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/NotificationOnPropValTest.java new file mode 100644 index 0000000000..c7b93b019a --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/NotificationOnPropValTest.java @@ -0,0 +1,76 @@ +package org.onap.config.test; + +import org.onap.config.api.Configuration; +import org.onap.config.api.ConfigurationChangeListener; +import org.onap.config.api.ConfigurationManager; +import org.onap.config.util.ConfigTestConstant; +import org.onap.config.util.TestUtil; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.Assert; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Properties; + +/** + * Pre-requisite - set -Dconfig.location=${"user.home"}/TestResources/ while running test + * Scenario 14 - Verify Change Notifications for any change in the registered key + * Created by sheetalm on 10/14/2016. + */ +public class NotificationOnPropValTest { + + public final static String NAMESPACE = "NotificationOnPropVal"; + + private String updatedValue = null; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + TestUtil.writeFile(data); + } + + @Test + public void testNotification() throws IOException, InterruptedException { + Configuration config = ConfigurationManager.lookup(); + + System.out.println(config.getAsString(NAMESPACE,ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH)); + + config.addConfigurationChangeListener(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, new PropValListener()); + + Properties props = new Properties(); + props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "20"); + props.setProperty("_config.namespace",NAMESPACE); + props.setProperty("_config.mergeStrategy","override"); + File f = new File(TestUtil.jsonSchemaLoc + "config.properties"); + try (OutputStream out = new FileOutputStream(f)) { + props.store(out, "Override Config Property at Conventional Resource"); + } + + Thread.sleep(35000); + + System.out.println(config.getAsString(NAMESPACE,ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH)); + + Assert.assertEquals("20" , updatedValue); + } + + private class PropValListener implements ConfigurationChangeListener { + @Override + public void notify(String key, Object oldValue, Object newValue) { + System.out.println("received notification::oldValue=="+oldValue+" newValue=="+newValue); + updatedValue = newValue.toString(); + } + } + + @After + public void tearDown() throws Exception { + TestUtil.cleanUp(); + File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); + if(f.exists()) { + f.delete(); + } + } +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/ResourceChangeNotificationTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/ResourceChangeNotificationTest.java new file mode 100644 index 0000000000..54bd339f29 --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/ResourceChangeNotificationTest.java @@ -0,0 +1,88 @@ +package org.onap.config.test; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.onap.config.util.ConfigTestConstant; + +import org.onap.config.util.TestUtil; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import org.onap.config.api.Configuration; +import org.onap.config.api.ConfigurationChangeListener; +import org.onap.config.api.ConfigurationManager; + +/** + * Scenario 7 + * Test to Validate notification on changes to the underlying source + * Resource here is GeneratorsList.json ehich is created in test itself + */ + +public class ResourceChangeNotificationTest { + + String newValue = null; + + public final static String NAMESPACE = "Notification"; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + TestUtil.writeFile(data); + } + + @Test + public void testNotification() throws IOException, InterruptedException { + Configuration config = ConfigurationManager.lookup(); + config.addConfigurationChangeListener(NAMESPACE,ConfigTestConstant.ARTIFACT_JSON_SCHEMA, new MyListener()); + updateJsonInFile(); + Thread.sleep(35000); + String newValue = config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_JSON_SCHEMA); + + Assert.assertEquals("{name:\"updated SCM\"}",newValue); + + Assert.assertEquals( "14",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH )); + + Assert.assertEquals( "a-zA-Z", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_UPPER )); + + String artifactConsumer = config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_CONSUMER ); + Assert.assertEquals(artifactConsumer,config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_CONSUMER_APPC )); + + List<String> expectedExtList = new ArrayList<String>(); + expectedExtList.add("pdf"); expectedExtList.add("zip"); expectedExtList.add("xml"); + List<String> extList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_EXT); + Assert.assertEquals(expectedExtList, extList); + + List<String> expectedEncList = new ArrayList<String>(); + expectedEncList.add("Base64"); expectedEncList.add("MD5"); + List<String> encList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_ENC); + Assert.assertEquals(expectedEncList, encList); + + List<String> expectedLocList = new ArrayList<String>(); + expectedLocList.add("/opt/spool"); expectedLocList.add(System.getProperty("user.home")+"/asdc"); + List<String> locList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_LOC); + Assert.assertEquals(expectedLocList, locList); + + Assert.assertEquals("@"+System.getenv("Path")+"/myschema.json",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_XML_SCHEMA)); + } + + class MyListener implements ConfigurationChangeListener{ + @Override + public void notify(String key, Object oldValue, Object newValue) { + System.out.println("received notification::oldValue=="+oldValue+" newValue=="+newValue); + } + } + + private void updateJsonInFile() throws IOException{ + String data = "{name:\"updated SCM\"}"; + TestUtil.writeFile(data); + } + + @After + public void tearDown() throws Exception { + TestUtil.cleanUp(); + } +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/UnregisterNotificationTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/UnregisterNotificationTest.java new file mode 100644 index 0000000000..cdfcfdf22d --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/UnregisterNotificationTest.java @@ -0,0 +1,94 @@ +package org.onap.config.test; + +import org.onap.config.api.Configuration; +import org.onap.config.api.ConfigurationChangeListener; +import org.onap.config.api.ConfigurationManager; +import org.onap.config.util.ConfigTestConstant; +import org.onap.config.util.TestUtil; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Properties; + +/** + * Pre-requisite - set -Dconfig.location=${"user.home"}/TestResources/ while running test + * Created by sheetalm on 10/19/2016. + * Scenario 24 + * Unregister notification and verify listener + */ +public class UnregisterNotificationTest { + public final static String NAMESPACE = "UnregisterNotification"; + + private String updatedValue = null; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + TestUtil.writeFile(data); + } + + @Test + public void testNotification() throws IOException, InterruptedException { + Configuration config = ConfigurationManager.lookup(); + + System.out.println(config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH)); + + PropertyListener propListener = new PropertyListener(); + config.addConfigurationChangeListener(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH,propListener); + + updateValue("20"); + + Thread.sleep(35000); + + System.out.println(config.getAsString(NAMESPACE,ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH)); + + //Verify listener is invoked and updated value to 20 + Assert.assertEquals("20" , updatedValue); + + config.removeConfigurationChangeListener(NAMESPACE,ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH,propListener); + + updateValue("22"); + + Thread.sleep(35000); + + //When listener is unregistered updating value does not invoke any listener and value from listener should remain unchanged + Assert.assertEquals("20" , updatedValue); + + //Verify value is updated even if listener is unregistered + Assert.assertEquals("22" , config.getAsString(NAMESPACE,ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH)); + } + + private void updateValue(String newValue) throws IOException { + Properties props = new Properties(); + props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, newValue); + props.setProperty("_config.namespace",NAMESPACE); + props.setProperty("_config.mergeStrategy","override"); + File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); + try (OutputStream out = new FileOutputStream(f)) { + props.store(out, "Override Config Property at Conventional Resource"); + } + } + + private class PropertyListener implements ConfigurationChangeListener { + @Override + public void notify(String key, Object oldValue, Object newValue) { + System.out.println("received notification::oldValue=="+oldValue+" newValue=="+newValue); + updatedValue = newValue.toString(); + } + } + + @After + public void tearDown() throws Exception { + TestUtil.cleanUp(); + File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); + if(f.exists()) { + f.delete(); + } + } +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/ValidateDefaultModeTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/ValidateDefaultModeTest.java new file mode 100644 index 0000000000..f9ce9a37ed --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/ValidateDefaultModeTest.java @@ -0,0 +1,58 @@ +package org.onap.config.test; + +import org.onap.config.api.Configuration; +import org.onap.config.api.ConfigurationManager; +import org.onap.config.util.ConfigTestConstant; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static org.onap.config.util.TestUtil.writeFile; + +/** + * Created by ARR on 10/17/2016. + * + * Scenario 22 + * Validate the default mode if the mode is not set + */ +public class ValidateDefaultModeTest { + + public static final String NAMESPACE = "defaultmode"; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + writeFile(data); + } + + @Test + public void testConfigurationWithValidateDefaultMode(){ + Configuration config = ConfigurationManager.lookup(); + + Assert.assertEquals(config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH ), "14"); + + Assert.assertEquals(config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_MAXSIZE ), "1048"); + + List<String> expectedExtList = new ArrayList<String>(); + expectedExtList.add("pdf"); + expectedExtList.add("tgz"); + expectedExtList.add("xls"); + List<String> extList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_EXT); + Assert.assertEquals(expectedExtList, extList); + + Assert.assertEquals(config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MINLENGTH ), "6"); + + } + + @After + public void tearDown() throws Exception { + String data = "{name:\"SCM\"}"; + writeFile(data); + // ConfigurationUtils.executeDDLSQL("truncate dox.configuration"); + } +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/ValidateNodeConfigTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/ValidateNodeConfigTest.java new file mode 100644 index 0000000000..e4f3a84b05 --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/ValidateNodeConfigTest.java @@ -0,0 +1,80 @@ +package org.onap.config.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; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.Assert; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Properties; + +/** + * Scenario 13 + * Validate node specific configuration + * Pre-requisite - set -Dnode.config.location=${"user.home"}/TestResources/ while running test + * + * Created by sheetalm on 10/14/2016. + */ +public class ValidateNodeConfigTest { + + public final static String NAMESPACE = "ValidateNodeConfig"; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + TestUtil.writeFile(data); + } + + @Test + public void testValidateNodeConfig() throws IOException, InterruptedException { + Configuration config = ConfigurationManager.lookup(); + + Properties props = new Properties(); + props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "56"); + props.setProperty("_config.namespace","ValidateNodeConfig"); + File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); + try (OutputStream out = new FileOutputStream(f)) { + props.store(out, "Node Config Property"); + } + + System.out.println(System.getProperty("node.config.location")); + + Thread.sleep(35000); + + //Verify property from node specific configuration + Assert.assertEquals("56", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH)); + + //Verify if property is not in node specific then fetch from namespace + //Assert.assertEquals("a-zA-Z",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_UPPER)); + + //Verify if property is not in node specific and namespace then fetch from global + Assert.assertEquals("1024", config.getAsString(NAMESPACE, "maxCachedBufferSize")); + + //Deleting node configurations to test property is fetched from namespace configuration when node configuration is not present + if(f.exists()) { + boolean isDeleted = f.delete(); + System.out.println(isDeleted); + } + + Thread.sleep(35000); + + Assert.assertEquals(config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH), "14"); + } + + @After + public void tearDown() throws Exception { + TestUtil.cleanUp(); + File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); + if(f.exists()) { + f.delete(); + } + } + +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/XMLConfigTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/XMLConfigTest.java new file mode 100644 index 0000000000..ae6fc3e7b1 --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/XMLConfigTest.java @@ -0,0 +1,40 @@ +package org.onap.config.test; + +import org.onap.config.util.TestUtil; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; + +import static org.onap.config.util.TestUtil.validateConfiguraton; +import static org.onap.config.util.TestUtil.writeFile; + +/** + * Created by ARR on 10/14/2016. + * + * Scenario 2 + * Validate configuration with XML file format with mode + */ +public class XMLConfigTest { + + public static final String NAMESPACE = "XMLConfig"; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + writeFile(data); + } + + @Test + public void testConfigurationWithXMLFileFormat(){ + validateConfiguraton(NAMESPACE); + } + + + + @After + public void tearDown() throws Exception { + TestUtil.cleanUp(); + } +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/YAMLConfigTest.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/YAMLConfigTest.java new file mode 100644 index 0000000000..46240402f4 --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/test/YAMLConfigTest.java @@ -0,0 +1,40 @@ +package org.onap.config.test; + +import org.onap.config.util.TestUtil; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; + +import static org.onap.config.util.TestUtil.validateConfiguraton; +import static org.onap.config.util.TestUtil.writeFile; + +/** + * Created by ARR on 10/14/2016. + * + * Scenario 4 + * Validate configuration with YAML file format with mode + */ +public class YAMLConfigTest { + + public static final String NAMESPACE = "YAMLConfig"; + + @Before + public void setUp() throws IOException { + String data = "{name:\"SCM\"}"; + writeFile(data); + } + + @Test + public void testConfigurationWithYAMLFileFormat(){ + validateConfiguraton(NAMESPACE); + } + + + + @After + public void tearDown() throws Exception { + TestUtil.cleanUp(); + } +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/util/ConfigTestConstant.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/util/ConfigTestConstant.java new file mode 100644 index 0000000000..1d4dead7d2 --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/util/ConfigTestConstant.java @@ -0,0 +1,23 @@ +package org.onap.config.util; + +public class ConfigTestConstant { + + public static final String ARTIFACT_NAME_MAXLENGTH = "artifact.name.maxlength"; + public static final String ARTIFACT_MAXSIZE = "artifact.maxsize"; + public static final String ARTIFACT_EXT = "artifact.extension"; + public static final String ARTIFACT_ENC = "artifact.supportedEncryption"; + public static final String ARTIFACT_NAME_UPPER = "artifact.name.allowedChar"; + public static final String ARTIFACT_NAME_LOWER = "artifact.name.allowedchar"; + public static final String ARTIFACT_STATUS = "artifact.status"; + public static final String ARTIFACT_LOC = "artifact.persistLocation"; + public static final String ARTIFACT_JSON_SCHEMA = "artifact.jsonSchema"; + public static final String ARTIFACT_XML_SCHEMA = "artifact.xmlSchema"; + public static final String ARTIFACT_CONSUMER_APPC = "artifact.consumerAPPC"; + public static final String ARTIFACT_CONSUMER = "artifact.consumer"; + public static final String ARTIFACT_MANDATORY_NAME = "artifact.mandatory.name"; + public static final String ARTIFACT_NAME_MINLENGTH = "artifact.name.minlength"; + public static final String ARTIFACT_ENCODED = "artifact.encoded"; + + public static final String ONBOARDING_NAMESPACE = "onboarding"; + +} diff --git a/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/util/TestUtil.java b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/util/TestUtil.java new file mode 100644 index 0000000000..83f0371c33 --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-test/src/test/java/org/onap/config/util/TestUtil.java @@ -0,0 +1,91 @@ +package org.onap.config.util; + +import org.onap.config.ConfigurationUtils; +import org.onap.config.api.Configuration; +import org.onap.config.api.ConfigurationManager; +import org.junit.Assert; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by sheetalm on 10/13/2016. + */ +public class TestUtil { + + public final static String jsonSchemaLoc = System.getProperty("user.home")+"/TestResources/"; + public static FileWriter fileWriter ; + + public static void writeFile(String data) throws IOException { + File dir = new File(jsonSchemaLoc); + File file = null; + dir.mkdirs(); + file = new File(jsonSchemaLoc+"/GeneratorsList.json"); + file.createNewFile(); + fileWriter = new FileWriter(file); + fileWriter.write(data); + fileWriter.close(); + } + + public static void cleanUp() throws Exception { + String data = "{name:\"SCM\"}"; + TestUtil.writeFile(data); + //ConfigurationUtils.executeDdlSql("truncate dox.configuration"); + try{ + ConfigurationUtils.executeDdlSql("truncate dox.configuration_change"); + } + catch(Exception e){ + e.printStackTrace(); + } + + } + + public static void validateConfiguraton(String nameSpace) { + Configuration config = ConfigurationManager.lookup(); + + Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH ), "14"); + + // First value from list is picked from Merge properties + Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_MAXSIZE ), "1048576"); + + List<String> expectedExtList = new ArrayList<String>(); + expectedExtList.add("pdf"); + expectedExtList.add("zip"); + expectedExtList.add("xml"); + expectedExtList.add("pdf"); + expectedExtList.add("tgz"); + expectedExtList.add("xls"); + List<String> extList = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_EXT); + Assert.assertEquals(expectedExtList, extList); + + List<String> expectedEncList = new ArrayList<String>(); + expectedEncList.add("Base64"); + expectedEncList.add("MD5"); + List<String> encList = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_ENC); + Assert.assertEquals(expectedEncList, encList); + + Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_UPPER ), "a-zA-Z_0-9"); + Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_LOWER ), "a-zA-Z"); + Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_STATUS ), "deleted"); + + List<String> expectedLocList = new ArrayList<String>(); + expectedLocList.add("/opt/spool"); + expectedLocList.add(System.getProperty("user.home")+"/asdc"); + List<String> locList = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_LOC); + Assert.assertEquals(expectedLocList, locList); + + Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_JSON_SCHEMA ), "@GeneratorList.json"); + + Assert.assertEquals("@"+System.getenv("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); + + Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_MINLENGTH ), "6"); + Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_MANDATORY_NAME ), "true"); + Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_ENCODED ), "true"); + } +} |