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=========================================================
21 package org.onap.aai.util;
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;
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;
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;
41 public class AAIConfigTest extends AAISetup {
44 public static void setUp() throws AAIException {
49 public void testGetConfigFile() {
50 String res = AAIConfig.getConfigFile();
52 assertTrue(res.endsWith("aaiconfig.properties"));
56 public void testGetStringString() {
57 String res = AAIConfig.get("aai.notificationEvent.default.sourceName", "somerandomvalue");
59 assertEquals("aai", res);
63 public void testGetStringStringReturnDefaultvalue() {
64 String res = AAIConfig.get("key", "result");
66 assertEquals("result", res);
69 @Test(expected = AAIException.class)
70 public void testGetStringInvalidKey() throws AAIException {
74 @Test(expected = AAIException.class)
75 public void testGetStringEmptyResponse() throws AAIException {
76 AAIConfig.get("aai.response.null");
80 public void testGetStringReloadConfig() throws AAIException {
81 String res = AAIConfig.get("aai.config.nodename");
83 assertEquals(AAIConfig.getNodeName(), res);
87 public void testGetStringPassword() throws AAIException {
88 String res = AAIConfig.get("aai.example.passwd");
90 assertEquals("changeit", res);
93 @Test(expected = NumberFormatException.class)
94 public void testGetIntInvalidInput() throws AAIException {
95 AAIConfig.getInt("aai.example.string");
99 public void testGetInt() throws AAIException {
100 int res = AAIConfig.getInt("aai.example.int");
102 assertEquals(7748, res);
106 public void testGetNodeName() throws UnknownHostException {
107 InetAddress ip = InetAddress.getLocalHost();
108 String res = AAIConfig.getNodeName();
110 assertEquals(ip.getHostName(), res);
114 public void testIsEmpty() {
115 boolean res = AAIConfig.isEmpty("hllo world");
120 public void testIsEmptyEmpty() {
121 boolean res = AAIConfig.isEmpty("");
126 public void testIsEmptyNull() {
127 boolean res = AAIConfig.isEmpty(null);