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 / NodeSpecificCliTest.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 static org.junit.Assert.assertTrue;
20
21 import java.io.File;
22 import java.io.FileOutputStream;
23 import java.io.OutputStream;
24 import java.util.HashMap;
25 import java.util.Map;
26 import java.util.Properties;
27 import org.junit.AfterClass;
28 import org.junit.Assert;
29 import org.junit.Test;
30 import org.onap.config.api.ConfigurationManager;
31 import org.onap.config.impl.CliConfigurationImpl;
32 import org.onap.config.util.ConfigTestConstant;
33 import org.onap.config.util.TestUtil;
34
35 /**
36  * Created by sheetalm on 10/19/2016.
37  * Scenario 19
38  * Pre-requisite - set -Dnode.config.location=${"user.home"}/TestResources/ while running test
39  * Verify node specific override using CLI
40  */
41 public class NodeSpecificCliTest {
42
43     private static final String NAMESPACE = "NodeCLI";
44
45     @AfterClass
46     public static void tearDown() throws Exception {
47         TestUtil.cleanUp();
48         File f = new File(TestUtil.jsonSchemaLoc + "config.properties");
49         if (f.exists()) {
50             assertTrue(f.delete());
51         }
52     }
53
54     @Test
55     public void testCliApi() throws Exception {
56         //Verify without fallback
57         Map<String, Object> input = new HashMap<>();
58         input.put("ImplClass", "org.onap.config.type.ConfigurationQuery");
59         input.put("namespace", NAMESPACE);
60         input.put("key", ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH);
61
62         ConfigurationManager conf = new CliConfigurationImpl();
63         String maxLength = conf.getConfigurationValue(input);
64
65         //Verify Property from Namespace configurations
66         Assert.assertEquals("30", maxLength);
67
68         //Add node specific configurations
69         Properties props = new Properties();
70         props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "50");
71         props.setProperty("_config.namespace", NAMESPACE);
72         File f = new File(TestUtil.jsonSchemaLoc + "config.properties");
73         try (OutputStream out = new FileOutputStream(f)) {
74             props.store(out, "Node Config Property");
75         }
76
77         //Verify property from node specific configuration
78         input.put("nodeSpecific", true);
79         String nodeVal = conf.getConfigurationValue(input);
80         Assert.assertEquals("30", nodeVal);
81
82         if (f.exists()) {
83             assertTrue(f.delete());
84         }
85     }
86 }