Increase code coverage on aai-common: aai-els-onap-logging library
[aai/aai-common.git] / aai-els-onap-logging / src / test / java / org / onap / aai / exceptions / AAIExceptionTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.aai.exceptions;
21
22 import org.junit.Test;
23 import org.onap.aai.logging.AaiElsErrorCode;
24 import org.onap.aai.logging.ErrorObject;
25
26 import javax.ws.rs.core.Response;
27 import java.io.IOException;
28
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertNotNull;
31
32
33 public class AAIExceptionTest {
34     private AAIException aaiException;
35
36     @Test
37     public void defaultAAIExceptionTest() {
38         //AAI_4000=5:4:ERROR:4000:500:3002:Internal Error:900
39         aaiException = new AAIException();
40         assertEquals(AAIException.DEFAULT_EXCEPTION_CODE, aaiException.getCode());
41
42         ErrorObject errorObject = aaiException.getErrorObject();
43         assertEquals(errorObject.getCategory(), "4");
44         assertEquals(errorObject.getDisposition(), "5");
45         assertEquals(errorObject.getSeverity(), "ERROR");
46         assertEquals(errorObject.getHTTPResponseCode(), Response.Status.INTERNAL_SERVER_ERROR);
47         assertEquals(errorObject.getRESTErrorCode(), "3002");
48         assertEquals(errorObject.getErrorCode(), "4000");
49         assertEquals(errorObject.getAaiElsErrorCode(), AaiElsErrorCode.UNKNOWN_ERROR);
50         assertEquals(errorObject.getErrorText(), "Internal Error");
51
52     }
53
54     @Test
55     public void aaiExceptionTest() {
56         //5:1:WARN:3303:403:3300:Too many objects would be returned by this request, please refine your request and retry:500
57         aaiException = new AAIException("AAI_3303");
58         assertEquals("AAI_3303", aaiException.getCode());
59
60         ErrorObject errorObject = aaiException.getErrorObject();
61         assertEquals(errorObject.getCategory(), "1");
62         assertEquals(errorObject.getDisposition(), "5");
63         assertEquals(errorObject.getSeverity(), "WARN");
64         assertEquals(errorObject.getHTTPResponseCode(), Response.Status.FORBIDDEN);
65         assertEquals(errorObject.getRESTErrorCode(), "3300");
66         assertEquals(errorObject.getErrorCode(), "3303");
67         assertEquals(errorObject.getAaiElsErrorCode(), AaiElsErrorCode.BUSINESS_PROCESS_ERROR);
68         assertEquals(errorObject.getErrorText(), "Too many objects would be returned by this request, please refine your request and retry");
69         assertNotNull(aaiException.getTemplateVars());
70     }
71
72     @Test
73     public void aaiExceptionTestWithDetails() {
74         //5:1:WARN:3303:403:3300:Too many objects would be returned by this request, please refine your request and retry:500
75         final String testDetails = "Test details";
76         aaiException = new AAIException("AAI_3303", testDetails);
77         assertEquals(testDetails, aaiException.getMessage());
78         assertEquals(testDetails, aaiException.getErrorObject().getDetails());
79         assertNotNull(aaiException.getTemplateVars());
80     }
81
82     @Test
83     public void aaiExceptionTestWithCause() {
84         aaiException = new AAIException("AAI_3303", new IOException("File not found"));
85         Throwable t = aaiException.getCause();
86         assertEquals("java.io.IOException: File not found", t.toString());
87         assertNotNull(aaiException.getTemplateVars());
88     }
89
90     @Test
91     public void aaiExceptionTestWithCauseDetails() {
92         final String testFileName = "TestFileName";
93         aaiException = new AAIException("AAI_3303", new IOException("File not found"), testFileName);
94
95         Throwable t = aaiException.getCause();
96         assertEquals("java.io.IOException: File not found", t.toString());
97         assertEquals(testFileName, aaiException.getMessage());
98         assertNotNull(aaiException.getTemplateVars());
99     }
100 }
101