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.ConfigurationChangeListener;
9 import org.onap.config.api.ConfigurationManager;
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;
21 * Update and Verify Change Notifications for any change in the registered key for node specific configuration
22 * Pre-requisite - set -Dnode.config.location=${"user.home"}/TestResources/ while running test
23 * Created by sheetalm on 10/17/2016.
25 public class NotificationForNodeConfigTest {
26 public final static String NAMESPACE = "NotificationForNodeConfig";
28 private String updatedValue = null;
31 public void setUp() throws IOException {
32 String data = "{name:\"SCM\"}";
33 TestUtil.writeFile(data);
37 public void testNotificationForNode() throws IOException, InterruptedException {
38 Configuration config = ConfigurationManager.lookup();
40 System.out.println(config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
42 Properties props = new Properties();
43 props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "30");
44 props.setProperty("_config.namespace",NAMESPACE);
45 File f = new File(TestUtil.jsonSchemaLoc + "config.properties");
46 try (OutputStream out = new FileOutputStream(f)) {
47 props.store(out, "Node Config Property");
52 //Verify property from node specific configuration
53 Assert.assertEquals("30", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
55 config.addConfigurationChangeListener(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, new NodePropValListener());
57 props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "80");
58 try (OutputStream out = new FileOutputStream(f)) {
59 props.store(out, "Updated Node Config Property");
64 //Verify change listenere is invoked when node specific configuration is changed.
65 Assert.assertEquals("80", updatedValue);
69 private class NodePropValListener implements ConfigurationChangeListener {
71 public void notify(String key, Object oldValue, Object newValue) {
72 System.out.println("received notification::oldValue=="+oldValue+" newValue=="+newValue);
73 updatedValue = newValue.toString();
78 public void tearDown() throws Exception {
80 File f = new File(TestUtil.jsonSchemaLoc+"config.properties");