Search in sources :

Example 1 with MockServletContext

use of com.helger.servlet.mock.MockServletContext in project ph-web by phax.

the class RequestHelperTest method testGetRequestURI.

@Test
public void testGetRequestURI() {
    final MockServletContext aSC = MockServletContext.create();
    try {
        MockHttpServletRequest r = new MockHttpServletRequest(aSC, EHttpMethod.GET).setAllPaths("/context/servlet/index.xyz?x=1");
        assertEquals("/context/servlet/index.xyz", RequestHelper.getRequestURIDecoded(r));
        r.addParameter("abc", "xyz");
        assertEquals("/context/servlet/index.xyz", RequestHelper.getRequestURIDecoded(r));
        r = new MockHttpServletRequest(aSC, EHttpMethod.GET).setAllPaths("/context/servlet/in%3adex.xyz?x=1");
        assertEquals("/context/servlet/in:dex.xyz", RequestHelper.getRequestURIDecoded(r));
        assertEquals("/context/servlet/in%3adex.xyz", RequestHelper.getRequestURIEncoded(r));
        r.addParameter("abc", "xyz");
        assertEquals("/context/servlet/in:dex.xyz", RequestHelper.getRequestURIDecoded(r));
        assertEquals("/context/servlet/in%3adex.xyz", RequestHelper.getRequestURIEncoded(r));
    } finally {
        aSC.invalidate();
    }
}
Also used : MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) MockServletContext(com.helger.servlet.mock.MockServletContext) Test(org.junit.Test)

Example 2 with MockServletContext

use of com.helger.servlet.mock.MockServletContext in project ph-web by phax.

the class RequestLoggerTest method testBasic.

@Test
public void testBasic() {
    final MockServletContext aSC = MockServletContext.create();
    try {
        final HttpServletRequest aHttpRequest = new MockHttpServletRequest(aSC);
        assertNotNull(RequestLogger.getRequestFieldMap(aHttpRequest));
    } finally {
        aSC.invalidate();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) MockServletContext(com.helger.servlet.mock.MockServletContext) Test(org.junit.Test)

Aggregations

MockHttpServletRequest (com.helger.servlet.mock.MockHttpServletRequest)2 MockServletContext (com.helger.servlet.mock.MockServletContext)2 Test (org.junit.Test)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1