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 static org.junit.Assert.assertTrue;
22 import java.io.FileOutputStream;
23 import java.io.OutputStream;
24 import java.lang.management.ManagementFactory;
25 import java.util.HashMap;
27 import java.util.Properties;
28 import javax.management.JMX;
29 import javax.management.MBeanServerConnection;
30 import javax.management.ObjectName;
31 import org.junit.AfterClass;
32 import org.junit.Assert;
33 import org.junit.Test;
34 import org.onap.config.Constants;
35 import org.onap.config.api.ConfigurationManager;
36 import org.onap.config.util.ConfigTestConstant;
37 import org.onap.config.util.TestUtil;
40 * Created by sheetalm on 10/19/2016.
42 * Pre-requisite - set -Dnode.config.location=${"user.home"}/TestResources/ while running test
43 * Verify node specific override using CLI
45 public class NodeSpecificCliTest {
47 private static final String NAMESPACE = "NodeCLI";
50 public static void tearDown() throws Exception {
52 File f = new File(TestUtil.jsonSchemaLoc + "config.properties");
54 assertTrue(f.delete());
59 public void testCliApi() throws Exception {
60 //Verify without fallback
61 Map<String, Object> input = new HashMap<>();
62 input.put("ImplClass", "org.onap.config.type.ConfigurationQuery");
63 input.put("namespace", NAMESPACE);
64 input.put("key", ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH);
66 MBeanServerConnection mbsc = ManagementFactory.getPlatformMBeanServer();
67 ObjectName mbeanName = new ObjectName(Constants.MBEAN_NAME);
68 ConfigurationManager conf = JMX.newMBeanProxy(mbsc, mbeanName, ConfigurationManager.class, true);
69 String maxLength = conf.getConfigurationValue(input);
71 //Verify Property from Namespace configurations
72 Assert.assertEquals("30", maxLength);
74 //Add node specific configurations
75 Properties props = new Properties();
76 props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "50");
77 props.setProperty("_config.namespace", NAMESPACE);
78 File f = new File(TestUtil.jsonSchemaLoc + "config.properties");
79 try (OutputStream out = new FileOutputStream(f)) {
80 props.store(out, "Node Config Property");
83 //Verify property from node specific configuration
84 input.put("nodeSpecific", true);
85 String nodeVal = conf.getConfigurationValue(input);
86 Assert.assertEquals("30", nodeVal);
89 assertTrue(f.delete());