2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.aai.exceptions;
22 import org.junit.Test;
23 import org.onap.aai.AAISetup;
25 import static org.junit.Assert.assertEquals;
27 public class AAIExceptionTest extends AAISetup {
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();
35 * Test constructor with 0 params.
37 * @throws Exception the exception
40 public void testConstructorWith0Params() throws Exception {
41 AAIException exception = new AAIException();
42 assertEquals(exception, exception);
46 * Test constructor with 1 params.
48 * @throws Exception the exception
51 public void testConstructorWith1Params() throws Exception {
52 AAIException exception = new AAIException(code);
53 assertEquals(exception, exception);
57 * Test constructor with 2 params details.
59 * @throws Exception the exception
62 public void testConstructorWith2ParamsDetails() throws Exception {
63 AAIException exception = new AAIException(code, details);
64 assertEquals(details, exception.getMessage());
68 * Test constructor with 2 params cause.
70 * @throws Exception the exception
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());
79 * Test constructor with 2 params null message.
81 * @throws Exception the exception
84 public void testConstructorWith2ParamsNullMessage() throws Exception {
85 AAIException exception = new AAIException(code, noMessage);
86 assertEquals(noMessage.toString(), exception.getMessage());
90 * Test constructor with 3 params.
92 * @throws Exception the exception
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());
102 * Test constructor with 3 params null message.
104 * @throws Exception the exception
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());