Release 1.14.1 maven artifact
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / util / AAIConfigTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.aai.util;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
27
28 import java.net.InetAddress;
29 import java.net.UnknownHostException;
30
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.onap.aai.AAISetup;
34 import org.onap.aai.exceptions.AAIException;
35
36 public class AAIConfigTest extends AAISetup {
37
38     @BeforeClass
39     public static void setUp() throws AAIException {
40         AAIConfig.init();
41     }
42
43     @Test
44     public void testGetConfigFile() {
45         String res = AAIConfig.getConfigFile();
46         assertNotNull(res);
47         assertTrue(res.endsWith("aaiconfig.properties"));
48     }
49
50     @Test
51     public void testGetStringString() {
52         String res = AAIConfig.get("aai.notificationEvent.default.sourceName", "somerandomvalue");
53         assertNotNull(res);
54         assertEquals("aai", res);
55     }
56
57     @Test
58     public void testGetStringStringReturnDefaultvalue() {
59         String res = AAIConfig.get("key", "result");
60         assertNotNull(res);
61         assertEquals("result", res);
62     }
63
64     @Test(expected = AAIException.class)
65     public void testGetStringInvalidKey() throws AAIException {
66         AAIConfig.get("key");
67     }
68
69     @Test(expected = AAIException.class)
70     public void testGetStringEmptyResponse() throws AAIException {
71         AAIConfig.get("aai.response.null");
72     }
73
74     @Test
75     public void testGetStringReloadConfig() throws AAIException {
76         String res = AAIConfig.get("aai.config.nodename");
77         assertNotNull(res);
78         assertEquals(AAIConfig.getNodeName(), res);
79     }
80
81     @Test
82     public void testGetStringPassword() throws AAIException {
83         String res = AAIConfig.get("aai.example.passwd");
84         assertNotNull(res);
85         assertEquals("changeit", res);
86     }
87
88     @Test(expected = NumberFormatException.class)
89     public void testGetIntInvalidInput() throws AAIException {
90         AAIConfig.getInt("aai.example.string");
91     }
92
93     @Test
94     public void testGetInt() throws AAIException {
95         int res = AAIConfig.getInt("aai.example.int");
96         assertEquals(7748, res);
97     }
98
99     @Test
100     public void testGetNodeName() throws UnknownHostException {
101         InetAddress ip = InetAddress.getLocalHost();
102         String res = AAIConfig.getNodeName();
103         assertNotNull(res);
104         assertEquals(ip.getHostName(), res);
105     }
106
107     @Test
108     public void testIsEmpty() {
109         boolean res = AAIConfig.isEmpty("hllo world");
110         assertFalse(res);
111     }
112
113     @Test
114     public void testIsEmptyEmpty() {
115         boolean res = AAIConfig.isEmpty("");
116         assertTrue(res);
117     }
118
119     @Test
120     public void testIsEmptyNull() {
121         boolean res = AAIConfig.isEmpty(null);
122         assertTrue(res);
123     }
124
125 }