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.Test;
24 import org.openecomp.aai.AAISetup;
26 import java.util.HashMap;
28 import static org.junit.Assert.assertEquals;
30 public class AAIExceptionWithInfoTest extends AAISetup {
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 * Test constructor with 2 params.
49 * @throws Exception the exception
52 public void testConstructorWith2Params() throws Exception {
53 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
55 assertEquals(map, exception.getInfoHash());
56 assertEquals(info, exception.getInfo());
60 * Test constructor with 3 params.
62 * @throws Exception the exception
65 public void testConstructorWith3Params() throws Exception {
66 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, map, info);
68 assertEquals("4004", exception.getErrorObject().getErrorCode());
69 assertEquals(map, exception.getInfoHash());
70 assertEquals(info, exception.getInfo());
74 * Test constructor with 4 params I.
76 * @throws Exception the exception
79 public void testConstructorWith4ParamsI() throws Exception {
80 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, details, map, info);
82 assertEquals("4004", exception.getErrorObject().getErrorCode());
83 assertEquals(details, exception.getMessage());
84 assertEquals(map, exception.getInfoHash());
85 assertEquals(info, exception.getInfo());
89 * Test constructor with 4 params II.
91 * @throws Exception the exception
94 public void testConstructorWith4ParamsII() throws Exception {
95 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, cause, map, info);
97 assertEquals("4004", exception.getErrorObject().getErrorCode());
98 assertEquals(cause.toString(), exception.getMessage());
99 assertEquals(map, exception.getInfoHash());
100 assertEquals(info, exception.getInfo());
104 * Test constructor with 5 params.
106 * @throws Exception the exception
109 public void testConstructorWith5Params() throws Exception {
110 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, cause, details, map, info);
112 assertEquals("4004", exception.getErrorObject().getErrorCode());
113 assertEquals(details, exception.getMessage());
114 assertEquals(map, exception.getInfoHash());
115 assertEquals(info, exception.getInfo());
119 * Test set info hash.
122 public void testSetInfoHash() {
123 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
125 HashMap<String, Object> newMap = new HashMap<String, Object>();
126 newMap.put("itemInteger", 2);
127 exception.setInfoHash(newMap);
129 assertEquals(newMap, exception.getInfoHash());
130 assertEquals(info, exception.getInfo());
137 public void testSetInfo() {
138 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
140 String newInfo = "This is updated info.";
141 exception.setInfo(newInfo);
143 assertEquals(map, exception.getInfoHash());
144 assertEquals(newInfo, exception.getInfo());