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;
25 import org.openecomp.aai.serialization.queryformats.QueryFormatTestHelper;
26 import org.openecomp.aai.util.AAIConstants;
28 import java.util.HashMap;
30 import static org.junit.Assert.assertEquals;
32 public class AAIExceptionWithInfoTest {
35 private static final HashMap<String, Object> map = new HashMap<String, Object>();
38 map.put("itemInteger", 1);
39 map.put("itemString", "Two");
40 map.put("itemThree", Boolean.TRUE);
43 private static final String info = "An error has occurred.";
44 private static final String code = "AAI_4004";
45 private static final String details = "This is a detailed description of the exception.";
46 private static final Throwable cause = new RuntimeException("This is a runtime exception.");
49 public static void configure() throws NoSuchFieldException, SecurityException, Exception {
50 System.setProperty("AJSC_HOME", ".");
51 System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
52 QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/org/openecomp/aai/introspection/");
56 * Test constructor with 2 params.
58 * @throws Exception the exception
61 public void testConstructorWith2Params() throws Exception {
62 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
64 assertEquals(map, exception.getInfoHash());
65 assertEquals(info, exception.getInfo());
69 * Test constructor with 3 params.
71 * @throws Exception the exception
74 public void testConstructorWith3Params() throws Exception {
75 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, map, info);
77 assertEquals("4004", exception.getErrorObject().getErrorCode());
78 assertEquals(map, exception.getInfoHash());
79 assertEquals(info, exception.getInfo());
83 * Test constructor with 4 params I.
85 * @throws Exception the exception
88 public void testConstructorWith4ParamsI() throws Exception {
89 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, details, map, info);
91 assertEquals("4004", exception.getErrorObject().getErrorCode());
92 assertEquals(details, exception.getMessage());
93 assertEquals(map, exception.getInfoHash());
94 assertEquals(info, exception.getInfo());
98 * Test constructor with 4 params II.
100 * @throws Exception the exception
103 public void testConstructorWith4ParamsII() throws Exception {
104 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, cause, map, info);
106 assertEquals("4004", exception.getErrorObject().getErrorCode());
107 assertEquals(cause.toString(), exception.getMessage());
108 assertEquals(map, exception.getInfoHash());
109 assertEquals(info, exception.getInfo());
113 * Test constructor with 5 params.
115 * @throws Exception the exception
118 public void testConstructorWith5Params() throws Exception {
119 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, cause, details, map, info);
121 assertEquals("4004", exception.getErrorObject().getErrorCode());
122 assertEquals(details, exception.getMessage());
123 assertEquals(map, exception.getInfoHash());
124 assertEquals(info, exception.getInfo());
128 * Test set info hash.
131 public void testSetInfoHash() {
132 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
134 HashMap<String, Object> newMap = new HashMap<String, Object>();
135 newMap.put("itemInteger", 2);
136 exception.setInfoHash(newMap);
138 assertEquals(newMap, exception.getInfoHash());
139 assertEquals(info, exception.getInfo());
146 public void testSetInfo() {
147 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
149 String newInfo = "This is updated info.";
150 exception.setInfo(newInfo);
152 assertEquals(map, exception.getInfoHash());
153 assertEquals(newInfo, exception.getInfo());