4d92889ab73c9e414743c4bad904736167547a86
[sdc.git] /
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.jupiter.api.Assertions.assertEquals;
20
21 import java.io.IOException;
22 import java.util.HashMap;
23 import java.util.Map;
24 import org.junit.jupiter.api.AfterEach;
25 import org.junit.jupiter.api.BeforeEach;
26 import org.junit.jupiter.api.Disabled;
27 import org.junit.jupiter.api.Test;
28 import org.onap.config.api.ConfigurationManager;
29 import org.onap.config.impl.CliConfigurationImpl;
30 import org.onap.config.util.ConfigTestConstant;
31 import org.onap.config.util.TestUtil;
32
33 /**
34  * Created by sheetalm on 10/18/2016.
35  * Scenario 21, Scenario 23
36  * 21 - Verify the CLI fetches only the current value unless the fallback option is specified
37  * 23 - Fetch value using CLI for a key with underlying resource
38  */
39 @Disabled("Investigate instability (random failures)"
40     + "[ERROR]   CliFallbackAndLookupTest.testCliFallbackAndLookup:71 expected:<[{name:\"SCM\"}]> but was:<[@/home/jenkins/TestResources/GeneratorsList.json]>")
41 class CliFallbackAndLookupTest {
42
43     private static final String NAMESPACE = "CLIFallback";
44     private static final String TENANT = "OPENECOMP";
45
46     @BeforeEach
47     public void setUp() throws Exception {
48         TestUtil.cleanUp();
49     }
50
51     @Test
52     void testCliFallbackAndLookup() throws Exception {
53
54         //Verify without fallback
55         Map<String, Object> input = new HashMap<>();
56         input.put("ImplClass", "org.onap.config.type.ConfigurationQuery");
57         input.put("tenant", TENANT);
58         input.put("namespace", NAMESPACE);
59         input.put("key", ConfigTestConstant.ARTIFACT_MAXSIZE);
60
61         ConfigurationManager conf = new CliConfigurationImpl();
62         String maxSizeWithNoFallback = conf.getConfigurationValue(input);
63         assertEquals("", maxSizeWithNoFallback);
64
65         //Verify underlying resource without lookup switch
66         input.put("key", ConfigTestConstant.ARTIFACT_JSON_SCHEMA);
67         String jsonSchema = conf.getConfigurationValue(input);
68         assertEquals("@" + System.getProperty("user.home") + "/TestResources/GeneratorsList.json", jsonSchema);
69
70         //Verify underlying resource with lookup switch
71         input.put("externalLookup", true);
72         jsonSchema = conf.getConfigurationValue(input);
73         assertEquals("{name:\"SCM\"}", jsonSchema);
74
75         //Verify with fallback
76         Map<String, Object> fallbackInput = new HashMap<>();
77         fallbackInput.put("ImplClass", "org.onap.config.type.ConfigurationQuery");
78         fallbackInput.put("fallback", true);
79         fallbackInput.put("tenant", TENANT);
80         fallbackInput.put("namespace", NAMESPACE);
81         fallbackInput.put("key", ConfigTestConstant.ARTIFACT_MAXSIZE);
82
83         String maxSizeWithFallback = conf.getConfigurationValue(fallbackInput);
84         assertEquals("1024", maxSizeWithFallback);
85     }
86
87     @AfterEach
88     public void tearDown() throws Exception {
89         TestUtil.cleanUp();
90     }
91 }