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.core.classloader.annotations.PowerMockIgnore;
40 import org.powermock.modules.junit4.PowerMockRunner;
42 import org.onap.dmaap.dmf.mr.exception.DMaaPErrorMessages;
44 @RunWith(PowerMockRunner.class)
45 @PowerMockIgnore("jdk.internal.reflect.*")
46 public class DMaaPWebExceptionMapperTest {
49 DMaaPWebExceptionMapper mapper;
52 DMaaPErrorMessages msgs;
55 public void setUp() throws Exception {
59 public void tearDown() throws Exception {
63 public void testToResponse() {
66 mapper.toResponse(null);
67 } catch (NullPointerException e) {
74 public void testToResponseNotFoundException() {
75 PowerMockito.when(msgs.getNotFound()).thenReturn("Not found");
77 mapper.toResponse(new NotFoundException());
78 } catch (NullPointerException e) {
85 public void testToResponseInternalServerErrorException() {
86 PowerMockito.when(msgs.getNotFound()).thenReturn("Not found");
88 mapper.toResponse(new InternalServerErrorException());
90 } catch (NullPointerException e) {
97 public void testToResponseNotAuthorizedException() {
98 PowerMockito.when(msgs.getNotFound()).thenReturn("Not found");
100 mapper.toResponse(new NotAuthorizedException("Error", "Error"));
102 } catch (NullPointerException e) {
109 public void testToResponseBadRequestException() {
110 PowerMockito.when(msgs.getNotFound()).thenReturn("Not found");
112 mapper.toResponse(new BadRequestException());
114 } catch (NullPointerException e) {
121 public void testToResponseNotAllowedException() {
122 PowerMockito.when(msgs.getNotFound()).thenReturn("Not found");
124 mapper.toResponse(new NotAllowedException("Not Allowed"));
126 } catch (NullPointerException e) {
133 public void testToResponseServiceUnavailableException() {
134 PowerMockito.when(msgs.getNotFound()).thenReturn("Not found");
136 mapper.toResponse(new ServiceUnavailableException());
138 } catch (NullPointerException e) {