2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package com.att.nsa.dmaap.util;
\r
23 import java.io.IOException;
\r
24 import java.util.logging.Level;
\r
26 import javax.servlet.FilterChain;
\r
27 import javax.servlet.ServletException;
\r
28 import javax.servlet.ServletResponse;
\r
29 import javax.servlet.http.HttpServletRequest;
\r
31 import org.junit.After;
\r
32 import org.junit.Before;
\r
33 import org.junit.Test;
\r
34 import org.junit.runner.RunWith;
\r
35 import org.mockito.InjectMocks;
\r
36 import org.mockito.Mock;
\r
37 import org.mockito.MockitoAnnotations;
\r
38 import org.powermock.api.mockito.PowerMockito;
\r
39 import org.powermock.core.classloader.annotations.PrepareForTest;
\r
40 import org.powermock.modules.junit4.PowerMockRunner;
\r
42 import com.att.ajsc.beans.PropertiesMapBean;
\r
43 import com.att.nsa.cambria.beans.DMaaPContext;
\r
44 import com.att.nsa.cambria.exception.DMaaPResponseCode;
\r
46 @RunWith(PowerMockRunner.class)
\r
47 @PrepareForTest({ PropertiesMapBean.class, DMaaPResponseCode.class })
\r
48 public class DMaaPAuthFilterTest {
\r
51 DMaaPAuthFilter filter;
\r
54 HttpServletRequest req;
\r
57 ServletResponse res;
\r
63 DMaaPContext dmaapContext;
\r
66 public void setUp() throws Exception {
\r
67 MockitoAnnotations.initMocks(this);
\r
71 public void tearDown() throws Exception {
\r
75 public void testDoFilter() throws IOException, ServletException {
\r
77 PowerMockito.when(dmaapContext.getRequest()).thenReturn(req);
\r
78 PowerMockito.when(req.getHeader("Authorization")).thenReturn("Authorization");
\r
79 // when(dmaapContext.getResponse()).thenReturn(res);
\r
80 filter.doFilter(req, res, chain);
\r
85 public void testDoFilter_nullAuth() throws IOException, ServletException {
\r
87 PowerMockito.when(dmaapContext.getRequest()).thenReturn(req);
\r
88 PowerMockito.when(req.getHeader("Authorization")).thenReturn("Authorization");
\r
90 // when(dmaapContext.getResponse()).thenReturn(res);
\r
91 filter.doFilter(req, res, chain);
\r