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=========================================================
21 package org.onap.aai.exceptions;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
26 import java.io.IOException;
28 import javax.ws.rs.core.Response;
30 import org.junit.Test;
31 import org.onap.aai.logging.AaiElsErrorCode;
32 import org.onap.aai.logging.ErrorObject;
34 public class AAIExceptionTest {
35 private AAIException aaiException;
38 public void defaultAAIExceptionTest() {
39 // AAI_4000=5:4:ERROR:4000:500:3002:Internal Error:900
40 aaiException = new AAIException();
41 assertEquals(AAIException.DEFAULT_EXCEPTION_CODE, aaiException.getCode());
43 ErrorObject errorObject = aaiException.getErrorObject();
44 assertEquals(errorObject.getCategory(), "4");
45 assertEquals(errorObject.getDisposition(), "5");
46 assertEquals(errorObject.getSeverity(), "ERROR");
47 assertEquals(errorObject.getHTTPResponseCode(), Response.Status.INTERNAL_SERVER_ERROR);
48 assertEquals(errorObject.getRESTErrorCode(), "3002");
49 assertEquals(errorObject.getErrorCode(), "4000");
50 assertEquals(errorObject.getAaiElsErrorCode(), AaiElsErrorCode.UNKNOWN_ERROR);
51 assertEquals(errorObject.getErrorText(), "Internal Error");
56 public void aaiExceptionTest() {
57 // 5:1:WARN:3303:403:3300:Too many objects would be returned by this request, please refine your request and
59 aaiException = new AAIException("AAI_3303");
60 assertEquals("AAI_3303", aaiException.getCode());
62 ErrorObject errorObject = aaiException.getErrorObject();
63 assertEquals(errorObject.getCategory(), "1");
64 assertEquals(errorObject.getDisposition(), "5");
65 assertEquals(errorObject.getSeverity(), "WARN");
66 assertEquals(errorObject.getHTTPResponseCode(), Response.Status.FORBIDDEN);
67 assertEquals(errorObject.getRESTErrorCode(), "3300");
68 assertEquals(errorObject.getErrorCode(), "3303");
69 assertEquals(errorObject.getAaiElsErrorCode(), AaiElsErrorCode.BUSINESS_PROCESS_ERROR);
70 assertEquals(errorObject.getErrorText(),
71 "Too many objects would be returned by this request, please refine your request and retry");
72 assertNotNull(aaiException.getTemplateVars());
76 public void aaiExceptionTestWithDetails() {
77 // 5:1:WARN:3303:403:3300:Too many objects would be returned by this request, please refine your request and
79 final String testDetails = "Test details";
80 aaiException = new AAIException("AAI_3303", testDetails);
81 assertEquals(testDetails, aaiException.getMessage());
82 assertEquals(testDetails, aaiException.getErrorObject().getDetails());
83 assertNotNull(aaiException.getTemplateVars());
87 public void aaiExceptionTestWithCause() {
88 aaiException = new AAIException("AAI_3303", new IOException("File not found"));
89 Throwable t = aaiException.getCause();
90 assertEquals("java.io.IOException: File not found", t.toString());
91 assertNotNull(aaiException.getTemplateVars());
95 public void aaiExceptionTestWithCauseDetails() {
96 final String testFileName = "TestFileName";
97 aaiException = new AAIException("AAI_3303", new IOException("File not found"), testFileName);
99 Throwable t = aaiException.getCause();
100 assertEquals("java.io.IOException: File not found", t.toString());
101 assertEquals(testFileName, aaiException.getMessage());
102 assertNotNull(aaiException.getTemplateVars());