use of javax.servlet.FilterConfig in project hbase by apache.
the class TestStaticUserWebFilter method mockConfig.
private FilterConfig mockConfig(String username) {
FilterConfig mock = Mockito.mock(FilterConfig.class);
Mockito.doReturn(username).when(mock).getInitParameter(ServerConfigurationKeys.HBASE_HTTP_STATIC_USER);
return mock;
}
use of javax.servlet.FilterConfig in project tomcat by apache.
the class TestCorsFilter method testInitDefaultFilterConfig.
@Test
public void testInitDefaultFilterConfig() throws IOException, ServletException {
TesterHttpServletRequest request = new TesterHttpServletRequest();
request.setHeader(CorsFilter.REQUEST_HEADER_ORIGIN, TesterFilterConfigs.HTTPS_WWW_APACHE_ORG);
request.setMethod("GET");
TesterHttpServletResponse response = new TesterHttpServletResponse();
CorsFilter corsFilter = new CorsFilter();
corsFilter.init(new FilterConfig() {
@Override
public ServletContext getServletContext() {
return null;
}
@Override
public Enumeration<String> getInitParameterNames() {
return null;
}
@Override
public String getInitParameter(String name) {
return null;
}
@Override
public String getFilterName() {
return null;
}
});
corsFilter.doFilter(request, response, filterChain);
Assert.assertTrue(response.getHeader(CorsFilter.RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN).equals("https://www.apache.org"));
Assert.assertTrue(((Boolean) request.getAttribute(CorsFilter.HTTP_REQUEST_ATTRIBUTE_IS_CORS_REQUEST)).booleanValue());
Assert.assertTrue(request.getAttribute(CorsFilter.HTTP_REQUEST_ATTRIBUTE_ORIGIN).equals(TesterFilterConfigs.HTTPS_WWW_APACHE_ORG));
Assert.assertTrue(request.getAttribute(CorsFilter.HTTP_REQUEST_ATTRIBUTE_REQUEST_TYPE).equals(CorsFilter.CORSRequestType.SIMPLE.name().toLowerCase(Locale.ENGLISH)));
}
use of javax.servlet.FilterConfig in project grails-core by grails.
the class SitemeshLayoutViewResolver method loadSitemeshConfig.
protected Factory loadSitemeshConfig() {
FilterConfig filterConfig = new FilterConfig() {
@Override
public ServletContext getServletContext() {
return servletContext;
}
@Override
public Enumeration<String> getInitParameterNames() {
return new Enumeration<String>() {
@Override
public boolean hasMoreElements() {
return false;
}
@Override
public String nextElement() {
throw new NoSuchElementException();
}
};
}
@Override
public String getInitParameter(String name) {
return null;
}
@Override
public String getFilterName() {
return null;
}
};
Config config = new Config(filterConfig);
Grails5535Factory sitemeshFactory = new Grails5535Factory(config);
if (servletContext != null) {
servletContext.setAttribute(FACTORY_SERVLET_CONTEXT_ATTRIBUTE, sitemeshFactory);
}
sitemeshFactory.refresh();
FactoryHolder.setFactory(sitemeshFactory);
sitemeshConfigLoaded = true;
return sitemeshFactory;
}
use of javax.servlet.FilterConfig in project guice by google.
the class FilterPipelineTest method testDispatchThruGuiceFilter.
public final void testDispatchThruGuiceFilter() throws ServletException, IOException {
//create mocks
FilterConfig filterConfig = createMock(FilterConfig.class);
ServletContext servletContext = createMock(ServletContext.class);
HttpServletRequest request = createMock(HttpServletRequest.class);
FilterChain proceedingFilterChain = createMock(FilterChain.class);
//begin mock script ***
expect(filterConfig.getServletContext()).andReturn(servletContext).once();
expect(request.getRequestURI()).andReturn("/public/login.jsp").anyTimes();
expect(request.getContextPath()).andReturn("").anyTimes();
//at the end, proceed down webapp's normal filter chain
proceedingFilterChain.doFilter(isA(HttpServletRequest.class), (ServletResponse) isNull());
expectLastCall().once();
//run mock script ***
replay(filterConfig, servletContext, request, proceedingFilterChain);
final GuiceFilter webFilter = new GuiceFilter();
webFilter.init(filterConfig);
webFilter.doFilter(request, null, proceedingFilterChain);
webFilter.destroy();
//assert expectations
verify(filterConfig, servletContext, request, proceedingFilterChain);
}
use of javax.servlet.FilterConfig in project guice by google.
the class ContinuingRequestIntegrationTest method testRequestContinuesInOtherThread.
public final void testRequestContinuesInOtherThread() throws ServletException, IOException, InterruptedException {
executor = Executors.newSingleThreadExecutor();
injector = Guice.createInjector(new ServletModule() {
@Override
protected void configureServlets() {
serve("/*").with(ContinuingServlet.class);
bind(ExecutorService.class).toInstance(executor);
}
});
FilterConfig filterConfig = createMock(FilterConfig.class);
expect(filterConfig.getServletContext()).andReturn(createMock(ServletContext.class));
GuiceFilter guiceFilter = injector.getInstance(GuiceFilter.class);
HttpServletRequest request = createMock(HttpServletRequest.class);
expect(request.getRequestURI()).andReturn("/");
expect(request.getContextPath()).andReturn("").anyTimes();
expect(request.getMethod()).andReturn("GET");
expect(request.getCookies()).andReturn(new Cookie[0]);
FilterChain filterChain = createMock(FilterChain.class);
expect(request.getParameter(PARAM_NAME)).andReturn(PARAM_VALUE);
replay(request, filterConfig, filterChain);
guiceFilter.init(filterConfig);
guiceFilter.doFilter(request, null, filterChain);
// join.
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
assertEquals(PARAM_VALUE, injector.getInstance(OffRequestCallable.class).value);
verify(request, filterConfig, filterChain);
}
Aggregations