2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.openecomp.aai.exceptions;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
26 import java.util.HashMap;
28 import static org.junit.Assert.assertEquals;
30 public class AAIExceptionWithInfoTest {
33 private static final HashMap<String, Object> map = new HashMap<String, Object>();
36 map.put("itemInteger", 1);
37 map.put("itemString", "Two");
38 map.put("itemThree", Boolean.TRUE);
41 private static final String info = "An error has occurred.";
42 private static final String code = "AAI_4004";
43 private static final String details = "This is a detailed description of the exception.";
44 private static final Throwable cause = new RuntimeException("This is a runtime exception.");
47 public static void configure() {
48 System.setProperty("AJSC_HOME", "./src/test/resources/");
49 System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
53 * Test constructor with 2 params.
55 * @throws Exception the exception
58 public void testConstructorWith2Params() throws Exception {
59 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
61 assertEquals(map, exception.getInfoHash());
62 assertEquals(info, exception.getInfo());
66 * Test constructor with 3 params.
68 * @throws Exception the exception
71 public void testConstructorWith3Params() throws Exception {
72 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, map, info);
74 assertEquals("4004", exception.getErrorObject().getErrorCode());
75 assertEquals(map, exception.getInfoHash());
76 assertEquals(info, exception.getInfo());
80 * Test constructor with 4 params I.
82 * @throws Exception the exception
85 public void testConstructorWith4ParamsI() throws Exception {
86 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, details, map, info);
88 assertEquals("4004", exception.getErrorObject().getErrorCode());
89 assertEquals(details, exception.getMessage());
90 assertEquals(map, exception.getInfoHash());
91 assertEquals(info, exception.getInfo());
95 * Test constructor with 4 params II.
97 * @throws Exception the exception
100 public void testConstructorWith4ParamsII() throws Exception {
101 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, cause, map, info);
103 assertEquals("4004", exception.getErrorObject().getErrorCode());
104 assertEquals(cause.toString(), exception.getMessage());
105 assertEquals(map, exception.getInfoHash());
106 assertEquals(info, exception.getInfo());
110 * Test constructor with 5 params.
112 * @throws Exception the exception
115 public void testConstructorWith5Params() throws Exception {
116 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, cause, details, map, info);
118 assertEquals("4004", exception.getErrorObject().getErrorCode());
119 assertEquals(details, exception.getMessage());
120 assertEquals(map, exception.getInfoHash());
121 assertEquals(info, exception.getInfo());
125 * Test set info hash.
128 public void testSetInfoHash() {
129 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
131 HashMap<String, Object> newMap = new HashMap<String, Object>();
132 newMap.put("itemInteger", 2);
133 exception.setInfoHash(newMap);
135 assertEquals(newMap, exception.getInfoHash());
136 assertEquals(info, exception.getInfo());
143 public void testSetInfo() {
144 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
146 String newInfo = "This is updated info.";
147 exception.setInfo(newInfo);
149 assertEquals(map, exception.getInfoHash());
150 assertEquals(newInfo, exception.getInfo());