1 package org.onap.config.test;
3 import java.io.IOException;
4 import java.util.ArrayList;
7 import org.onap.config.util.ConfigTestConstant;
9 import org.onap.config.util.TestUtil;
10 import org.junit.After;
11 import org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Test;
15 import org.onap.config.api.Configuration;
16 import org.onap.config.api.ConfigurationChangeListener;
17 import org.onap.config.api.ConfigurationManager;
21 * Test to Validate notification on changes to the underlying source
22 * Resource here is GeneratorsList.json ehich is created in test itself
25 public class ResourceChangeNotificationTest {
27 String newValue = null;
29 public final static String NAMESPACE = "Notification";
32 public void setUp() throws IOException {
33 String data = "{name:\"SCM\"}";
34 TestUtil.writeFile(data);
38 public void testNotification() throws IOException, InterruptedException {
39 Configuration config = ConfigurationManager.lookup();
40 config.addConfigurationChangeListener(NAMESPACE,ConfigTestConstant.ARTIFACT_JSON_SCHEMA, new MyListener());
43 String newValue = config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_JSON_SCHEMA);
45 Assert.assertEquals("{name:\"updated SCM\"}",newValue);
47 Assert.assertEquals( "14",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH ));
49 Assert.assertEquals( "a-zA-Z", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_UPPER ));
51 String artifactConsumer = config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_CONSUMER );
52 Assert.assertEquals(artifactConsumer,config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_CONSUMER_APPC ));
54 List<String> expectedExtList = new ArrayList<String>();
55 expectedExtList.add("pdf"); expectedExtList.add("zip"); expectedExtList.add("xml");
56 List<String> extList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_EXT);
57 Assert.assertEquals(expectedExtList, extList);
59 List<String> expectedEncList = new ArrayList<String>();
60 expectedEncList.add("Base64"); expectedEncList.add("MD5");
61 List<String> encList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_ENC);
62 Assert.assertEquals(expectedEncList, encList);
64 List<String> expectedLocList = new ArrayList<String>();
65 expectedLocList.add("/opt/spool"); expectedLocList.add(System.getProperty("user.home")+"/asdc");
66 List<String> locList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_LOC);
67 Assert.assertEquals(expectedLocList, locList);
69 Assert.assertEquals("@"+System.getenv("Path")+"/myschema.json",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_XML_SCHEMA));
72 class MyListener implements ConfigurationChangeListener{
74 public void notify(String key, Object oldValue, Object newValue) {
75 System.out.println("received notification::oldValue=="+oldValue+" newValue=="+newValue);
79 private void updateJsonInFile() throws IOException{
80 String data = "{name:\"updated SCM\"}";
81 TestUtil.writeFile(data);
85 public void tearDown() throws Exception {