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