e3f7833a80d4cd541a6f7ee0a892c7d0947ac294
[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 java.util.concurrent.TimeUnit.SECONDS;
20 import static org.awaitility.Awaitility.await;
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22 import static org.junit.jupiter.api.Assertions.assertTrue;
23
24 import java.io.File;
25 import java.io.FileOutputStream;
26 import java.io.OutputStream;
27 import java.util.HashMap;
28 import java.util.Map;
29 import java.util.Properties;
30 import org.junit.jupiter.api.AfterAll;
31 import org.junit.jupiter.api.Disabled;
32 import org.junit.jupiter.api.Test;
33 import org.onap.config.api.ConfigurationManager;
34 import org.onap.config.impl.CliConfigurationImpl;
35 import org.onap.config.util.ConfigTestConstant;
36 import org.onap.config.util.TestUtil;
37
38 /**
39  * Created by sheetalm on 10/19/2016. Scenario 19 Pre-requisite - set -Dnode.config.location=${"user.home"}/TestResources/ while running test Verify
40  * node specific override using CLI
41  */
42 @Disabled("Investigate instability (random failures)")
43 class NodeSpecificCliTest {
44
45     private static final String NAMESPACE = "NodeCLI";
46     private static final File FILE = new File(TestUtil.jsonSchemaLoc + "config.properties");
47
48     @AfterAll
49     public static void tearDown() throws Exception {
50         TestUtil.cleanUp();
51         if (FILE.exists()) {
52             assertTrue(FILE.delete());
53         }
54     }
55
56     @Test
57     void testCliApi() throws Exception {
58         //Verify without fallback
59         final Map<String, Object> input = new HashMap<>();
60         input.put("ImplClass", "org.onap.config.type.ConfigurationQuery");
61         input.put("namespace", NAMESPACE);
62         input.put("key", ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH);
63
64         final ConfigurationManager conf = new CliConfigurationImpl();
65         final String maxLength = conf.getConfigurationValue(input);
66
67         //Verify Property from Namespace configurations
68         assertEquals("30", maxLength);
69
70         //Add node specific configurations
71         final Properties props = new Properties();
72         props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "50");
73         props.setProperty("_config.namespace", NAMESPACE);
74
75         await().atMost(30, SECONDS).pollInterval(1, SECONDS).until(() -> FILE.exists());
76         try (final OutputStream out = new FileOutputStream(FILE)) {
77             props.store(out, "Node Config Property");
78         }
79
80         //Verify property from node specific configuration
81         input.put("nodeSpecific", true);
82         final String nodeVal = conf.getConfigurationValue(input);
83         assertEquals("30", nodeVal);
84
85         if (FILE.exists()) {
86             assertTrue(FILE.delete());
87         }
88     }
89 }