cba17397684681a3dee15833ef654753710dd252
[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     + "[ERROR]   NodeSpecificCliTest.testCliApi:73 » FileNotFound /home/jenkins/TestResources/c...")
44 class NodeSpecificCliTest {
45
46     private static final String NAMESPACE = "NodeCLI";
47     private static final File FILE = new File(TestUtil.jsonSchemaLoc + "config.properties");
48
49     @AfterAll
50     public static void tearDown() throws Exception {
51         TestUtil.cleanUp();
52         if (FILE.exists()) {
53             assertTrue(FILE.delete());
54         }
55     }
56
57     @Test
58     void testCliApi() throws Exception {
59         //Verify without fallback
60         final Map<String, Object> input = new HashMap<>();
61         input.put("ImplClass", "org.onap.config.type.ConfigurationQuery");
62         input.put("namespace", NAMESPACE);
63         input.put("key", ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH);
64
65         final ConfigurationManager conf = new CliConfigurationImpl();
66         final String maxLength = conf.getConfigurationValue(input);
67
68         //Verify Property from Namespace configurations
69         assertEquals("30", maxLength);
70
71         //Add node specific configurations
72         final Properties props = new Properties();
73         props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "50");
74         props.setProperty("_config.namespace", NAMESPACE);
75
76         await().atMost(30, SECONDS).pollInterval(1, SECONDS).until(() -> FILE.exists());
77         try (final OutputStream out = new FileOutputStream(FILE)) {
78             props.store(out, "Node Config Property");
79         }
80
81         //Verify property from node specific configuration
82         input.put("nodeSpecific", true);
83         final String nodeVal = conf.getConfigurationValue(input);
84         assertEquals("30", nodeVal);
85
86         if (FILE.exists()) {
87             assertTrue(FILE.delete());
88         }
89     }
90 }