4b1fb74d1629d82aed225eda9df77e2aae3c4fde
[dmaap/messagerouter/messageservice.git] / src / test / java / org / onap / dmaap / DMaaPWebExceptionMapperTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
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
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.dmaap;
22
23 import static org.junit.Assert.*;
24
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;
31
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;
41
42 import org.onap.dmaap.dmf.mr.exception.DMaaPErrorMessages;
43
44 @RunWith(PowerMockRunner.class)
45 @PowerMockIgnore("jdk.internal.reflect.*")
46 public class DMaaPWebExceptionMapperTest {
47
48         @InjectMocks
49         DMaaPWebExceptionMapper mapper;
50
51         @Mock
52         DMaaPErrorMessages msgs;
53
54         @Before
55         public void setUp() throws Exception {
56         }
57
58         @After
59         public void tearDown() throws Exception {
60         }
61
62         @Test
63         public void testToResponse() {
64
65                 try {
66                         mapper.toResponse(null);
67                 } catch (NullPointerException e) {
68                         assertTrue(true);
69                 }
70
71         }
72
73         @Test
74         public void testToResponseNotFoundException() {
75                 PowerMockito.when(msgs.getNotFound()).thenReturn("Not found");
76                 try {
77                         mapper.toResponse(new NotFoundException());
78                 } catch (NullPointerException e) {
79                         assertTrue(true);
80                 }
81
82         }
83
84         @Test
85         public void testToResponseInternalServerErrorException() {
86                 PowerMockito.when(msgs.getNotFound()).thenReturn("Not found");
87                 try {
88                         mapper.toResponse(new InternalServerErrorException());
89
90                 } catch (NullPointerException e) {
91                         assertTrue(true);
92                 }
93
94         }
95
96         @Test
97         public void testToResponseNotAuthorizedException() {
98                 PowerMockito.when(msgs.getNotFound()).thenReturn("Not found");
99                 try {
100                         mapper.toResponse(new NotAuthorizedException("Error", "Error"));
101
102                 } catch (NullPointerException e) {
103                         assertTrue(true);
104                 }
105
106         }
107
108         @Test
109         public void testToResponseBadRequestException() {
110                 PowerMockito.when(msgs.getNotFound()).thenReturn("Not found");
111                 try {
112                         mapper.toResponse(new BadRequestException());
113
114                 } catch (NullPointerException e) {
115                         assertTrue(true);
116                 }
117
118         }
119
120         @Test
121         public void testToResponseNotAllowedException() {
122                 PowerMockito.when(msgs.getNotFound()).thenReturn("Not found");
123                 try {
124                         mapper.toResponse(new NotAllowedException("Not Allowed"));
125
126                 } catch (NullPointerException e) {
127                         assertTrue(true);
128                 }
129
130         }
131
132         @Test
133         public void testToResponseServiceUnavailableException() {
134                 PowerMockito.when(msgs.getNotFound()).thenReturn("Not found");
135                 try {
136                         mapper.toResponse(new ServiceUnavailableException());
137
138                 } catch (NullPointerException e) {
139                         assertTrue(true);
140                 }
141
142         }
143
144 }