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;
13 import java.io.IOException;
14 import java.util.ArrayList;
15 import java.util.List;
19 * Test to Validate notification on changes to the underlying source
20 * Resource here is GeneratorsList.json ehich is created in test itself
23 public class ResourceChangeNotificationTest {
25 String newValue = null;
27 public final static String NAMESPACE = "Notification";
30 public void setUp() throws IOException {
31 String data = "{name:\"SCM\"}";
32 TestUtil.writeFile(data);
36 public void testNotification() throws IOException, InterruptedException {
37 Configuration config = ConfigurationManager.lookup();
38 config.addConfigurationChangeListener(NAMESPACE,ConfigTestConstant.ARTIFACT_JSON_SCHEMA, new MyListener());
41 String newValue = config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_JSON_SCHEMA);
43 Assert.assertEquals("{name:\"updated SCM\"}",newValue);
45 Assert.assertEquals( "14",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH ));
47 Assert.assertEquals( "a-zA-Z", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_UPPER ));
49 String artifactConsumer = config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_CONSUMER );
50 Assert.assertEquals(artifactConsumer,config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_CONSUMER_APPC ));
52 List<String> expectedExtList = new ArrayList<String>();
53 expectedExtList.add("pdf"); expectedExtList.add("zip"); expectedExtList.add("xml");
54 List<String> extList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_EXT);
55 Assert.assertEquals(expectedExtList, extList);
57 List<String> expectedEncList = new ArrayList<String>();
58 expectedEncList.add("Base64"); expectedEncList.add("MD5");
59 List<String> encList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_ENC);
60 Assert.assertEquals(expectedEncList, encList);
62 List<String> expectedLocList = new ArrayList<String>();
63 expectedLocList.add("/opt/spool"); expectedLocList.add(System.getProperty("user.home")+"/asdc");
64 List<String> locList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_LOC);
65 Assert.assertEquals(expectedLocList, locList);
67 Assert.assertEquals("@"+System.getenv("Path")+"/myschema.json",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_XML_SCHEMA));
70 class MyListener implements ConfigurationChangeListener{
72 public void notify(String key, Object oldValue, Object newValue) {
73 System.out.println("received notification::oldValue=="+oldValue+" newValue=="+newValue);
77 private void updateJsonInFile() throws IOException{
78 String data = "{name:\"updated SCM\"}";
79 TestUtil.writeFile(data);
83 public void tearDown() throws Exception {