FileDocCategorySizeDatePackage
RequestUtilsTest.javaAPI DocExample3620Mon Jul 23 13:26:26 BST 2007org.apache.struts2

RequestUtilsTest

public class RequestUtilsTest extends TestCase
RequestUtilsTest

Fields Summary
private org.easymock.MockControl
control
private HttpServletRequest
requestMock
Constructors Summary
Methods Summary
protected voidsetUp()

        control = MockControl.createControl(HttpServletRequest.class);
        requestMock = (HttpServletRequest) control.getMock();
    
public voidtestGetServletPathWithRequestURIAndContextPathSet()

        control.expectAndReturn(requestMock.getServletPath(), null);
        control.expectAndReturn(requestMock.getRequestURI(), "/servlet/mycontext/test.jsp");
        control.expectAndReturn(requestMock.getContextPath(), "/servlet");
        control.expectAndReturn(requestMock.getContextPath(), "/servlet");
        control.expectAndReturn(requestMock.getPathInfo(), "test.jsp");
        control.expectAndReturn(requestMock.getPathInfo(), "test.jsp");
        control.replay();
        assertEquals("/mycontext/", RequestUtils.getServletPath(requestMock));
        control.verify();
    
public voidtestGetServletPathWithRequestURIAndContextPathSetButNoPatchInfo()

        control.expectAndReturn(requestMock.getServletPath(), null);
        control.expectAndReturn(requestMock.getRequestURI(), "/servlet/mycontext/");
        control.expectAndReturn(requestMock.getContextPath(), "/servlet");
        control.expectAndReturn(requestMock.getContextPath(), "/servlet");
        control.expectAndReturn(requestMock.getPathInfo(), null);
        control.replay();
        assertEquals("/mycontext/", RequestUtils.getServletPath(requestMock));
        control.verify();
    
public voidtestGetServletPathWithRequestURIAndEmptyContextPath()

        control.expectAndReturn(requestMock.getServletPath(), null);
        control.expectAndReturn(requestMock.getRequestURI(), "/mycontext/test.jsp");
        control.expectAndReturn(requestMock.getContextPath(), "");
        control.expectAndReturn(requestMock.getPathInfo(), "test.jsp");
        control.expectAndReturn(requestMock.getPathInfo(), "test.jsp");
        control.replay();
        assertEquals("/mycontext/", RequestUtils.getServletPath(requestMock));
        control.verify();
    
public voidtestGetServletPathWithServletPathSet()

        control.expectAndReturn(requestMock.getServletPath(), "/mycontext/");
        control.replay();
        assertEquals("/mycontext/", RequestUtils.getServletPath(requestMock));
        control.verify();