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.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;
40 public class AAIConfigTest extends AAISetup {
43 public static void setUp() throws AAIException {
48 public void testGetConfigFile() {
49 String res = AAIConfig.getConfigFile();
51 assertTrue(res.endsWith("aaiconfig.properties"));
55 public void testGetStringString() {
56 String res = AAIConfig.get("aai.notificationEvent.default.sourceName", "somerandomvalue");
58 assertEquals("aai", res);
62 public void testGetStringStringReturnDefaultvalue() {
63 String res = AAIConfig.get("key", "result");
65 assertEquals("result", res);
68 @Test(expected = AAIException.class)
69 public void testGetStringInvalidKey() throws AAIException {
73 @Test(expected = AAIException.class)
74 public void testGetStringEmptyResponse() throws AAIException {
75 AAIConfig.get("aai.response.null");
79 public void testGetStringReloadConfig() throws AAIException {
80 String res = AAIConfig.get("aai.config.nodename");
82 assertEquals(AAIConfig.getNodeName(), res);
86 public void testGetStringPassword() throws AAIException {
87 String res = AAIConfig.get("aai.example.passwd");
89 assertEquals("changeit", res);
92 @Test(expected=NumberFormatException.class)
93 public void testGetIntInvalidInput() throws AAIException {
94 AAIConfig.getInt("aai.example.string");
98 public void testGetInt() throws AAIException {
99 int res = AAIConfig.getInt("aai.example.int");
101 assertEquals(7748, res);
105 public void testGetNodeName() throws UnknownHostException {
106 InetAddress ip = InetAddress.getLocalHost();
107 String res = AAIConfig.getNodeName();
109 assertEquals(ip.getHostName(), res);
113 public void testIsEmpty() {
114 boolean res = AAIConfig.isEmpty("hllo world");
119 public void testIsEmptyEmpty() {
120 boolean res = AAIConfig.isEmpty("");
125 public void testIsEmptyNull() {
126 boolean res = AAIConfig.isEmpty(null);