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.util.HashMap;
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;
36 * Created by sheetalm on 10/19/2016.
38 * Pre-requisite - set -Dnode.config.location=${"user.home"}/TestResources/ while running test
39 * Verify node specific override using CLI
41 public class NodeSpecificCliTest {
43 private static final String NAMESPACE = "NodeCLI";
46 public static void tearDown() throws Exception {
48 File f = new File(TestUtil.jsonSchemaLoc + "config.properties");
50 assertTrue(f.delete());
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);
62 ConfigurationManager conf = new CliConfigurationImpl();
63 String maxLength = conf.getConfigurationValue(input);
65 //Verify Property from Namespace configurations
66 Assert.assertEquals("30", maxLength);
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");
77 //Verify property from node specific configuration
78 input.put("nodeSpecific", true);
79 String nodeVal = conf.getConfigurationValue(input);
80 Assert.assertEquals("30", nodeVal);
83 assertTrue(f.delete());