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 static org.junit.Assert.assertTrue;
\r
25 import java.io.IOException;
\r
27 import javax.servlet.FilterChain;
\r
28 import javax.servlet.ServletException;
\r
29 import javax.servlet.ServletResponse;
\r
30 import javax.servlet.http.HttpServletRequest;
\r
32 import org.junit.After;
\r
33 import org.junit.Before;
\r
34 import org.junit.Test;
\r
35 import org.junit.runner.RunWith;
\r
36 import org.mockito.InjectMocks;
\r
37 import org.mockito.Mock;
\r
38 import org.mockito.MockitoAnnotations;
\r
39 import org.powermock.api.mockito.PowerMockito;
\r
40 import org.powermock.core.classloader.annotations.PrepareForTest;
\r
41 import org.powermock.modules.junit4.PowerMockRunner;
\r
43 import com.att.ajsc.beans.PropertiesMapBean;
\r
44 import com.att.dmf.mr.beans.DMaaPContext;
\r
45 import com.att.dmf.mr.exception.DMaaPResponseCode;
\r
47 import com.att.cadi.Access.Level;
\r
49 @RunWith(PowerMockRunner.class)
\r
50 @PrepareForTest({ PropertiesMapBean.class, DMaaPResponseCode.class })
\r
51 public class DMaaPAuthFilterTest {
\r
54 DMaaPAuthFilter filter;
\r
57 HttpServletRequest req;
\r
60 ServletResponse res;
\r
66 DMaaPContext dmaapContext;
\r
69 public void setUp() throws Exception {
\r
70 MockitoAnnotations.initMocks(this);
\r
74 public void tearDown() throws Exception {
\r
78 public void testDoFilter() throws IOException, ServletException {
\r
80 PowerMockito.when(dmaapContext.getRequest()).thenReturn(req);
\r
81 PowerMockito.when(req.getHeader("Authorization")).thenReturn("Authorization");
\r
82 // when(dmaapContext.getResponse()).thenReturn(res);
\r
83 filter.doFilter(req, res, chain);
\r
89 public void testDoFilter_nullAuth() throws IOException, ServletException {
\r
91 PowerMockito.when(dmaapContext.getRequest()).thenReturn(req);
\r
92 PowerMockito.when(req.getHeader("Authorization")).thenReturn("Authorization");
\r
94 // when(dmaapContext.getResponse()).thenReturn(res);
\r
95 filter.doFilter(req, res, chain);
\r
101 public void testLog() {
\r
102 String s[] = { "test1", "test2" };
\r
104 filter.log(Level.AUDIT, o);
\r
105 filter.log(Level.DEBUG, o);
\r
106 filter.log(Level.ERROR, o);
\r
107 filter.log(Level.INFO, o);
\r
108 filter.log(Level.INIT, o);
\r
109 filter.log(Level.WARN, o);
\r