1 package org.openecomp.config.test;
4 import java.io.FileWriter;
5 import java.io.IOException;
6 import java.util.ArrayList;
9 import org.openecomp.config.ConfigurationUtils;
10 import org.openecomp.config.util.ConfigTestConstant;
12 import org.openecomp.config.util.TestUtil;
13 import org.junit.After;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
18 import org.openecomp.config.api.Configuration;
19 import org.openecomp.config.api.ConfigurationChangeListener;
20 import org.openecomp.config.api.ConfigurationManager;
24 * Test to Validate notification on changes to the underlying source
25 * Resource here is GeneratorsList.json ehich is created in test itself
28 public class ResourceChangeNotificationTest {
30 String newValue = null;
32 public final static String NAMESPACE = "Notification";
35 public void setUp() throws IOException {
36 String data = "{name:\"SCM\"}";
37 TestUtil.writeFile(data);
41 public void testNotification() throws IOException, InterruptedException {
42 Configuration config = ConfigurationManager.lookup();
43 config.addConfigurationChangeListener(NAMESPACE,ConfigTestConstant.ARTIFACT_JSON_SCHEMA, new MyListener());
46 String newValue = config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_JSON_SCHEMA);
48 Assert.assertEquals("{name:\"updated SCM\"}",newValue);
50 Assert.assertEquals( "14",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH ));
52 Assert.assertEquals( "a-zA-Z", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_UPPER ));
54 String artifactConsumer = config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_CONSUMER );
55 Assert.assertEquals(artifactConsumer,config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_CONSUMER_APPC ));
57 List<String> expectedExtList = new ArrayList<String>();
58 expectedExtList.add("pdf"); expectedExtList.add("zip"); expectedExtList.add("xml");
59 List<String> extList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_EXT);
60 Assert.assertEquals(expectedExtList, extList);
62 List<String> expectedEncList = new ArrayList<String>();
63 expectedEncList.add("Base64"); expectedEncList.add("MD5");
64 List<String> encList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_ENC);
65 Assert.assertEquals(expectedEncList, encList);
67 List<String> expectedLocList = new ArrayList<String>();
68 expectedLocList.add("/opt/spool"); expectedLocList.add(System.getProperty("user.home")+"/asdc");
69 List<String> locList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_LOC);
70 Assert.assertEquals(expectedLocList, locList);
72 Assert.assertEquals("@"+System.getenv("Path")+"/myschema.json",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_XML_SCHEMA));
75 class MyListener implements ConfigurationChangeListener{
77 public void notify(String key, Object oldValue, Object newValue) {
78 System.out.println("received notification::oldValue=="+oldValue+" newValue=="+newValue);
82 private void updateJsonInFile() throws IOException{
83 String data = "{name:\"updated SCM\"}";
84 TestUtil.writeFile(data);
88 public void tearDown() throws Exception {