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