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