FileDocCategorySizeDatePackage
ActionContextCleanUpTest.javaAPI DocExample6564Mon Jul 23 13:26:12 BST 2007org.apache.struts2.dispatcher

ActionContextCleanUpTest

public class ActionContextCleanUpTest extends TestCase
version
$Date: 2006-11-23 12:31:52 -0500 (Thu, 23 Nov 2006) $ $Id: ActionContextCleanUpTest.java 478625 2006-11-23 17:31:52Z wsmoak $

Fields Summary
protected org.springframework.mock.web.MockFilterConfig
filterConfig
protected org.springframework.mock.web.MockHttpServletRequest
request
protected org.springframework.mock.web.MockHttpServletResponse
response
protected com.mockobjects.servlet.MockFilterChain
filterChain
protected com.mockobjects.servlet.MockFilterChain
filterChain2
protected org.springframework.mock.web.MockServletContext
servletContext
protected Counter
counter
protected Map
_tmpStore
protected InnerDispatcher
_dispatcher
protected InnerDispatcher
_dispatcher2
protected ActionContextCleanUp
cleanUp
protected ActionContextCleanUp
cleanUp2
Constructors Summary
Methods Summary
protected voidsetUp()

        Dispatcher.setInstance(null);

        counter = new Counter();
        _tmpStore = new LinkedHashMap<String, Integer>();

        filterConfig = new MockFilterConfig();
        request = new MockHttpServletRequest();
        response = new MockHttpServletResponse();
        servletContext = new MockServletContext();
        _dispatcher = new InnerDispatcher(servletContext) {
            @Override
            public String toString() {
                return "dispatcher";
            }
        };
        _dispatcher2 = new InnerDispatcher(servletContext){
            @Override
            public String toString() {
                return "dispatcher2";
            }
        };


        filterChain = new MockFilterChain() {
            @Override
            public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
                _tmpStore.put("counter"+(counter.count++), (Integer) request.getAttribute("__cleanup_recursion_counter"));
            }
        };

        cleanUp = new ActionContextCleanUp();
        cleanUp2 = new ActionContextCleanUp();
        filterChain2 = new MockFilterChain() {
            @Override
            public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
                _tmpStore.put("counter"+(counter.count++), (Integer) request.getAttribute("__cleanup_recursion_counter"));
                cleanUp2.doFilter(request, response, filterChain);
            }
        };
    
protected voidtearDown()

        filterConfig = null;
        request = null;
        response = null;
        filterChain = null;
        filterChain2 = null;
        servletContext = null;
        counter = null;
        _tmpStore = null;
        _dispatcher = null;
        _dispatcher2 = null;
        cleanUp = null;
        cleanUp2 = null;
    
public voidtestMultiple()

        assertNull(request.getAttribute("__cleanup_recursion_counter"));

        cleanUp.init(filterConfig);
        cleanUp2.init(filterConfig);
        cleanUp.doFilter(request, response, filterChain2);
        cleanUp2.destroy();
        cleanUp.destroy();

        assertEquals(_tmpStore.size(), 2);
        assertEquals(_tmpStore.get("counter0"), new Integer(1));
        assertEquals(_tmpStore.get("counter1"), new Integer(2));

        assertEquals(request.getAttribute("__cleanup_recursion_counter"), new Integer("0"));
    
public voidtestSingle()

        assertNull(request.getAttribute("__cleanup_recursion_counter"));

        cleanUp.init(filterConfig);
        cleanUp.doFilter(request, response, filterChain);
        cleanUp.destroy();

        assertEquals(_tmpStore.size(), 1);
        assertEquals(_tmpStore.get("counter0"), new Integer(1));

        assertEquals(request.getAttribute("__cleanup_recursion_counter"), new Integer("0"));