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 java.io.IOException;
20 import java.util.HashMap;
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;
33 * Created by sheetalm on 10/18/2016.
34 * Scenario 21, Scenario 23
35 * 21 - Verify the CLI fetches only the current value unless the fallback option is specified
36 * 23 - Fetch value using CLI for a key with underlying resource
38 public class CliFallbackAndLookupTest {
40 private static final String NAMESPACE = "CLIFallback";
41 private static final String TENANT = "OPENECOMP";
44 public void setUp() throws IOException {
45 String data = "{name:\"SCM\"}";
46 TestUtil.writeFile(data);
50 public void testCliFallbackAndLookup() throws Exception {
52 //Verify without fallback
53 Map<String, Object> input = new HashMap<>();
54 input.put("ImplClass", "org.onap.config.type.ConfigurationQuery");
55 input.put("tenant", TENANT);
56 input.put("namespace", NAMESPACE);
57 input.put("key", ConfigTestConstant.ARTIFACT_MAXSIZE);
59 ConfigurationManager conf = new CliConfigurationImpl();
60 String maxSizeWithNoFallback = conf.getConfigurationValue(input);
61 Assert.assertEquals("", maxSizeWithNoFallback);
63 //Verify underlying resource without lookup switch
64 input.put("key", ConfigTestConstant.ARTIFACT_JSON_SCHEMA);
65 String jsonSchema = conf.getConfigurationValue(input);
66 Assert.assertEquals("@" + System.getProperty("user.home") + "/TestResources/GeneratorsList.json", jsonSchema);
68 //Verify underlying resource with lookup switch
69 input.put("externalLookup", true);
70 jsonSchema = conf.getConfigurationValue(input);
71 Assert.assertEquals("{name:\"SCM\"}", jsonSchema);
73 //Verify with fallback
74 Map<String, Object> fallbackInput = new HashMap<>();
75 fallbackInput.put("ImplClass", "org.onap.config.type.ConfigurationQuery");
76 fallbackInput.put("fallback", true);
77 fallbackInput.put("tenant", TENANT);
78 fallbackInput.put("namespace", NAMESPACE);
79 fallbackInput.put("key", ConfigTestConstant.ARTIFACT_MAXSIZE);
81 String maxSizeWithFallback = conf.getConfigurationValue(fallbackInput);
82 Assert.assertEquals("1024", maxSizeWithFallback);
86 public void tearDown() throws Exception {