TilesDecorationFilter implements Filter { public void doFilter(javax.servlet.ServletRequest req, ServletResponse res, FilterChain filterChain) throws IOException, ServletException { if (!isPreventTokenPresent(req)) { ApplicationContext applicationContext = org.apache.tiles.request.servlet.ServletUtil .getApplicationContext(servletContext); Request request = new ServletRequest(applicationContext, (HttpServletRequest) req, (HttpServletResponse) res); TilesContainer container = TilesAccess.getContainer(applicationContext, containerKey); mutator.mutate(container.getAttributeContext(request), req); if (preventDecorationToken != null) { req.setAttribute(preventDecorationToken, Boolean.TRUE); } String definitionName = getDefinitionForRequest(req); container.render(definitionName, request); } filterChain.doFilter(req, res); }  void init(FilterConfig config); void destroy(); void doFilter(javax.servlet.ServletRequest req, ServletResponse res, FilterChain filterChain); static final String CONTAINER_KEY_INIT_PARAMETER; }
@SuppressWarnings("unchecked") @Test public void testDoFilter() throws IOException, ServletException { HttpServletRequest request = createMock(HttpServletRequest.class); HttpServletResponse response = createMock(HttpServletResponse.class); FilterChain chain = createMock(FilterChain.class); ApplicationContext applicationContext = createMock(ApplicationContext.class); Map<String, Object> applicationScope = createMock(Map.class); TilesContainer container = createMock(TilesContainer.class); AttributeContext attributeContext = createMock(AttributeContext.class); expect(request.getAttribute("org.apache.tiles.decoration.PREVENT:tokenKey")).andReturn(null); expect(servletContext.getAttribute(ApplicationAccess.APPLICATION_CONTEXT_ATTRIBUTE)) .andReturn(applicationContext); expect(applicationContext.getApplicationScope()).andReturn(applicationScope); expect(applicationScope.get("key")).andReturn(container); expect(container.getAttributeContext(isA(ServletRequest.class))).andReturn(attributeContext); request.setAttribute("org.apache.tiles.decoration.PREVENT:tokenKey", true); expect(request.getAttribute("javax.servlet.include.servlet_path")).andReturn(null); expect(request.getServletPath()).andReturn("/tiles"); container.render(eq("definitionKey"), isA(ServletRequest.class)); chain.doFilter(request, response); replay(servletContext, request, response, chain, applicationContext, applicationScope, container, attributeContext); filter.doFilter(request, response, chain); verify(request, response, chain, applicationContext, applicationScope, container, attributeContext); }