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;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.onap.aai.AAISetup;
34 import org.onap.aai.exceptions.AAIException;
36 public class AAIConfigTest extends AAISetup {
39 public static void setUp() throws AAIException {
44 public void testGetConfigFile() {
45 String res = AAIConfig.getConfigFile();
47 assertTrue(res.endsWith("aaiconfig.properties"));
51 public void testGetStringString() {
52 String res = AAIConfig.get("aai.notificationEvent.default.sourceName", "somerandomvalue");
54 assertEquals("aai", res);
58 public void testGetStringStringReturnDefaultvalue() {
59 String res = AAIConfig.get("key", "result");
61 assertEquals("result", res);
64 @Test(expected = AAIException.class)
65 public void testGetStringInvalidKey() throws AAIException {
69 @Test(expected = AAIException.class)
70 public void testGetStringEmptyResponse() throws AAIException {
71 AAIConfig.get("aai.response.null");
75 public void testGetStringReloadConfig() throws AAIException {
76 String res = AAIConfig.get("aai.config.nodename");
78 assertEquals(AAIConfig.getNodeName(), res);
82 public void testGetStringPassword() throws AAIException {
83 String res = AAIConfig.get("aai.example.passwd");
85 assertEquals("changeit", res);
88 @Test(expected = NumberFormatException.class)
89 public void testGetIntInvalidInput() throws AAIException {
90 AAIConfig.getInt("aai.example.string");
94 public void testGetInt() throws AAIException {
95 int res = AAIConfig.getInt("aai.example.int");
96 assertEquals(7748, res);
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);