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