use of javax.servlet.FilterConfig in project OpenAM by OpenRock.
the class CORSFilterTest method shouldConfigureWithBothMethodsAndOriginsNoErrors.
@Test
public void shouldConfigureWithBothMethodsAndOriginsNoErrors() {
//given
FilterConfig config = mock(FilterConfig.class);
given(config.getInitParameter(CORSConstants.ORIGINS_KEY)).willReturn("www.google.com");
given(config.getInitParameter(CORSConstants.METHODS_KEY)).willReturn("GET,POST");
boolean success = true;
//when
try {
testFilter.init(config);
} catch (ServletException e) {
success = false;
}
//then
assertTrue(success);
}
use of javax.servlet.FilterConfig in project OpenAM by OpenRock.
the class CORSFilterTest method shoudlThrowExceptionWhenNoMethodsInConfig.
@Test(expectedExceptions = ServletException.class)
public void shoudlThrowExceptionWhenNoMethodsInConfig() throws ServletException {
//given
FilterConfig config = mock(FilterConfig.class);
given(config.getInitParameter(CORSConstants.ORIGINS_KEY)).willReturn("www.google.com");
//when
testFilter.init(config);
//then
}
use of javax.servlet.FilterConfig in project roboguice by roboguice.
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);
}
use of javax.servlet.FilterConfig in project roboguice by roboguice.
the class FilterDefinition method init.
public void init(final ServletContext servletContext, Injector injector, Set<Filter> initializedSoFar) throws ServletException {
// This absolutely must be a singleton, and so is only initialized once.
if (!Scopes.isSingleton(injector.getBinding(filterKey))) {
throw new ServletException("Filters must be bound as singletons. " + filterKey + " was not bound in singleton scope.");
}
Filter filter = injector.getInstance(filterKey);
this.filter.set(filter);
// in the filter chain.
if (initializedSoFar.contains(filter)) {
return;
}
//initialize our filter with the configured context params and servlet context
filter.init(new FilterConfig() {
public String getFilterName() {
return filterKey.toString();
}
public ServletContext getServletContext() {
return servletContext;
}
public String getInitParameter(String s) {
return initParams.get(s);
}
public Enumeration getInitParameterNames() {
return Iterators.asEnumeration(initParams.keySet().iterator());
}
});
initializedSoFar.add(filter);
}
use of javax.servlet.FilterConfig in project roboguice by roboguice.
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);
}
Aggregations