1 package org.onap.config.test;
3 import org.onap.config.util.ConfigTestConstant;
4 import org.onap.config.Constants;
5 import org.onap.config.api.ConfigurationChangeListener;
6 import org.onap.config.api.ConfigurationManager;
7 import org.onap.config.util.TestUtil;
8 import org.junit.After;
9 import org.junit.Assert;
10 import org.junit.Before;
11 import org.junit.Test;
13 import javax.management.JMX;
14 import javax.management.MBeanServerConnection;
15 import javax.management.ObjectName;
16 import java.io.IOException;
17 import java.lang.management.ManagementFactory;
18 import java.util.HashMap;
22 * Created by sheetalm on 10/18/2016.
24 * Verify Configuration Management System - Command Line Interface for query, update and list operations
26 public class CLITest {
28 public final static String NAMESPACE = "CLI";
29 public final static String TENANT = "OPENECOMP";
30 private String updatedValue = "";
33 public void setUp() throws IOException {
34 String data = "{name:\"SCM\"}";
35 TestUtil.writeFile(data);
39 public void testCLIApi() throws Exception{
40 //Verify without fallback
41 Map<String, Object> input = new HashMap<>();
42 input.put("ImplClass", "org.openecomp.config.type.ConfigurationQuery");
43 input.put("tenant", TENANT);
44 input.put("namespace", NAMESPACE);
45 input.put("key", ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH);
47 MBeanServerConnection mbsc = ManagementFactory.getPlatformMBeanServer();
48 ObjectName mbeanName = new ObjectName(Constants.MBEAN_NAME);
49 ConfigurationManager conf = JMX.newMBeanProxy(mbsc, mbeanName, ConfigurationManager.class, true);
50 String maxLength = conf.getConfigurationValue(input);
51 Assert.assertEquals("14",maxLength);
53 conf.addConfigurationChangeListener(TENANT,NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, new CLIListener());
57 input.put("ImplClass", "org.openecomp.config.type.ConfigurationUpdate");
58 input.put("value", "24");
59 conf.updateConfigurationValue(input);
63 Assert.assertEquals("24",updatedValue);
65 //Reset value and fetch updated value again
66 input.put("value", "");
67 input.put("ImplClass", "org.openecomp.config.type.ConfigurationQuery");
68 String updatedMaxLength = conf.getConfigurationValue(input);
69 Assert.assertEquals("24",updatedMaxLength);
71 Map<String, String> outputMap = conf.listConfiguration(input);
72 for(Map.Entry<String, String> entry : outputMap.entrySet()){
73 System.out.println(entry.getKey()+" : "+entry.getValue());
74 validateCLIListConfig(outputMap);
78 private class CLIListener implements ConfigurationChangeListener {
80 public void notify(String key, Object oldValue, Object newValue) {
81 System.out.println("received notification::oldValue=="+oldValue+" newValue=="+newValue);
82 updatedValue = newValue.toString();
86 private void validateCLIListConfig(Map<String, String> outputMap ) {
88 Assert.assertEquals("@"+System.getProperty("user.home")+"/TestResources/GeneratorsList.json" , outputMap.get(
89 ConfigTestConstant.ARTIFACT_JSON_SCHEMA));
90 Assert.assertEquals("appc,catalog", outputMap.get(ConfigTestConstant.ARTIFACT_CONSUMER));
91 Assert.assertEquals("6", outputMap.get(ConfigTestConstant.ARTIFACT_NAME_MINLENGTH));
92 Assert.assertEquals("true", outputMap.get(ConfigTestConstant.ARTIFACT_ENCODED));
93 Assert.assertEquals("24", outputMap.get(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
94 Assert.assertEquals("pdf,zip,xml,pdf,tgz,xls", outputMap.get(ConfigTestConstant.ARTIFACT_EXT));
95 Assert.assertEquals("Base64,MD5", outputMap.get(ConfigTestConstant.ARTIFACT_ENC));
96 Assert.assertEquals("@"+System.getenv("Path")+"/myschema.json", outputMap.get(
97 ConfigTestConstant.ARTIFACT_XML_SCHEMA));
98 Assert.assertEquals("a-zA-Z_0-9", outputMap.get(ConfigTestConstant.ARTIFACT_NAME_UPPER));
99 Assert.assertEquals("/opt/spool,"+System.getProperty("user.home")+"/asdc", outputMap.get(
100 ConfigTestConstant.ARTIFACT_LOC));
101 Assert.assertEquals("deleted,Deleted", outputMap.get(ConfigTestConstant.ARTIFACT_STATUS));
105 public void tearDown() throws Exception {