use of net.sourceforge.stripes.mock.MockFilterChain in project jspwiki by apache.
the class WikiSessionTest method runSecurityFilter.
/**
* "Scaffolding" method that runs the session security filter on a mock request. We do this by creating a
* complete mock servlet context and filter chain, and running the request through it.
* @param engine the wiki engine
* @param request the mock request to pass itnto the
* @throws ServletException
* @throws IOException
*/
private static void runSecurityFilter(WikiEngine engine, HttpServletRequest request) throws ServletException, IOException {
// Create a mock servlet context and stash the wiki engine in it
ServletContext servletCtx = new MockServletContext("JSPWiki");
servletCtx.setAttribute("org.apache.wiki.WikiEngine", engine);
// Create a mock filter configuration and add the servlet context we just created
MockFilterConfig filterConfig = new MockFilterConfig();
filterConfig.setFilterName("WikiServletFilter");
filterConfig.setServletContext(servletCtx);
// Create the security filter and run the request through it
Filter filter = new WikiServletFilter();
MockFilterChain chain = new MockFilterChain();
chain.addFilter(filter);
Servlet servlet = new MockServlet();
chain.setServlet(servlet);
filter.init(filterConfig);
filter.doFilter(request, null, chain);
}
Aggregations