2 * ============LICENSE_START=======================================================
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
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.exceptions;
24 import org.junit.Test;
25 import org.onap.aai.AAISetup;
27 import static org.junit.Assert.assertEquals;
29 public class AAIExceptionTest extends AAISetup {
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();
37 * Test constructor with 0 params.
39 * @throws Exception the exception
42 public void testConstructorWith0Params() throws Exception {
43 AAIException exception = new AAIException();
44 assertEquals(exception, exception);
48 * Test constructor with 1 params.
50 * @throws Exception the exception
53 public void testConstructorWith1Params() throws Exception {
54 AAIException exception = new AAIException(code);
55 assertEquals(exception, exception);
59 * Test constructor with 2 params details.
61 * @throws Exception the exception
64 public void testConstructorWith2ParamsDetails() throws Exception {
65 AAIException exception = new AAIException(code, details);
66 assertEquals(details, exception.getMessage());
70 * Test constructor with 2 params cause.
72 * @throws Exception the exception
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());
81 * Test constructor with 2 params null message.
83 * @throws Exception the exception
86 public void testConstructorWith2ParamsNullMessage() throws Exception {
87 AAIException exception = new AAIException(code, noMessage);
88 assertEquals(noMessage.toString(), exception.getMessage());
92 * Test constructor with 3 params.
94 * @throws Exception the exception
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());
104 * Test constructor with 3 params null message.
106 * @throws Exception the exception
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());