Removed below sonar issues:
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / exceptions / AAIExceptionWithInfoTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.exceptions;
23
24 import org.junit.Test;
25 import org.onap.aai.AAISetup;
26
27 import java.util.HashMap;
28
29 import static org.junit.Assert.assertEquals;
30
31 public class AAIExceptionWithInfoTest extends AAISetup {
32
33         
34         private static final HashMap<String, Object> map = new HashMap<String, Object>();
35
36         {
37                 map.put("itemInteger", 1);
38                 map.put("itemString", "Two");
39                 map.put("itemThree", Boolean.TRUE);
40         }
41
42         private static final String info = "An error has occurred.";
43         private static final String code = "AAI_4004";
44         private static final String details = "This is a detailed description of the exception.";
45         private static final Throwable cause = new RuntimeException("This is a runtime exception.");
46
47         /**
48          * Test constructor with 2 params.
49          *
50          * @throws Exception the exception
51          */
52         @Test
53         public void testConstructorWith2Params() throws Exception {
54                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
55
56                 assertEquals(map, exception.getInfoHash());
57                 assertEquals(info, exception.getInfo());
58         }
59
60         /**
61          * Test constructor with 3 params.
62          *
63          * @throws Exception the exception
64          */
65         @Test
66         public void testConstructorWith3Params() throws Exception {
67                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, map, info);
68
69                 assertEquals("4004", exception.getErrorObject().getErrorCode());
70                 assertEquals(map, exception.getInfoHash());
71                 assertEquals(info, exception.getInfo());
72         }
73
74         /**
75          * Test constructor with 4 params I.
76          *
77          * @throws Exception the exception
78          */
79         @Test
80         public void testConstructorWith4ParamsI() throws Exception {
81                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, details, map, info);
82
83                 assertEquals("4004", exception.getErrorObject().getErrorCode());
84                 assertEquals(details, exception.getMessage());
85                 assertEquals(map, exception.getInfoHash());
86                 assertEquals(info, exception.getInfo());
87         }
88
89         /**
90          * Test constructor with 4 params II.
91          *
92          * @throws Exception the exception
93          */
94         @Test
95         public void testConstructorWith4ParamsII() throws Exception {
96                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, cause, map, info);
97
98                 assertEquals("4004", exception.getErrorObject().getErrorCode());
99                 assertEquals(cause.toString(), exception.getMessage());
100                 assertEquals(map, exception.getInfoHash());
101                 assertEquals(info, exception.getInfo());
102         }
103
104         /**
105          * Test constructor with 5 params.
106          *
107          * @throws Exception the exception
108          */
109         @Test
110         public void testConstructorWith5Params() throws Exception {
111                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(code, cause, details, map, info);
112
113                 assertEquals("4004", exception.getErrorObject().getErrorCode());
114                 assertEquals(details, exception.getMessage());
115                 assertEquals(map, exception.getInfoHash());
116                 assertEquals(info, exception.getInfo());
117         }
118
119         /**
120          * Test set info hash.
121          */
122         @Test
123         public void testSetInfoHash() {
124                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
125
126                 HashMap<String, Object> newMap = new HashMap<String, Object>();
127                 newMap.put("itemInteger", 2);
128                 exception.setInfoHash(newMap);
129                 
130                 assertEquals(newMap, exception.getInfoHash());
131                 assertEquals(info, exception.getInfo());
132         }
133         
134         /**
135          * Test set info.
136          */
137         @Test
138         public void testSetInfo() {
139                 AAIExceptionWithInfo exception = new AAIExceptionWithInfo(map, info);
140
141                 String newInfo = "This is updated info.";
142                 exception.setInfo(newInfo);
143                 
144                 assertEquals(map, exception.getInfoHash());
145                 assertEquals(newInfo, exception.getInfo());
146         }
147
148 }