1 package org.onap.config.test;
3 import org.junit.After;
4 import org.junit.Assert;
5 import org.junit.Before;
7 import org.onap.config.api.Configuration;
8 import org.onap.config.api.ConfigurationManager;
9 import org.onap.config.api.DynamicConfiguration;
10 import org.onap.config.util.ConfigTestConstant;
11 import org.onap.config.util.TestUtil;
14 import java.io.FileOutputStream;
15 import java.io.IOException;
16 import java.io.OutputStream;
17 import java.util.Properties;
20 * Created by sheetalm on 10/17/2016.
21 * Pre-requisite - set -Dconfig.location=${"user.home"}/TestResources/ while running test
23 * Update the central configuration and fetch the Dynamic Configuration
25 public class DynamicConfigurationTest {
27 public final static String NAMESPACE = "DynamicConfiguration";
30 public void setUp() throws IOException {
31 String data = "{name:\"SCM\"}";
32 TestUtil.writeFile(data);
36 public void testDynamicConfig() throws IOException, InterruptedException {
37 Configuration config = ConfigurationManager.lookup();
38 Properties props = new Properties();
39 props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "20");
40 props.setProperty("_config.namespace",NAMESPACE);
41 props.setProperty("_config.mergeStrategy","override");
42 File f = new File(TestUtil.jsonSchemaLoc + "config.properties");
43 try (OutputStream out = new FileOutputStream(f)) {
44 props.store(out, "Override Config Property at Conventional Resource");
47 //Verify configuration with Configuration without wait. This should fetch cached value
48 Assert.assertEquals("14" , config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
52 DynamicConfiguration dynaConfig = config.getDynamicConfiguration(NAMESPACE,ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH,String.class,"14");
53 //Verify configuration with DynamicConfiguration This should fetch values from DB
54 Assert.assertEquals("20" , dynaConfig.get());
59 public void tearDown() throws Exception {
61 File f = new File(TestUtil.jsonSchemaLoc+"config.properties");