65381d642391906639db4d98f4a2d01cd9acbd5f
[aai/aai-common.git] / aai-core / src / test / java / org / openecomp / aai / exceptions / AAIExceptionWithInfoTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.openecomp.aai
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.aai.exceptions;
22
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25
26 import java.util.HashMap;
27
28 import static org.junit.Assert.assertEquals;
29
30 public class AAIExceptionWithInfoTest {
31
32         
33         private static final HashMap<String, Object> map = new HashMap<String, Object>();
34
35         {
36                 map.put("itemInteger", 1);
37                 map.put("itemString", "Two");
38                 map.put("itemThree", Boolean.TRUE);
39         }
40
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.");
45
46         @BeforeClass
47         public static void configure() {
48                 System.setProperty("AJSC_HOME", "./src/test/resources/");
49                 System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
50         }
51
52         /**
53          * Test constructor with 2 params.
54          *
55          * @throws Exception the exception
56          */
57         @Test
58         public void testConstructorWith2Params() throws Exception {
59                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
60
61                 assertEquals(map, exception.getInfoHash());
62                 assertEquals(info, exception.getInfo());
63         }
64
65         /**
66          * Test constructor with 3 params.
67          *
68          * @throws Exception the exception
69          */
70         @Test
71         public void testConstructorWith3Params() throws Exception {
72                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, map, info);
73
74                 assertEquals("4004", exception.getErrorObject().getErrorCode());
75                 assertEquals(map, exception.getInfoHash());
76                 assertEquals(info, exception.getInfo());
77         }
78
79         /**
80          * Test constructor with 4 params I.
81          *
82          * @throws Exception the exception
83          */
84         @Test
85         public void testConstructorWith4ParamsI() throws Exception {
86                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, details, map, info);
87
88                 assertEquals("4004", exception.getErrorObject().getErrorCode());
89                 assertEquals(details, exception.getMessage());
90                 assertEquals(map, exception.getInfoHash());
91                 assertEquals(info, exception.getInfo());
92         }
93
94         /**
95          * Test constructor with 4 params II.
96          *
97          * @throws Exception the exception
98          */
99         @Test
100         public void testConstructorWith4ParamsII() throws Exception {
101                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, cause, map, info);
102
103                 assertEquals("4004", exception.getErrorObject().getErrorCode());
104                 assertEquals(cause.toString(), exception.getMessage());
105                 assertEquals(map, exception.getInfoHash());
106                 assertEquals(info, exception.getInfo());
107         }
108
109         /**
110          * Test constructor with 5 params.
111          *
112          * @throws Exception the exception
113          */
114         @Test
115         public void testConstructorWith5Params() throws Exception {
116                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, cause, details, map, info);
117
118                 assertEquals("4004", exception.getErrorObject().getErrorCode());
119                 assertEquals(details, exception.getMessage());
120                 assertEquals(map, exception.getInfoHash());
121                 assertEquals(info, exception.getInfo());
122         }
123
124         /**
125          * Test set info hash.
126          */
127         @Test
128         public void testSetInfoHash() {
129                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
130
131                 HashMap<String, Object> newMap = new HashMap<String, Object>();
132                 newMap.put("itemInteger", 2);
133                 exception.setInfoHash(newMap);
134                 
135                 assertEquals(newMap, exception.getInfoHash());
136                 assertEquals(info, exception.getInfo());
137         }
138         
139         /**
140          * Test set info.
141          */
142         @Test
143         public void testSetInfo() {
144                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
145
146                 String newInfo = "This is updated info.";
147                 exception.setInfo(newInfo);
148                 
149                 assertEquals(map, exception.getInfoHash());
150                 assertEquals(newInfo, exception.getInfo());
151         }
152
153 }