2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 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=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.exceptions;
24 import org.junit.Test;
25 import org.onap.aai.AAISetup;
27 import java.util.HashMap;
29 import static org.junit.Assert.assertEquals;
31 public class AAIExceptionWithInfoTest extends AAISetup {
34 private static final HashMap<String, Object> map = new HashMap<String, Object>();
37 map.put("itemInteger", 1);
38 map.put("itemString", "Two");
39 map.put("itemThree", Boolean.TRUE);
42 private static final String info = "An error has occurred.";
43 private static final String code = "AAI_4004";
44 private static final String details = "This is a detailed description of the exception.";
45 private static final Throwable cause = new RuntimeException("This is a runtime exception.");
48 * Test constructor with 2 params.
50 * @throws Exception the exception
53 public void testConstructorWith2Params() throws Exception {
54 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
56 assertEquals(map, exception.getInfoHash());
57 assertEquals(info, exception.getInfo());
61 * Test constructor with 3 params.
63 * @throws Exception the exception
66 public void testConstructorWith3Params() throws Exception {
67 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, map, info);
69 assertEquals("4004", exception.getErrorObject().getErrorCode());
70 assertEquals(map, exception.getInfoHash());
71 assertEquals(info, exception.getInfo());
75 * Test constructor with 4 params I.
77 * @throws Exception the exception
80 public void testConstructorWith4ParamsI() throws Exception {
81 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, details, map, info);
83 assertEquals("4004", exception.getErrorObject().getErrorCode());
84 assertEquals(details, exception.getMessage());
85 assertEquals(map, exception.getInfoHash());
86 assertEquals(info, exception.getInfo());
90 * Test constructor with 4 params II.
92 * @throws Exception the exception
95 public void testConstructorWith4ParamsII() throws Exception {
96 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, cause, map, info);
98 assertEquals("4004", exception.getErrorObject().getErrorCode());
99 assertEquals(cause.toString(), exception.getMessage());
100 assertEquals(map, exception.getInfoHash());
101 assertEquals(info, exception.getInfo());
105 * Test constructor with 5 params.
107 * @throws Exception the exception
110 public void testConstructorWith5Params() throws Exception {
111 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, cause, details, map, info);
113 assertEquals("4004", exception.getErrorObject().getErrorCode());
114 assertEquals(details, exception.getMessage());
115 assertEquals(map, exception.getInfoHash());
116 assertEquals(info, exception.getInfo());
120 * Test set info hash.
123 public void testSetInfoHash() {
124 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
126 HashMap<String, Object> newMap = new HashMap<String, Object>();
127 newMap.put("itemInteger", 2);
128 exception.setInfoHash(newMap);
130 assertEquals(newMap, exception.getInfoHash());
131 assertEquals(info, exception.getInfo());
138 public void testSetInfo() {
139 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
141 String newInfo = "This is updated info.";
142 exception.setInfo(newInfo);
144 assertEquals(map, exception.getInfoHash());
145 assertEquals(newInfo, exception.getInfo());