1 package org.openecomp.config.test;
3 import org.openecomp.config.api.Configuration;
4 import org.openecomp.config.api.ConfigurationChangeListener;
5 import org.openecomp.config.api.ConfigurationManager;
6 import org.openecomp.config.util.ConfigTestConstant;
7 import org.openecomp.config.util.TestUtil;
8 import org.junit.After;
9 import org.junit.Before;
10 import org.junit.Test;
11 import org.junit.Assert;
14 import java.io.FileOutputStream;
15 import java.io.IOException;
16 import java.io.OutputStream;
17 import java.util.Properties;
20 * Pre-requisite - set -Dconfig.location=${"user.home"}/TestResources/ while running test
21 * Scenario 14 - Verify Change Notifications for any change in the registered key
22 * Created by sheetalm on 10/14/2016.
24 public class NotificationOnPropValTest {
26 public final static String NAMESPACE = "NotificationOnPropVal";
28 public String updatedValue = null;
31 public void setUp() throws IOException {
32 String data = "{name:\"SCM\"}";
33 TestUtil.writeFile(data);
37 public void testNotification() throws IOException, InterruptedException {
38 Configuration config = ConfigurationManager.lookup();
40 System.out.println(config.getAsString(NAMESPACE,ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
42 config.addConfigurationChangeListener(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, new PropValListener());
44 Properties props = new Properties();
45 props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "20");
46 props.setProperty("_config.namespace",NAMESPACE);
47 props.setProperty("_config.mergeStrategy","override");
48 File f = new File(TestUtil.jsonSchemaLoc+"config.properties");
49 OutputStream out = new FileOutputStream( f );
50 props.store(out, "Override Config Property at Conventional Resource");
55 System.out.println(config.getAsString(NAMESPACE,ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
57 Assert.assertEquals("20" , updatedValue);
60 private class PropValListener implements ConfigurationChangeListener {
62 public void notify(String key, Object oldValue, Object newValue) {
63 System.out.println("received notification::oldValue=="+oldValue+" newValue=="+newValue);
64 updatedValue = newValue.toString();
69 public void tearDown() throws Exception {
71 File f = new File(TestUtil.jsonSchemaLoc+"config.properties");
73 boolean isDeleted = f.delete();