2 * ============LICENSE_START=======================================================
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
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.so.web.exceptions;
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;
30 import javax.ws.rs.NotFoundException;
31 import javax.ws.rs.core.Response;
32 import javax.ws.rs.core.Response.Status;
34 import org.junit.AfterClass;
35 import org.junit.Test;
36 import org.onap.so.logger.MsoAlarmLogger;
38 public class RuntimeExceptionMapperTest {
42 public static void tearDown() {
43 MsoAlarmLogger logger = new MsoAlarmLogger();
44 logger.resetAppender();
48 public void testResponse() {
50 RuntimeExceptionMapper mapper = new RuntimeExceptionMapper();
52 Response r = mapper.toResponse(new RuntimeException("This is the run time exception message"));
54 assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus());
55 assertThat(r.getEntity(), instanceOf(ExceptionResponse.class));
56 assertThat(((ExceptionResponse)r.getEntity()).getMessage(), equalTo("Unexpected Internal Exception"));
61 public void preserve404ExceptionForForwarding() {
63 RuntimeExceptionMapper mapper = new RuntimeExceptionMapper();
65 Response r = mapper.toResponse(new NotFoundException("not found"));
67 assertEquals(Status.NOT_FOUND.getStatusCode(), r.getStatus());
68 assertThat(r.getEntity(), is(nullValue()));