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;
24 import static org.junit.Assert.assertEquals;
26 import org.junit.BeforeClass;
28 import org.junit.Test;
30 import static org.junit.Assert.assertEquals;
32 public class AAIExceptionTest {
33 private static final String code = "4004";
34 private static final String details = "This is a detailed description of the exception.";
35 private static final Throwable cause = new RuntimeException("This is a runtime exception.");
36 private static final Throwable noMessage = new RuntimeException();
39 public static void configure() {
40 System.setProperty("AJSC_HOME", "./src/test/resources/");
41 System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
45 * Test constructor with 0 params.
47 * @throws Exception the exception
50 public void testConstructorWith0Params() throws Exception {
51 AAIException exception = new AAIException();
52 assertEquals(exception, exception);
56 * Test constructor with 1 params.
58 * @throws Exception the exception
61 public void testConstructorWith1Params() throws Exception {
62 AAIException exception = new AAIException(code);
63 assertEquals(exception, exception);
67 * Test constructor with 2 params details.
69 * @throws Exception the exception
72 public void testConstructorWith2ParamsDetails() throws Exception {
73 AAIException exception = new AAIException(code, details);
74 assertEquals(details, exception.getMessage());
78 * Test constructor with 2 params cause.
80 * @throws Exception the exception
83 public void testConstructorWith2ParamsCause() throws Exception {
84 AAIException exception = new AAIException(code, cause);
85 assertEquals(cause.getMessage(), exception.getMessage());
89 * Test constructor with 2 params null message.
91 * @throws Exception the exception
94 public void testConstructorWith2ParamsNullMessage() throws Exception {
95 AAIException exception = new AAIException(code, noMessage);
96 assertEquals(noMessage.toString(), exception.getMessage());
100 * Test constructor with 3 params.
102 * @throws Exception the exception
105 public void testConstructorWith3Params() throws Exception {
106 AAIException exception = new AAIException(code, cause, details);
107 String details = "This is a runtime exception.-This is a detailed description of the exception.";
108 assertEquals(details, exception.getMessage());
112 * Test constructor with 3 params null message.
114 * @throws Exception the exception
117 public void testConstructorWith3ParamsNullMessage() throws Exception {
118 AAIException exception = new AAIException(code, noMessage, details);
119 String detailString = new String(noMessage.toString() + "-" + details);
120 assertEquals(detailString, exception.getMessage());