18c136013c0d1bc97160c4186b99d7fb7f9faf21
[sdc.git] / common / onap-common-configuration-management / onap-configuration-management-core / src / test / java / org / onap / config / test / CliTest.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.config.test;
18
19 import java.io.IOException;
20 import java.lang.management.ManagementFactory;
21 import java.util.HashMap;
22 import java.util.Map;
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;
34
35 /**
36  * Created by sheetalm on 10/18/2016.
37  * Scenario 17
38  * Verify Configuration Management System - Command Line Interface for query, update and list operations
39  */
40 public class CliTest {
41
42     private static final String NAMESPACE = "CLI";
43     private static final String TENANT = "OPENECOMP";
44
45     @Before
46     public void setUp() throws IOException {
47         String data = "{name:\"SCM\"}";
48         TestUtil.writeFile(data);
49     }
50
51     @Test
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);
59
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);
65
66         Map<String, String> outputMap = conf.listConfiguration(input);
67         validateCliListConfig(outputMap);
68     }
69
70     private void validateCliListConfig(Map<String, String> outputMap) {
71
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));
86     }
87
88     @After
89     public void tearDown() throws Exception {
90         TestUtil.cleanUp();
91     }
92 }