2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.dmaap.util;
23 import static org.junit.Assert.assertTrue;
25 import java.io.IOException;
27 import javax.servlet.FilterChain;
28 import javax.servlet.ServletException;
29 import javax.servlet.ServletResponse;
30 import javax.servlet.http.HttpServletRequest;
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;
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;
48 @RunWith(PowerMockRunner.class)
49 @PrepareForTest({ PropertiesMapBean.class, DMaaPResponseCode.class })
50 public class DMaaPAuthFilterTest {
53 DMaaPAuthFilter filter;
56 HttpServletRequest req;
65 DMaaPContext dmaapContext;
68 public void setUp() throws Exception {
69 MockitoAnnotations.initMocks(this);
73 public void tearDown() throws Exception {
77 public void testDoFilter() throws IOException, ServletException {
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);
88 public void testDoFilter_nullAuth() throws IOException, ServletException {
90 PowerMockito.when(dmaapContext.getRequest()).thenReturn(req);
91 PowerMockito.when(req.getHeader("Authorization")).thenReturn("Authorization");
93 // when(dmaapContext.getResponse()).thenReturn(res);
94 filter.doFilter(req, res, chain);