Rename packages from openecomp to onap.
[sdc.git] / common / onap-common-configuration-management / onap-configuration-management-test / src / test / java / org / onap / config / test / ResourceChangeNotificationTest.java
1 package org.onap.config.test;
2
3 import java.io.IOException;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import org.onap.config.util.ConfigTestConstant;
8
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;
14
15 import org.onap.config.api.Configuration;
16 import org.onap.config.api.ConfigurationChangeListener;
17 import org.onap.config.api.ConfigurationManager;
18
19 /**
20  * Scenario 7
21  * Test to Validate notification on changes to the underlying source
22  * Resource here is GeneratorsList.json ehich is created in test itself
23  */
24
25 public class ResourceChangeNotificationTest  {
26
27         String newValue = null;
28
29         public final static String NAMESPACE = "Notification";
30         
31         @Before
32         public void setUp() throws IOException {
33                 String data = "{name:\"SCM\"}";
34                 TestUtil.writeFile(data);
35         }
36
37         @Test
38         public void testNotification() throws IOException, InterruptedException {               
39                 Configuration config = ConfigurationManager.lookup();           
40                 config.addConfigurationChangeListener(NAMESPACE,ConfigTestConstant.ARTIFACT_JSON_SCHEMA, new MyListener());
41                 updateJsonInFile();
42                 Thread.sleep(35000);
43                 String newValue = config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_JSON_SCHEMA);
44
45                 Assert.assertEquals("{name:\"updated SCM\"}",newValue);
46                 
47                 Assert.assertEquals( "14",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH ));
48                 
49                 Assert.assertEquals( "a-zA-Z", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_UPPER ));
50                 
51                 String artifactConsumer = config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_CONSUMER );
52                 Assert.assertEquals(artifactConsumer,config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_CONSUMER_APPC ));
53
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);
58                 
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);          
63                 
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);
68
69                 Assert.assertEquals("@"+System.getenv("Path")+"/myschema.json",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_XML_SCHEMA));
70         }
71         
72         class MyListener implements ConfigurationChangeListener{
73                 @Override
74                 public void notify(String key, Object oldValue, Object newValue) {                      
75                         System.out.println("received notification::oldValue=="+oldValue+" newValue=="+newValue);                        
76                 }               
77         }
78         
79         private void updateJsonInFile() throws IOException{     
80                 String data = "{name:\"updated SCM\"}";
81                 TestUtil.writeFile(data);
82         }
83         
84         @After
85         public void tearDown() throws Exception {
86                 TestUtil.cleanUp();
87         }
88 }