84284ec507fc73e4ecb04748703a42180c2a51ab
[aai/aai-common.git] / aai-els-onap-logging / src / test / java / org / onap / aai / exceptions / AAIExceptionWithInfoTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 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.onap.aai.exceptions;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25
26 import java.io.IOException;
27 import java.util.HashMap;
28
29 import org.junit.Test;
30
31 public class AAIExceptionWithInfoTest {
32
33     private AAIExceptionWithInfo aaiException;
34     private static final String testInfo = "Test Info";
35     private static final String testDetails = "Test Details";
36
37     @Test
38     public void aaiExceptionWithInfoTest() {
39
40         aaiException = new AAIExceptionWithInfo(new HashMap<String, Object>(), testInfo);
41
42         assertEquals(testInfo, aaiException.getInfo());
43         assertNotNull(aaiException.getInfoHash());
44     }
45
46     @Test
47     public void aaiExceptionWithCodeInfoTest() {
48         aaiException = new AAIExceptionWithInfo("AAI_3300", new HashMap<String, Object>(), testInfo);
49
50         assertEquals(testInfo, aaiException.getInfo());
51         assertEquals("AAI_3300", aaiException.getCode());
52         assertNotNull(aaiException.getInfoHash());
53     }
54
55     @Test
56     public void aaiExceptionWithCodeDetailsInfoTest() {
57
58         aaiException = new AAIExceptionWithInfo("AAI_3300", testDetails, new HashMap<String, Object>(), testInfo);
59
60         assertEquals(testInfo, aaiException.getInfo());
61         assertEquals("AAI_3300", aaiException.getCode());
62         assertEquals(testDetails, aaiException.getMessage());
63         assertNotNull(aaiException.getInfoHash());
64     }
65
66     @Test
67     public void aaiExceptionWithCodeThrowableDetailsInfoTest() {
68
69         aaiException = new AAIExceptionWithInfo("AAI_3300", new IOException("File not found"), testDetails,
70                 new HashMap<String, Object>(), testInfo);
71
72         assertEquals(testInfo, aaiException.getInfo());
73         assertEquals("AAI_3300", aaiException.getCode());
74         assertEquals(testDetails, aaiException.getMessage());
75         assertNotNull(aaiException.getInfoHash());
76         Throwable t = aaiException.getCause();
77         assertEquals("java.io.IOException: File not found", t.toString());
78     }
79
80 }