2 * ============LICENSE_START=======================================================
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
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=========================================================
21 package org.openecomp.aai.exceptions;
23 import org.junit.Test;
24 import org.openecomp.aai.AAISetup;
26 import static org.junit.Assert.assertEquals;
28 public class AAIExceptionTest extends AAISetup {
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();
36 * Test constructor with 0 params.
38 * @throws Exception the exception
41 public void testConstructorWith0Params() throws Exception {
42 AAIException exception = new AAIException();
43 assertEquals(exception, exception);
47 * Test constructor with 1 params.
49 * @throws Exception the exception
52 public void testConstructorWith1Params() throws Exception {
53 AAIException exception = new AAIException(code);
54 assertEquals(exception, exception);
58 * Test constructor with 2 params details.
60 * @throws Exception the exception
63 public void testConstructorWith2ParamsDetails() throws Exception {
64 AAIException exception = new AAIException(code, details);
65 assertEquals(details, exception.getMessage());
69 * Test constructor with 2 params cause.
71 * @throws Exception the exception
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());
80 * Test constructor with 2 params null message.
82 * @throws Exception the exception
85 public void testConstructorWith2ParamsNullMessage() throws Exception {
86 AAIException exception = new AAIException(code, noMessage);
87 assertEquals(noMessage.toString(), exception.getMessage());
91 * Test constructor with 3 params.
93 * @throws Exception the exception
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());
103 * Test constructor with 3 params null message.
105 * @throws Exception the exception
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());