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