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 static org.junit.Assert.assertEquals;
25 import org.junit.BeforeClass;
26 import org.junit.Test;
27 import org.openecomp.aai.serialization.queryformats.QueryFormatTestHelper;
28 import org.openecomp.aai.util.AAIConstants;
30 public class AAIExceptionTest {
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 public static void configure() throws NoSuchFieldException, SecurityException, Exception {
38 System.setProperty("AJSC_HOME", ".");
39 System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
40 QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/org/openecomp/aai/introspection/");
44 * Test constructor with 0 params.
46 * @throws Exception the exception
49 public void testConstructorWith0Params() throws Exception {
50 AAIException exception = new AAIException();
51 assertEquals(exception, exception);
55 * Test constructor with 1 params.
57 * @throws Exception the exception
60 public void testConstructorWith1Params() throws Exception {
61 AAIException exception = new AAIException(code);
62 assertEquals(exception, exception);
66 * Test constructor with 2 params details.
68 * @throws Exception the exception
71 public void testConstructorWith2ParamsDetails() throws Exception {
72 AAIException exception = new AAIException(code, details);
73 assertEquals(details, exception.getMessage());
77 * Test constructor with 2 params cause.
79 * @throws Exception the exception
82 public void testConstructorWith2ParamsCause() throws Exception {
83 AAIException exception = new AAIException(code, cause);
84 assertEquals("java.lang.RuntimeException: This is a runtime exception.", exception.getMessage());
88 * Test constructor with 2 params null message.
90 * @throws Exception the exception
93 public void testConstructorWith2ParamsNullMessage() throws Exception {
94 AAIException exception = new AAIException(code, noMessage);
95 assertEquals(noMessage.toString(), exception.getMessage());
99 * Test constructor with 3 params.
101 * @throws Exception the exception
104 public void testConstructorWith3Params() throws Exception {
105 AAIException exception = new AAIException(code, cause, details);
106 String details = "This is a detailed description of the exception.";
107 assertEquals(details, exception.getMessage());
111 * Test constructor with 3 params null message.
113 * @throws Exception the exception
116 public void testConstructorWith3ParamsNullMessage() throws Exception {
117 AAIException exception = new AAIException(code, noMessage, details);
118 String detailString = new String(details);
119 assertEquals(detailString, exception.getMessage());