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