[SO] Release so 1.13.0 image
[so.git] / common / src / test / java / org / onap / so / web / exceptions / RuntimeExceptionMapperTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 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
21 package org.onap.so.web.exceptions;
22
23 import static org.hamcrest.CoreMatchers.equalTo;
24 import static org.hamcrest.CoreMatchers.instanceOf;
25 import static org.hamcrest.CoreMatchers.is;
26 import static org.hamcrest.CoreMatchers.nullValue;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertThat;
29 import javax.ws.rs.NotFoundException;
30 import javax.ws.rs.core.Response;
31 import javax.ws.rs.core.Response.Status;
32 import org.junit.AfterClass;
33 import org.junit.Test;
34
35
36 public class RuntimeExceptionMapperTest {
37
38
39
40     @Test
41     public void testResponse() {
42
43         RuntimeExceptionMapper mapper = new RuntimeExceptionMapper();
44
45         Response r = mapper.toResponse(new RuntimeException("This is the run time exception message"));
46
47         assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus());
48         assertThat(r.getEntity(), instanceOf(ExceptionResponse.class));
49         assertThat(((ExceptionResponse) r.getEntity()).getMessage(), equalTo("Unexpected Internal Exception"));
50
51     }
52
53     @Test
54     public void preserve404ExceptionForForwarding() {
55
56         RuntimeExceptionMapper mapper = new RuntimeExceptionMapper();
57
58         Response r = mapper.toResponse(new NotFoundException("not found"));
59
60         assertEquals(Status.NOT_FOUND.getStatusCode(), r.getStatus());
61         assertThat(r.getEntity(), is(nullValue()));
62     }
63
64 }