2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.aai.util;
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;
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;
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;
39 public class AAIConfigTest extends AAISetup {
42 public static void setUp() throws AAIException {
47 public void testGetDefaultBools() {
48 HashMap<String,ArrayList<String>> res = AAIConfig.getDefaultBools();
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));
63 public void testGetConfigFile() {
64 String res = AAIConfig.getConfigFile();
66 assertTrue(res.endsWith("aaiconfig.properties"));
70 public void testGetStringStringReturnDefaultvalue() {
71 String res = AAIConfig.get("key", "result");
73 assertEquals("result", res);
76 @Test(expected = AAIException.class)
77 public void testGetStringInvalidKey() throws AAIException {
81 @Test(expected = AAIException.class)
82 public void testGetStringEmptyResponse() throws AAIException {
83 AAIConfig.get("aai.response.null");
87 public void testGetStringReloadConfig() throws AAIException {
88 String res = AAIConfig.get("aai.config.nodename");
90 assertEquals(AAIConfig.getNodeName(), res);
94 public void testGetServerProps() {
95 Properties res = AAIConfig.getServerProps();
100 public void testGetNodeName() throws UnknownHostException {
101 InetAddress ip = InetAddress.getLocalHost();
102 String res = AAIConfig.getNodeName();
104 assertEquals(ip.getHostName(), res);
108 public void testIsEmpty() {
109 boolean res = AAIConfig.isEmpty("hllo world");
114 public void testIsEmptyEmpty() {
115 boolean res = AAIConfig.isEmpty("");
120 public void testIsEmptyNull() {
121 boolean res = AAIConfig.isEmpty(null);