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 / CliFallbackAndLookupTest.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 /**
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
37  */
38 public class CliFallbackAndLookupTest {
39
40     private static final String NAMESPACE = "CLIFallback";
41     private static final String TENANT = "OPENECOMP";
42
43     @Before
44     public void setUp() throws IOException {
45         String data = "{name:\"SCM\"}";
46         TestUtil.writeFile(data);
47     }
48
49     @Test
50     public void testCliFallbackAndLookup() throws Exception {
51
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);
58
59         ConfigurationManager conf = new CliConfigurationImpl();
60         String maxSizeWithNoFallback = conf.getConfigurationValue(input);
61         Assert.assertEquals("", maxSizeWithNoFallback);
62
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);
67
68         //Verify underlying resource with lookup switch
69         input.put("externalLookup", true);
70         jsonSchema = conf.getConfigurationValue(input);
71         Assert.assertEquals("{name:\"SCM\"}", jsonSchema);
72
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);
80
81         String maxSizeWithFallback = conf.getConfigurationValue(fallbackInput);
82         Assert.assertEquals("1024", maxSizeWithFallback);
83     }
84
85     @After
86     public void tearDown() throws Exception {
87         TestUtil.cleanUp();
88     }
89 }