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.logging;
23 import static org.junit.Assert.assertEquals;
25 import javax.ws.rs.core.Response;
27 import org.junit.Test;
29 public class ErrorObjectTest {
30 private ErrorObject errorObject;
31 private static final String ERROR_DISPOSITION = "5";
32 private static final String ERROR_SEVERITY = "ERROR";
33 private static final String ERROR_CATEGORY = "4";
34 private static final Integer ERROR_HTTP_RESPONSE_CODE = new Integer(401);
35 private static final String ERROR_REST_CODE = "3300";
36 private static final String ERROR_CODE = "4000";
37 private static final String ERROR_TEXT = "Test data error";
38 private static final String ERROR_PATTERN = "ERR.5.4.4000";
39 private static final String ERROR_SEVERITY_CODE = "2";
42 public void errorObjectDefaultConstructorTest() {
43 errorObject = new ErrorObject();
44 assertEquals("3002", errorObject.getRESTErrorCode());
45 assertEquals(Response.Status.fromStatusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()),
46 errorObject.getHTTPResponseCode());
47 assertEquals(AaiElsErrorCode.UNKNOWN_ERROR, errorObject.getAaiElsErrorCode());
48 assertEquals(ERROR_SEVERITY_CODE, errorObject.getSeverityCode(ERROR_SEVERITY));
52 public void errorObjectConstructor7Test() {
53 errorObject = new ErrorObject(ERROR_DISPOSITION, ERROR_CATEGORY, ERROR_SEVERITY, ERROR_HTTP_RESPONSE_CODE,
54 ERROR_REST_CODE, ERROR_CODE, ERROR_TEXT);
55 assertEquals(ERROR_DISPOSITION, errorObject.getDisposition());
56 assertEquals(ERROR_SEVERITY, errorObject.getSeverity());
57 assertEquals(ERROR_CATEGORY, errorObject.getCategory());
58 assertEquals(Response.Status.fromStatusCode(ERROR_HTTP_RESPONSE_CODE), errorObject.getHTTPResponseCode());
59 assertEquals(ERROR_REST_CODE, errorObject.getRESTErrorCode());
60 assertEquals(ERROR_CODE, errorObject.getErrorCode());
61 assertEquals(ERROR_TEXT, errorObject.getErrorText());
62 assertEquals(AaiElsErrorCode.UNKNOWN_ERROR, errorObject.getAaiElsErrorCode());
63 assertEquals(ERROR_SEVERITY_CODE, errorObject.getSeverityCode(ERROR_SEVERITY));
67 public void errorObjectConstructor5Test() {
68 errorObject = new ErrorObject(ERROR_SEVERITY, ERROR_CODE, ERROR_TEXT, ERROR_DISPOSITION, ERROR_CATEGORY);
69 assertEquals(ERROR_DISPOSITION, errorObject.getDisposition());
70 assertEquals(ERROR_SEVERITY, errorObject.getSeverity());
71 assertEquals(ERROR_CATEGORY, errorObject.getCategory());
72 assertEquals(Response.Status.fromStatusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()),
73 errorObject.getHTTPResponseCode());
74 assertEquals("3002", errorObject.getRESTErrorCode());
75 assertEquals(ERROR_CODE, errorObject.getErrorCode());
76 assertEquals(ERROR_TEXT, errorObject.getErrorText());
77 assertEquals(AaiElsErrorCode.UNKNOWN_ERROR, errorObject.getAaiElsErrorCode());
78 assertEquals(ERROR_PATTERN, errorObject.getErrorCodeString());
79 assertEquals(ERROR_SEVERITY_CODE, errorObject.getSeverityCode(ERROR_SEVERITY));
83 public void errorObjectConstructor6Test() {
84 errorObject = new ErrorObject(ERROR_SEVERITY, ERROR_HTTP_RESPONSE_CODE, ERROR_CODE, ERROR_TEXT,
85 ERROR_DISPOSITION, ERROR_CATEGORY);
86 assertEquals(ERROR_DISPOSITION, errorObject.getDisposition());
87 assertEquals(ERROR_SEVERITY, errorObject.getSeverity());
88 assertEquals(ERROR_CATEGORY, errorObject.getCategory());
89 assertEquals(Response.Status.fromStatusCode(ERROR_HTTP_RESPONSE_CODE), errorObject.getHTTPResponseCode());
90 assertEquals("3002", errorObject.getRESTErrorCode());
91 assertEquals(ERROR_CODE, errorObject.getErrorCode());
92 assertEquals(ERROR_TEXT, errorObject.getErrorText());
93 assertEquals(AaiElsErrorCode.UNKNOWN_ERROR, errorObject.getAaiElsErrorCode());
94 assertEquals(ERROR_PATTERN, errorObject.getErrorCodeString());
95 assertEquals(ERROR_SEVERITY_CODE, errorObject.getSeverityCode(ERROR_SEVERITY));