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;
25 import java.util.HashMap;
27 import static org.junit.Assert.assertEquals;
29 public class AAIExceptionWithInfoTest {
32 private static final HashMap<String, Object> map = new HashMap<String, Object>();
35 map.put("itemInteger", 1);
36 map.put("itemString", "Two");
37 map.put("itemThree", Boolean.TRUE);
40 private static final String info = "An error has occurred.";
41 private static final String code = "4004";
42 private static final String details = "This is a detailed description of the exception.";
43 private static final Throwable cause = new RuntimeException("This is a runtime exception.");
46 * Test constructor with 2 params.
48 * @throws Exception the exception
51 public void testConstructorWith2Params() throws Exception {
52 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
54 assertEquals(map, exception.getInfoHash());
55 assertEquals(info, exception.getInfo());
59 * Test constructor with 3 params.
61 * @throws Exception the exception
64 public void testConstructorWith3Params() throws Exception {
65 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, map, info);
67 assertEquals(code, exception.getErrorObject().getErrorCode());
68 assertEquals(map, exception.getInfoHash());
69 assertEquals(info, exception.getInfo());
73 * Test constructor with 4 params I.
75 * @throws Exception the exception
78 public void testConstructorWith4ParamsI() throws Exception {
79 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, details, map, info);
81 assertEquals(code, exception.getErrorObject().getErrorCode());
82 assertEquals(details, exception.getMessage());
83 assertEquals(map, exception.getInfoHash());
84 assertEquals(info, exception.getInfo());
88 * Test constructor with 4 params II.
90 * @throws Exception the exception
93 public void testConstructorWith4ParamsII() throws Exception {
94 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, cause, map, info);
96 assertEquals(code, exception.getErrorObject().getErrorCode());
97 assertEquals(cause.getMessage(), exception.getMessage());
98 assertEquals(map, exception.getInfoHash());
99 assertEquals(info, exception.getInfo());
103 * Test constructor with 5 params.
105 * @throws Exception the exception
108 public void testConstructorWith5Params() throws Exception {
109 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, cause, details, map, info);
111 assertEquals(code, exception.getErrorObject().getErrorCode());
112 assertEquals(cause.getMessage() + "-" + details, exception.getMessage());
113 assertEquals(map, exception.getInfoHash());
114 assertEquals(info, exception.getInfo());
118 * Test set info hash.
121 public void testSetInfoHash() {
122 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
124 HashMap<String, Object> newMap = new HashMap<String, Object>();
125 newMap.put("itemInteger", 2);
126 exception.setInfoHash(newMap);
128 assertEquals(newMap, exception.getInfoHash());
129 assertEquals(info, exception.getInfo());
136 public void testSetInfo() {
137 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
139 String newInfo = "This is updated info.";
140 exception.setInfo(newInfo);
142 assertEquals(map, exception.getInfoHash());
143 assertEquals(newInfo, exception.getInfo());