2d4a3651598716bb3c730a65ec8b9e5e5a82af98
[aai/sparky-be.git] / sparkybe-onap-service / src / test / java / org / onap / aai / sparky / util / ConfigHelperTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
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.aai.sparky.util;
23
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.hamcrest.MatcherAssert.assertThat;
27 import java.io.File;
28 import java.io.IOException;
29 import java.nio.file.FileSystems;
30 import java.util.Properties;
31
32 import org.junit.Before;
33 import org.junit.Test;
34 import static org.junit.Assert.assertEquals;
35 public class ConfigHelperTest {
36
37   private ConfigHelper configHelper;
38   private Properties props;
39
40   @Before
41   public void init() throws Exception {
42     configHelper = new ConfigHelper();
43     props = new Properties();
44
45   }
46
47   @SuppressWarnings("static-access")
48   @Test
49   public void updateValues() throws Exception {
50
51     assertNotNull(configHelper.getConfigWithPrefix("aai-ui", props));
52     assertFalse(configHelper.isEssDevModeEnabled());
53     assertNotNull(configHelper.getFilepath("sparky-aaui", false));
54
55   }
56
57   @Test
58   public void getFileContents() {
59     File file = new File(getClass().getClassLoader().getResource("configHelperTest.properties").getFile());
60     try {
61       assertNotNull(ConfigHelper.getFileContents(file.getAbsolutePath()));
62     } catch (IOException e) {
63       e.printStackTrace();
64     }
65   }
66
67   @Test
68   public void loadConfig() throws Exception {
69     String separator = FileSystems.getDefault().getSeparator();
70     assertEquals(3, ConfigHelper.loadConfig("target"+separator+"test-classes"+separator+"configHelperTest.properties").size());
71   }
72
73   @Test
74   public void propertyFetch() throws Exception {
75     Properties p=new Properties();
76     p.setProperty("key1","value1");
77     assertEquals(ConfigHelper.propertyFetch(p,"key1","value2"),"value1");
78     assertEquals(ConfigHelper.propertyFetch(p,"key2","value2"),"value2");
79   }
80 }