ActivitySpec - Correcting logger messages
[sdc.git] / common / onap-common-configuration-management / onap-configuration-management-test / src / test / java / org / onap / config / test / DynamicConfigurationTest.java
1 package org.onap.config.test;
2
3 import org.onap.config.api.Configuration;
4 import org.onap.config.api.ConfigurationManager;
5 import org.onap.config.api.DynamicConfiguration;
6 import org.onap.config.util.ConfigTestConstant;
7 import org.onap.config.util.TestUtil;
8 import org.junit.After;
9 import org.junit.Assert;
10 import org.junit.Before;
11 import org.junit.Test;
12
13 import java.io.File;
14 import java.io.FileOutputStream;
15 import java.io.IOException;
16 import java.io.OutputStream;
17 import java.util.Properties;
18
19 /**
20  * Created by sheetalm on 10/17/2016.
21  * Pre-requisite - set -Dconfig.location=${"user.home"}/TestResources/ while running test
22  * Scenario 20
23  * Update the central configuration and fetch the Dynamic Configuration
24  */
25 public class DynamicConfigurationTest {
26
27     public final static String NAMESPACE = "DynamicConfiguration";
28
29     @Before
30     public void setUp() throws IOException {
31         String data = "{name:\"SCM\"}";
32         TestUtil.writeFile(data);
33     }
34
35     @Test
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");
45         }
46
47         //Verify configuration with Configuration without wait. This should fetch cached value
48         Assert.assertEquals("14" , config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
49
50         Thread.sleep(10000);
51
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());
55
56     }
57
58     @After
59     public void tearDown() throws Exception {
60         TestUtil.cleanUp();
61         File f = new File(TestUtil.jsonSchemaLoc+"config.properties");
62         if(f.exists()) {
63             f.delete();
64         }
65     }
66 }