2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.dmaap;
23 import static org.junit.Assert.*;
25 import javax.ws.rs.BadRequestException;
26 import javax.ws.rs.InternalServerErrorException;
27 import javax.ws.rs.NotAllowedException;
28 import javax.ws.rs.NotAuthorizedException;
29 import javax.ws.rs.NotFoundException;
30 import javax.ws.rs.ServiceUnavailableException;
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.InjectMocks;
37 import org.mockito.Mock;
38 import org.powermock.api.mockito.PowerMockito;
39 import org.powermock.modules.junit4.PowerMockRunner;
41 import org.onap.dmaap.dmf.mr.exception.DMaaPErrorMessages;
43 @RunWith(PowerMockRunner.class)
44 public class DMaaPWebExceptionMapperTest {
47 DMaaPWebExceptionMapper mapper;
50 DMaaPErrorMessages msgs;
53 public void setUp() throws Exception {
57 public void tearDown() throws Exception {
61 public void testToResponse() {
64 mapper.toResponse(null);
65 } catch (NullPointerException e) {
72 public void testToResponseNotFoundException() {
73 PowerMockito.when(msgs.getNotFound()).thenReturn("Not found");
75 mapper.toResponse(new NotFoundException());
76 } catch (NullPointerException e) {
83 public void testToResponseInternalServerErrorException() {
84 PowerMockito.when(msgs.getNotFound()).thenReturn("Not found");
86 mapper.toResponse(new InternalServerErrorException());
88 } catch (NullPointerException e) {
95 public void testToResponseNotAuthorizedException() {
96 PowerMockito.when(msgs.getNotFound()).thenReturn("Not found");
98 mapper.toResponse(new NotAuthorizedException("Error", "Error"));
100 } catch (NullPointerException e) {
107 public void testToResponseBadRequestException() {
108 PowerMockito.when(msgs.getNotFound()).thenReturn("Not found");
110 mapper.toResponse(new BadRequestException());
112 } catch (NullPointerException e) {
119 public void testToResponseNotAllowedException() {
120 PowerMockito.when(msgs.getNotFound()).thenReturn("Not found");
122 mapper.toResponse(new NotAllowedException("Not Allowed"));
124 } catch (NullPointerException e) {
131 public void testToResponseServiceUnavailableException() {
132 PowerMockito.when(msgs.getNotFound()).thenReturn("Not found");
134 mapper.toResponse(new ServiceUnavailableException());
136 } catch (NullPointerException e) {