Example usage for org.apache.wicket.protocol.http.mock MockHttpServletRequest setUrl

List of usage examples for org.apache.wicket.protocol.http.mock MockHttpServletRequest setUrl

Introduction

In this page you can find the example usage for org.apache.wicket.protocol.http.mock MockHttpServletRequest setUrl.

Prototype

public void setUrl(Url url) 

Source Link

Usage

From source file:fiftyfive.wicket.test.WicketTestUtils.java

License:Apache License

/**
 * Download the requested resource and assert that the binary contents of that
 * resource match the provided byte array.
 *
 * @param tester The WicketTester that was used to render the page being tested
 * @param resourceUri A path to a resource to download, like {@code wicket/resource/...}
 *                    (note the lack of a leading slash)
 * @param expectedBytes The expected binary contents of that resource
 *
 * @since 3.2/*from  w w  w.  j a  v a2s.c  o  m*/
 */
public static void assertDownloadEquals(WicketTester tester, String resourceUri, byte[] expectedBytes) {
    MockHttpSession session = new MockHttpSession(tester.getApplication().getServletContext());
    MockHttpServletRequest request = new MockHttpServletRequest(tester.getApplication(), session,
            tester.getApplication().getServletContext());

    request.setURL(resourceUri);
    tester.processRequest(request);

    byte[] actual = tester.getLastResponse().getBinaryContent();
    Assert.assertArrayEquals(expectedBytes, actual);
}

From source file:sk.drunkenpanda.leaflet.AbstractLeafletTest.java

License:Apache License

/**
 * Prepares request that triggers AJAX behavior and contains parameter with given name and value.
 *
 * @param tester the wicket tester which triggers behavior
 * @param behavior the behavior that should be triggered
 * @param parameterName the name of parameter
 * @param parameterValue the value of parameter
 * @return mock HTTP request that triggers given behavior
 *///  w  w  w .  j a  v  a2 s . co m
protected MockHttpServletRequest prepareRequest(WicketTester tester, AbstractAjaxBehavior behavior,
        String parameterName, String parameterValue) {
    MockHttpServletRequest request = new MockHttpServletRequest(tester.getApplication(),
            tester.getHttpSession(), tester.getServletContext());

    Url url = Url.parse(behavior.getCallbackUrl().toString(), Charset.forName(request.getCharacterEncoding()));

    // make url suitable for wicket tester use. usually this involves stripping any leading ..
    // segments to make the url absolute
    for (Iterator<String> segments = url.getSegments().iterator(); segments.hasNext();) {
        String segment = segments.next();
        if (segment.equals("..") || segment.equals(".")) {
            segments.remove();
        }
    }

    request.addHeader("Wicket-Ajax", "true");
    request.addHeader("Wicket-Ajax-BaseURL", url.toString());
    request.setUrl(url);

    request.setParameter(parameterName, parameterValue);

    return request;
}