update the package name
[dmaap/messagerouter/messageservice.git] / src / test / java / org / onap / dmaap / util / DMaaPAuthFilterTest.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.util;
22
23 import static org.junit.Assert.assertTrue;
24
25 import java.io.IOException;
26
27 import javax.servlet.FilterChain;
28 import javax.servlet.ServletException;
29 import javax.servlet.ServletResponse;
30 import javax.servlet.http.HttpServletRequest;
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.mockito.MockitoAnnotations;
39 import org.powermock.api.mockito.PowerMockito;
40 import org.powermock.core.classloader.annotations.PrepareForTest;
41 import org.powermock.modules.junit4.PowerMockRunner;
42
43 import com.att.ajsc.beans.PropertiesMapBean;
44 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
45 import org.onap.dmaap.dmf.mr.exception.DMaaPResponseCode;
46
47
48 @RunWith(PowerMockRunner.class)
49 @PrepareForTest({ PropertiesMapBean.class, DMaaPResponseCode.class })
50 public class DMaaPAuthFilterTest {
51
52         @InjectMocks
53         DMaaPAuthFilter filter;
54
55         @Mock
56         HttpServletRequest req;
57
58         @Mock
59         ServletResponse res;
60
61         @Mock
62         FilterChain chain;
63
64         @Mock
65         DMaaPContext dmaapContext;
66
67         @Before
68         public void setUp() throws Exception {
69                 MockitoAnnotations.initMocks(this);
70         }
71
72         @After
73         public void tearDown() throws Exception {
74         }
75
76         //@Test
77         public void testDoFilter() throws IOException, ServletException {
78
79                 PowerMockito.when(dmaapContext.getRequest()).thenReturn(req);
80                 PowerMockito.when(req.getHeader("Authorization")).thenReturn("Authorization");
81                 // when(dmaapContext.getResponse()).thenReturn(res);
82                 filter.doFilter(req, res, chain);
83                 assertTrue(true);
84
85         }
86
87         //@Test
88         public void testDoFilter_nullAuth() throws IOException, ServletException {
89
90                 PowerMockito.when(dmaapContext.getRequest()).thenReturn(req);
91                 PowerMockito.when(req.getHeader("Authorization")).thenReturn("Authorization");
92
93                 // when(dmaapContext.getResponse()).thenReturn(res);
94                 filter.doFilter(req, res, chain);
95                 assertTrue(true);
96
97         }
98         
99         
100 }