c12128337b82310f2c533e2cc869dfe652464332
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.test;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertTrue;
27 import java.io.File;
28
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
33 import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section;
34 import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section.EnvGetter;
35 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.EsConfig;
36 import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataProviderConfig;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40 public class TestConfig {
41
42     private static final Logger LOG = LoggerFactory.getLogger(TestConfig.class);
43
44     private static final String TESTFILENAME = "testconfig.properties";
45     private static String ENVSDNRDBURL = "SDNRDBURL";
46     private static String ENVSDNRDBENABLED = "SDNRDBENABLED";
47     private static String SDNRDBURL = "http://sdnrdb:9200";
48
49     @After
50     @Before
51     public void afterAndBefore() {
52         File f = new File(TESTFILENAME);
53         if (f.exists()) {
54             LOG.info("Remove {}", f.getAbsolutePath());
55             f.delete();
56         }
57     }
58
59     @Test
60     public void test() {
61         EnvGetter env = Section.getEnvGetter();
62         Section.setEnvGetter((envname) -> {
63             return envname.equals(ENVSDNRDBURL) ? SDNRDBURL : env.getenv(envname);
64         });
65         ConfigurationFileRepresentation configuration = new ConfigurationFileRepresentation(TESTFILENAME);
66         DataProviderConfig dbConfig = new DataProviderConfig(configuration);
67         EsConfig esConfig = dbConfig.getEsConfig();
68         LOG.info("Defaultconfiguration: {}", esConfig.toString());
69         assertEquals("http", esConfig.getHosts()[0].protocol.getValue());
70         assertEquals(9200, esConfig.getHosts()[0].port);
71         assertEquals("sdnrdb", esConfig.getHosts()[0].hostname);
72         assertTrue(dbConfig.isEnabled());
73         Section.setEnvGetter((envname) -> {
74             return envname.equals(ENVSDNRDBENABLED) ? "false" : env.getenv(envname);
75         });
76         assertFalse(dbConfig.isEnabled());
77         
78     }
79 }