2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.config.test;
19 import java.io.IOException;
20 import java.lang.management.ManagementFactory;
21 import java.util.HashMap;
23 import javax.management.JMX;
24 import javax.management.MBeanServerConnection;
25 import javax.management.ObjectName;
26 import org.junit.After;
27 import org.junit.Assert;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.config.Constants;
31 import org.onap.config.api.ConfigurationManager;
32 import org.onap.config.util.ConfigTestConstant;
33 import org.onap.config.util.TestUtil;
36 * Created by sheetalm on 10/18/2016.
38 * Verify Configuration Management System - Command Line Interface for query, update and list operations
40 public class CliTest {
42 private static final String NAMESPACE = "CLI";
43 private static final String TENANT = "OPENECOMP";
46 public void setUp() throws IOException {
47 String data = "{name:\"SCM\"}";
48 TestUtil.writeFile(data);
52 public void testCliApi() throws Exception {
53 //Verify without fallback
54 Map<String, Object> input = new HashMap<>();
55 input.put("ImplClass", "org.onap.config.type.ConfigurationQuery");
56 input.put("tenant", TENANT);
57 input.put("namespace", NAMESPACE);
58 input.put("key", ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH);
60 MBeanServerConnection mbsc = ManagementFactory.getPlatformMBeanServer();
61 ObjectName mbeanName = new ObjectName(Constants.MBEAN_NAME);
62 ConfigurationManager conf = JMX.newMBeanProxy(mbsc, mbeanName, ConfigurationManager.class, true);
63 String maxLength = conf.getConfigurationValue(input);
64 Assert.assertEquals("14", maxLength);
66 Map<String, String> outputMap = conf.listConfiguration(input);
67 validateCliListConfig(outputMap);
70 private void validateCliListConfig(Map<String, String> outputMap) {
72 Assert.assertEquals("@" + System.getProperty("user.home") + "/TestResources/GeneratorsList.json",
73 outputMap.get(ConfigTestConstant.ARTIFACT_JSON_SCHEMA));
74 Assert.assertEquals("appc,catalog", outputMap.get(ConfigTestConstant.ARTIFACT_CONSUMER));
75 Assert.assertEquals("6", outputMap.get(ConfigTestConstant.ARTIFACT_NAME_MINLENGTH));
76 Assert.assertEquals("true", outputMap.get(ConfigTestConstant.ARTIFACT_ENCODED));
77 Assert.assertEquals("14", outputMap.get(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
78 Assert.assertEquals("pdf,zip,xml,pdf,tgz,xls", outputMap.get(ConfigTestConstant.ARTIFACT_EXT));
79 Assert.assertEquals("Base64,MD5", outputMap.get(ConfigTestConstant.ARTIFACT_ENC));
80 Assert.assertEquals("@" + TestUtil.getenv(ConfigTestConstant.PATH) + "/myschema.json",
81 outputMap.get(ConfigTestConstant.ARTIFACT_XML_SCHEMA));
82 Assert.assertEquals("a-zA-Z_0-9", outputMap.get(ConfigTestConstant.ARTIFACT_NAME_UPPER));
83 Assert.assertEquals("/opt/spool," + System.getProperty("user.home") + "/asdc",
84 outputMap.get(ConfigTestConstant.ARTIFACT_LOC));
85 Assert.assertEquals("deleted,Deleted", outputMap.get(ConfigTestConstant.ARTIFACT_STATUS));
89 public void tearDown() throws Exception {