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