Initial commit with all the necessary files
[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.Test;
24
25 import java.util.HashMap;
26
27 import static org.junit.Assert.assertEquals;
28
29 public class AAIExceptionWithInfoTest {
30
31         
32         private static final HashMap<String, Object> map = new HashMap<String, Object>();
33
34         {
35                 map.put("itemInteger", 1);
36                 map.put("itemString", "Two");
37                 map.put("itemThree", Boolean.TRUE);
38         }
39
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.");
44
45         /**
46          * Test constructor with 2 params.
47          *
48          * @throws Exception the exception
49          */
50         @Test
51         public void testConstructorWith2Params() throws Exception {
52                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
53
54                 assertEquals(map, exception.getInfoHash());
55                 assertEquals(info, exception.getInfo());
56         }
57
58         /**
59          * Test constructor with 3 params.
60          *
61          * @throws Exception the exception
62          */
63         @Test
64         public void testConstructorWith3Params() throws Exception {
65                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, map, info);
66
67                 assertEquals(code, exception.getErrorObject().getErrorCode());
68                 assertEquals(map, exception.getInfoHash());
69                 assertEquals(info, exception.getInfo());
70         }
71
72         /**
73          * Test constructor with 4 params I.
74          *
75          * @throws Exception the exception
76          */
77         @Test
78         public void testConstructorWith4ParamsI() throws Exception {
79                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, details, map, info);
80
81                 assertEquals(code, exception.getErrorObject().getErrorCode());
82                 assertEquals(details, exception.getMessage());
83                 assertEquals(map, exception.getInfoHash());
84                 assertEquals(info, exception.getInfo());
85         }
86
87         /**
88          * Test constructor with 4 params II.
89          *
90          * @throws Exception the exception
91          */
92         @Test
93         public void testConstructorWith4ParamsII() throws Exception {
94                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, cause, map, info);
95
96                 assertEquals(code, exception.getErrorObject().getErrorCode());
97                 assertEquals(cause.getMessage(), exception.getMessage());
98                 assertEquals(map, exception.getInfoHash());
99                 assertEquals(info, exception.getInfo());
100         }
101
102         /**
103          * Test constructor with 5 params.
104          *
105          * @throws Exception the exception
106          */
107         @Test
108         public void testConstructorWith5Params() throws Exception {
109                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, cause, details, map, info);
110
111                 assertEquals(code, exception.getErrorObject().getErrorCode());
112                 assertEquals(cause.getMessage() + "-" + details, exception.getMessage());
113                 assertEquals(map, exception.getInfoHash());
114                 assertEquals(info, exception.getInfo());
115         }
116
117         /**
118          * Test set info hash.
119          */
120         @Test
121         public void testSetInfoHash() {
122                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
123
124                 HashMap<String, Object> newMap = new HashMap<String, Object>();
125                 newMap.put("itemInteger", 2);
126                 exception.setInfoHash(newMap);
127                 
128                 assertEquals(newMap, exception.getInfoHash());
129                 assertEquals(info, exception.getInfo());
130         }
131         
132         /**
133          * Test set info.
134          */
135         @Test
136         public void testSetInfo() {
137                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
138
139                 String newInfo = "This is updated info.";
140                 exception.setInfo(newInfo);
141                 
142                 assertEquals(map, exception.getInfoHash());
143                 assertEquals(newInfo, exception.getInfo());
144         }
145
146 }