99597f7fca22220cb0e9127b3c438e2d68f244fb
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / exceptions / AAIExceptionTest.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 package org.onap.aai.exceptions;
21
22 import org.junit.Test;
23 import org.onap.aai.AAISetup;
24
25 import static org.junit.Assert.assertEquals;
26
27 public class AAIExceptionTest extends AAISetup {
28
29     private static final String code = "4004";
30     private static final String details = "This is a detailed description of the exception.";
31     private static final Throwable cause = new RuntimeException("This is a runtime exception.");
32     private static final Throwable noMessage = new RuntimeException();
33     
34     /**
35      * Test constructor with 0 params.
36      *
37      * @throws Exception the exception
38      */
39     @Test
40     public void testConstructorWith0Params() throws Exception {
41         AAIException exception = new AAIException();
42         assertEquals(exception, exception);
43     }
44     
45     /**
46      * Test constructor with 1 params.
47      *
48      * @throws Exception the exception
49      */
50     @Test
51     public void testConstructorWith1Params() throws Exception {
52         AAIException exception = new AAIException(code);
53         assertEquals(exception, exception);
54     }
55     
56     /**
57      * Test constructor with 2 params details.
58      *
59      * @throws Exception the exception
60      */
61     @Test
62     public void testConstructorWith2ParamsDetails() throws Exception {
63         AAIException exception = new AAIException(code, details);
64         assertEquals(details, exception.getMessage());
65     }
66     
67     /**
68      * Test constructor with 2 params cause.
69      *
70      * @throws Exception the exception
71      */
72     @Test
73     public void testConstructorWith2ParamsCause() throws Exception {
74         AAIException exception = new AAIException(code, cause);
75         assertEquals("java.lang.RuntimeException: This is a runtime exception.", exception.getMessage());
76     }
77     
78     /**
79      * Test constructor with 2 params null message.
80      *
81      * @throws Exception the exception
82      */
83     @Test
84     public void testConstructorWith2ParamsNullMessage() throws Exception {
85         AAIException exception = new AAIException(code, noMessage);
86         assertEquals(noMessage.toString(), exception.getMessage());
87     }
88     
89     /**
90      * Test constructor with 3 params.
91      *
92      * @throws Exception the exception
93      */
94     @Test
95     public void testConstructorWith3Params() throws Exception {
96         AAIException exception = new AAIException(code, cause, details);
97         String details = "This is a detailed description of the exception.";
98         assertEquals(details, exception.getMessage());
99     }
100     
101     /**
102      * Test constructor with 3 params null message.
103      *
104      * @throws Exception the exception
105      */
106     @Test
107     public void testConstructorWith3ParamsNullMessage() throws Exception {
108         AAIException exception = new AAIException(code, noMessage, details);
109         String detailString = new String(details);
110         assertEquals(detailString, exception.getMessage());
111     }
112 }