Add plugin to check coverage
[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.junit.AfterClass;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
36 import org.onap.aai.AAISetup;
37 import org.onap.aai.exceptions.AAIException;
38
39 public class AAIConfigTest extends AAISetup {
40
41         @BeforeClass
42         public static void setUp() throws AAIException {
43                 AAIConfig.init();
44         }
45
46         @Test
47         public void testGetDefaultBools() {
48                 HashMap<String,ArrayList<String>> res = AAIConfig.getDefaultBools();
49                 assertNotNull(res);
50                 assertEquals(6, res.size());
51                 assertEquals("in-maint", res.get("generic-vnf").get(0));
52                 assertEquals("is-closed-loop-disabled", res.get("generic-vnf").get(1));
53                 assertEquals("is-bound-to-vpn", res.get("l3-network").get(0));
54                 assertEquals("in-maint", res.get("pserver").get(0));
55                 assertEquals("dhcp-enabled", res.get("subnet").get(0));
56                 assertEquals("in-maint", res.get("vserver").get(0));
57                 assertEquals("is-closed-loop-disabled", res.get("vserver").get(1));
58                 assertEquals("in-maint", res.get("vnfc").get(0));
59                 assertEquals("is-closed-loop-disabled", res.get("vnfc").get(1));
60         }
61
62         @Test
63         public void testGetConfigFile() {
64                 String res = AAIConfig.getConfigFile();
65                 assertNotNull(res);
66                 assertTrue(res.endsWith("aaiconfig.properties"));
67         }
68
69         @Test
70         public void testGetStringStringReturnDefaultvalue() {
71                 String res = AAIConfig.get("key", "result");
72                 assertNotNull(res);
73                 assertEquals("result", res);
74         }
75
76         @Test(expected = AAIException.class)
77         public void testGetStringInvalidKey() throws AAIException {
78                 AAIConfig.get("key");
79         }
80
81         @Test(expected = AAIException.class)
82         public void testGetStringEmptyResponse() throws AAIException {
83                 AAIConfig.get("aai.response.null");
84         }
85
86         @Test
87         public void testGetStringReloadConfig() throws AAIException {
88                 String res = AAIConfig.get("aai.config.nodename");
89                 assertNotNull(res);
90                 assertEquals(AAIConfig.getNodeName(), res);
91         }
92
93         @Test
94         public void testGetServerProps() {
95                 Properties res = AAIConfig.getServerProps();
96                 assertNotNull(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 }