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