51acdb744969cc52e0573fe7b2b80e9b7595cf60
[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 package org.onap.aai.util;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26
27 import java.net.InetAddress;
28 import java.net.UnknownHostException;
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import java.util.Properties;
32
33 import org.eclipse.jetty.util.security.Password;
34 import org.junit.AfterClass;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
37 import org.onap.aai.AAISetup;
38 import org.onap.aai.exceptions.AAIException;
39
40 public class AAIConfigTest extends AAISetup {
41
42         @BeforeClass
43         public static void setUp() throws AAIException {
44                 AAIConfig.init();
45         }
46
47         @Test
48         public void testGetConfigFile() {
49                 String res = AAIConfig.getConfigFile();
50                 assertNotNull(res);
51                 assertTrue(res.endsWith("aaiconfig.properties"));
52         }
53
54         @Test
55         public void testGetStringString() {
56                 String res = AAIConfig.get("aai.notificationEvent.default.sourceName", "somerandomvalue");
57                 assertNotNull(res);
58                 assertEquals("aai", res);
59         }
60
61         @Test
62         public void testGetStringStringReturnDefaultvalue() {
63                 String res = AAIConfig.get("key", "result");
64                 assertNotNull(res);
65                 assertEquals("result", res);
66         }
67
68         @Test(expected = AAIException.class)
69         public void testGetStringInvalidKey() throws AAIException {
70                 AAIConfig.get("key");
71         }
72
73         @Test(expected = AAIException.class)
74         public void testGetStringEmptyResponse() throws AAIException {
75                 AAIConfig.get("aai.response.null");
76         }
77
78         @Test
79         public void testGetStringReloadConfig() throws AAIException {
80                 String res = AAIConfig.get("aai.config.nodename");
81                 assertNotNull(res);
82                 assertEquals(AAIConfig.getNodeName(), res);
83         }
84
85         @Test
86         public void testGetStringPassword() throws AAIException {
87                 String res = AAIConfig.get("aai.example.passwd");
88                 assertNotNull(res);
89                 assertEquals("changeit", res);
90         }
91
92         @Test(expected=NumberFormatException.class)
93         public void testGetIntInvalidInput() throws AAIException {
94                 AAIConfig.getInt("aai.example.string");
95         }
96
97         @Test
98         public void testGetInt() throws AAIException {
99                 int res = AAIConfig.getInt("aai.example.int");
100                 assertNotNull(res);
101                 assertEquals(7748, res);
102         }
103
104         @Test
105         public void testGetNodeName() throws UnknownHostException {
106                 InetAddress ip = InetAddress.getLocalHost();
107                 String res = AAIConfig.getNodeName();
108                 assertNotNull(res);
109                 assertEquals(ip.getHostName(), res);
110         }
111
112         @Test
113         public void testIsEmpty() {
114                 boolean res = AAIConfig.isEmpty("hllo world");
115                 assertFalse(res);
116         }
117
118         @Test
119         public void testIsEmptyEmpty() {
120                 boolean res = AAIConfig.isEmpty("");
121                 assertTrue(res);
122         }
123
124         @Test
125         public void testIsEmptyNull() {
126                 boolean res = AAIConfig.isEmpty(null);
127                 assertTrue(res);
128         }
129
130 }