Search in sources :

Example 41 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest in project wicket by apache.

the class UrlRendererTest method test12.

/**
 * <a href="https://issues.apache.org/jira/browse/WICKET-3567">WICKET-3567</a>
 */
@Test
public void test12() {
    UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("?0")));
    assertEquals("./", r1.renderUrl(Url.parse("")));
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Test(org.junit.Test)

Example 42 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest in project wicket by apache.

the class UrlRendererTest method renderFullUrlWithNoOpLeadingSegments.

/**
 * https://issues.apache.org/jira/browse/WICKET-5774
 */
@Test
public void renderFullUrlWithNoOpLeadingSegments() {
    UrlRenderer renderer = new UrlRenderer(new MockWebRequest(Url.parse("any/thing")));
    String fullUrl = renderer.renderFullUrl(Url.parse("http://www.example.com:8888/./../one/two/three"));
    assertEquals("http://www.example.com:8888/one/two/three", fullUrl);
    fullUrl = renderer.renderFullUrl(Url.parse("http://www.example.com:8888/.././one/two/three"));
    assertEquals("http://www.example.com:8888/one/two/three", fullUrl);
    fullUrl = renderer.renderFullUrl(Url.parse("http://www.example.com:8888/one/.././two/three"));
    assertEquals("http://www.example.com:8888/two/three", fullUrl);
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Test(org.junit.Test)

Example 43 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest in project wicket by apache.

the class WriteCallbackTest method writeStream.

/**
 */
@Test
public void writeStream() throws IOException {
    WriteCallback callback = new WriteCallback() {

        @Override
        public void writeData(Attributes attributes) {
        }
    };
    ByteArrayResponse response = new ByteArrayResponse();
    Attributes attributes = new Attributes(new MockWebRequest(new Url()), response);
    byte[] srcData = new byte[5000];
    for (int i = 0; i < srcData.length; i++) {
        srcData[i] = (byte) i;
    }
    InputStream in = new ByteArrayInputStream(srcData);
    callback.writeStream(attributes, in);
    assertTrue("Content not equal", Arrays.equals(response.getBytes(), srcData));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Attributes(org.apache.wicket.request.resource.IResource.Attributes) WriteCallback(org.apache.wicket.request.resource.AbstractResource.WriteCallback) MockWebRequest(org.apache.wicket.mock.MockWebRequest) ByteArrayResponse(org.apache.wicket.response.ByteArrayResponse) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 44 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest in project wicket by apache.

the class UrlRendererTest method renderFullUrlWithAbsoluteArgument.

/**
 * https://issues.apache.org/jira/browse/WICKET-4514
 */
@Test
public void renderFullUrlWithAbsoluteArgument() {
    Url baseUrl = Url.parse("one/two/three");
    baseUrl.setProtocol("http");
    baseUrl.setHost("www.example.com");
    baseUrl.setPort(8888);
    UrlRenderer renderer = new UrlRenderer(new MockWebRequest(baseUrl));
    // this is needed because MockWebRequest cuts data
    renderer.setBaseUrl(baseUrl);
    // url starting with slash is
    String fullUrl = renderer.renderFullUrl(Url.parse("/four"));
    // considered absolute
    assertEquals("http://www.example.com:8888/four", fullUrl);
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 45 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest in project wicket by apache.

the class UrlRendererTest method rendersRelativeUrl.

@Test
public void rendersRelativeUrl() {
    Url contextRelativeUrl = new Url();
    contextRelativeUrl.setProtocol("http");
    contextRelativeUrl.setHost("localshot");
    contextRelativeUrl.setPort(8080);
    contextRelativeUrl.setContextRelative(true);
    contextRelativeUrl.getSegments().addAll(asList("", ""));
    UrlRenderer r1 = new UrlRenderer(new MockWebRequest(contextRelativeUrl));
    assertThat(r1.renderRelativeUrl(Url.parse("foo")), is("../foo"));
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Aggregations

MockWebRequest (org.apache.wicket.mock.MockWebRequest)54 Test (org.junit.Test)52 UrlRenderer (org.apache.wicket.request.UrlRenderer)47 Url (org.apache.wicket.request.Url)29 Locale (java.util.Locale)2 MockServletContext (org.apache.wicket.protocol.http.mock.MockServletContext)2 IRequestHandler (org.apache.wicket.request.IRequestHandler)2 Binder (com.google.inject.Binder)1 Module (com.google.inject.Module)1 Provider (com.google.inject.Provider)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Session (org.apache.wicket.Session)1 MockApplication (org.apache.wicket.mock.MockApplication)1 WebSession (org.apache.wicket.protocol.http.WebSession)1 IExceptionMapper (org.apache.wicket.request.IExceptionMapper)1 IRequestCycle (org.apache.wicket.request.IRequestCycle)1