Search in sources :

Example 16 with MockHttpServletRequest

use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest in project wicket by apache.

the class SecuredRemoteAddressRequestWrapperFactoryTest method test1.

/**
 */
@Test
public void test1() {
    SecuredRemoteAddressRequestWrapperFactory factory = new SecuredRemoteAddressRequestWrapperFactory();
    MockHttpServletRequest request = tester.getRequest();
    request.setSecure(true);
    assertFalse(factory.needsWrapper(request));
    request.setRemoteAddr("111.222.333.444");
    assertFalse(factory.needsWrapper(request));
    request.setSecure(false);
    assertTrue(factory.needsWrapper(request));
    request.setRemoteAddr("10.222.333.444");
    assertFalse(factory.needsWrapper(request));
    request.setRemoteAddr("129.222.333.444");
    assertTrue(factory.needsWrapper(request));
}
Also used : MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) Test(org.junit.Test)

Example 17 with MockHttpServletRequest

use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest in project wicket by apache.

the class ServletWebRequestTest method wicket3599.

/**
 * Tests that {@link ServletWebRequest#getClientUrl()} returns the current url + the query
 * string when this is not error dispatched request. When the request is error dispatched it
 * returns just the request uri to the error page without the query string
 */
@Test
public void wicket3599() {
    MockHttpServletRequest httpRequest = new MockHttpServletRequest(null, null, null);
    httpRequest.setURL(httpRequest.getContextPath() + "/request/Uri");
    httpRequest.setParameter("some", "parameter");
    ServletWebRequest webRequest = new ServletWebRequest(httpRequest, "");
    Url clientUrl = webRequest.getClientUrl();
    assertEquals("request/Uri?some=parameter", clientUrl.toString());
    // simulates a request that has errors metadata
    httpRequest.setAttribute("javax.servlet.error.request_uri", httpRequest.getContextPath() + "/any/source/of/error");
    ServletWebRequest errorWebRequest = new ServletWebRequest(httpRequest, "");
    Url errorClientUrl = errorWebRequest.getClientUrl();
    assertEquals("any/source/of/error", errorClientUrl.toString());
}
Also used : MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 18 with MockHttpServletRequest

use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest in project wicket by apache.

the class ServletWebRequestTest method testClientURLIsContextRelativeInErrorResponses.

/**
 * <a href="https://issues.apache.org/jira/browse/WICKET-4168">WICKET-4168</a>
 */
@Test
public void testClientURLIsContextRelativeInErrorResponses() {
    MockHttpServletRequest httpRequest = new MockHttpServletRequest(null, null, null);
    httpRequest.setURL(httpRequest.getContextPath() + "/request/Uri");
    String problematiURI = httpRequest.getContextPath() + "/any/source/of/error";
    httpRequest.setAttribute("javax.servlet.error.request_uri", problematiURI);
    ServletWebRequest errorWebRequest = new ServletWebRequest(httpRequest, "");
    Url errorClientUrl = errorWebRequest.getClientUrl();
    assertEquals("any/source/of/error", errorClientUrl.toString());
}
Also used : MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 19 with MockHttpServletRequest

use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest in project wicket by apache.

the class ServletWebRequestTest method wicket5203.

/**
 * Tests that {@link ServletWebRequest#getClientUrl()} returns the current url + the query
 * string when this is not forward dispatched request. When the request is error dispatched it
 * returns just the request uri to the error page without the query string
 */
@Test
public void wicket5203() {
    String filterPath = "filterPath";
    MockHttpServletRequest httpRequest = new MockHttpServletRequest(null, null, null);
    httpRequest.setURL(httpRequest.getContextPath() + '/' + filterPath + "/request/Path");
    httpRequest.setParameter("some", "parameter");
    ServletWebRequest webRequest = new ServletWebRequest(httpRequest, filterPath);
    Url clientUrl = webRequest.getClientUrl();
    assertEquals("request/Path?some=parameter", clientUrl.toString());
    // simulates a request that has errors metadata
    httpRequest.setAttribute("javax.servlet.error.request_uri", httpRequest.getContextPath() + '/' + filterPath + "/any/source/of/error");
    ServletWebRequest errorWebRequest = new ServletWebRequest(httpRequest, filterPath);
    Url errorClientUrl = errorWebRequest.getClientUrl();
    assertEquals("any/source/of/error", errorClientUrl.toString());
}
Also used : MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 20 with MockHttpServletRequest

use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest in project wicket by apache.

the class RequestUtilsTest method charset.

@Test
public void charset() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest(null, null, null);
    request.setCharacterEncoding("UTF-8");
    assertEquals(Charset.forName("UTF-8"), RequestUtils.getCharset(request));
    request.setCharacterEncoding("FOO");
    assertEquals(Charset.forName("UTF-8"), RequestUtils.getCharset(request));
}
Also used : MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) Test(org.junit.Test)

Aggregations

MockHttpServletRequest (org.apache.wicket.protocol.http.mock.MockHttpServletRequest)24 Test (org.junit.Test)13 MockHttpServletResponse (org.apache.wicket.protocol.http.mock.MockHttpServletResponse)5 Url (org.apache.wicket.request.Url)5 Application (org.apache.wicket.Application)4 IOException (java.io.IOException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 FilterChain (javax.servlet.FilterChain)2 ServletException (javax.servlet.ServletException)2 ServletRequest (javax.servlet.ServletRequest)2 ServletResponse (javax.servlet.ServletResponse)2 MockApplication (org.apache.wicket.mock.MockApplication)2 WebApplication (org.apache.wicket.protocol.http.WebApplication)2 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)2 Request (org.apache.wicket.request.Request)2 Attributes (org.apache.wicket.request.resource.IResource.Attributes)2 UrlAttributes (org.apache.wicket.request.resource.ResourceReference.UrlAttributes)2 ByteArrayResponse (org.apache.wicket.response.ByteArrayResponse)2 StringReader (java.io.StringReader)1