Removed JMX, other unused code from configuration
[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.util.HashMap;
21 import java.util.Map;
22 import org.junit.After;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.onap.config.api.ConfigurationManager;
27 import org.onap.config.impl.CliConfigurationImpl;
28 import org.onap.config.util.ConfigTestConstant;
29 import org.onap.config.util.TestUtil;
30
31 /**
32  * Created by sheetalm on 10/18/2016.
33  * Scenario 17
34  * Verify Configuration Management System - Command Line Interface for query, update and list operations
35  */
36 public class CliTest {
37
38     private static final String NAMESPACE = "CLI";
39     private static final String TENANT = "OPENECOMP";
40
41     @Before
42     public void setUp() throws IOException {
43         String data = "{name:\"SCM\"}";
44         TestUtil.writeFile(data);
45     }
46
47     @Test
48     public void testCliApi() throws Exception {
49         //Verify without fallback
50         Map<String, Object> input = new HashMap<>();
51         input.put("ImplClass", "org.onap.config.type.ConfigurationQuery");
52         input.put("tenant", TENANT);
53         input.put("namespace", NAMESPACE);
54         input.put("key", ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH);
55
56         ConfigurationManager conf = new CliConfigurationImpl();
57         String maxLength = conf.getConfigurationValue(input);
58         Assert.assertEquals("14", maxLength);
59
60         Map<String, String> outputMap = conf.listConfiguration(input);
61         validateCliListConfig(outputMap);
62     }
63
64     private void validateCliListConfig(Map<String, String> outputMap) {
65
66         Assert.assertEquals("@" + System.getProperty("user.home") + "/TestResources/GeneratorsList.json",
67                 outputMap.get(ConfigTestConstant.ARTIFACT_JSON_SCHEMA));
68         Assert.assertEquals("appc,catalog", outputMap.get(ConfigTestConstant.ARTIFACT_CONSUMER));
69         Assert.assertEquals("6", outputMap.get(ConfigTestConstant.ARTIFACT_NAME_MINLENGTH));
70         Assert.assertEquals("true", outputMap.get(ConfigTestConstant.ARTIFACT_ENCODED));
71         Assert.assertEquals("14", outputMap.get(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
72         Assert.assertEquals("pdf,zip,xml,pdf,tgz,xls", outputMap.get(ConfigTestConstant.ARTIFACT_EXT));
73         Assert.assertEquals("Base64,MD5", outputMap.get(ConfigTestConstant.ARTIFACT_ENC));
74         Assert.assertEquals("@" + TestUtil.getenv(ConfigTestConstant.PATH) + "/myschema.json",
75                 outputMap.get(ConfigTestConstant.ARTIFACT_XML_SCHEMA));
76         Assert.assertEquals("a-zA-Z_0-9", outputMap.get(ConfigTestConstant.ARTIFACT_NAME_UPPER));
77         Assert.assertEquals("/opt/spool," + System.getProperty("user.home") + "/asdc",
78                 outputMap.get(ConfigTestConstant.ARTIFACT_LOC));
79         Assert.assertEquals("deleted,Deleted", outputMap.get(ConfigTestConstant.ARTIFACT_STATUS));
80     }
81
82     @After
83     public void tearDown() throws Exception {
84         TestUtil.cleanUp();
85     }
86 }