Search in sources :

Example 51 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class ResourceMapperTest method validPathWithParamsAndQueryPath.

/**
 * testValidPathWithParamsAndQueryPath()
 */
@Test
public void validPathWithParamsAndQueryPath() {
    Request request = createRequest("test/resource/1/fred?foo=bar&foo=baz&value=12");
    IRequestHandler requestHandler = mapper.mapRequest(request);
    assertNotNull(requestHandler);
    assertEquals(ResourceReferenceRequestHandler.class, requestHandler.getClass());
    assertEquals(request.getUrl(), mapper.mapHandler(requestHandler));
    tester.processRequest(requestHandler);
    PageParameters params = resource.pageParameters;
    assertNotNull(params);
    assertEquals(3, params.getAllNamed().size());
    assertEquals(2, params.getIndexedCount());
    StringValue paramId = params.get(0);
    assertNotNull(paramId);
    assertEquals(1, paramId.toInt());
    StringValue paramName = params.get(1);
    assertNotNull(paramName);
    assertEquals("fred", paramName.toString());
    List<StringValue> foo = params.getValues("foo");
    assertNotNull(foo.size() == 2);
    assertEquals("bar", foo.get(0).toString(""));
    assertEquals("baz", foo.get(1).toString(""));
    StringValue paramValue = params.get("value");
    assertEquals(12, paramValue.toInt());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) StringValue(org.apache.wicket.util.string.StringValue) Test(org.junit.Test)

Example 52 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class ResourceMapperTest method placeholders.

/**
 * testPlaceholders()
 */
@Test
public void placeholders() {
    Request request = createRequest("test2/image/resource/foo/bar?a=abc&b=123");
    IRequestHandler requestHandler = mapperWithPlaceholder.mapRequest(request);
    assertNotNull(requestHandler);
    assertEquals(ResourceReferenceRequestHandler.class, requestHandler.getClass());
    assertEquals(request.getUrl(), mapperWithPlaceholder.mapHandler(requestHandler));
    tester.processRequest(requestHandler);
    PageParameters params = resource.pageParameters;
    assertNotNull(params);
    assertEquals(3, params.getAllNamed().size());
    assertEquals(2, params.getIndexedCount());
    assertEquals("foo", params.get(0).toString());
    assertEquals("bar", params.get(1).toString());
    assertEquals("image", params.get("name").toString());
    assertEquals("abc", params.get("a").toString());
    assertEquals("123", params.get("b").toString());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Test(org.junit.Test)

Example 53 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class ResourceMapperTest method placeholdersWithQueryParamDuplicate.

/**
 * testPlaceholdersWithQueryParamDuplicate()
 */
@Test
public void placeholdersWithQueryParamDuplicate() {
    // we have one named parameter that exists twice
    Request request = createRequest("test2/image/resource/foo/bar?name=name-2&val=123");
    IRequestHandler handler = mapperWithPlaceholder.mapRequest(request);
    assertNotNull(handler);
    assertEquals(ResourceReferenceRequestHandler.class, handler.getClass());
    // the query part of the duplicate should be gone now
    Url newUrl = mapperWithPlaceholder.mapHandler(handler);
    assertEquals(Url.parse("test2/name-2/resource/foo/bar?val=123"), newUrl);
    // create new request
    request = createRequest(newUrl.toString());
    // get handler again
    handler = mapperWithPlaceholder.mapRequest(request);
    assertNotNull(handler);
    tester.processRequest(handler);
    PageParameters params = resource.pageParameters;
    assertNotNull(params);
    assertEquals(2, params.getAllNamed().size());
    assertEquals(2, params.getIndexedCount());
    assertEquals("foo", params.get(0).toString());
    assertEquals("bar", params.get(1).toString());
    assertEquals("name-2", params.get("name").toString());
    assertEquals("123", params.get("val").toString());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 54 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class ResourceMapperTest method requestWithEmptyFilename.

/**
 */
@Test
public void requestWithEmptyFilename() {
    // request invalid path with empty filename
    // this must not return a handler
    Request request = createRequest("test2/image/");
    IRequestHandler handler = mapperWithPlaceholder.mapRequest(request);
    assertNull(handler);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) Test(org.junit.Test)

Example 55 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class ComponentRenderer method renderPage.

/**
 * Collects the html generated by rendering a page.
 *
 * @param page
 *            supplier of the page
 * @return the html rendered by the panel
 */
public CharSequence renderPage(final Supplier<? extends Page> page) {
    return inThreadContext(() -> {
        Request request = newRequest();
        BufferedWebResponse response = new BufferedWebResponse(null);
        RequestCycle cycle = application.createRequestCycle(request, response);
        ThreadContext.setRequestCycle(cycle);
        page.get().renderPage();
        return response.getText();
    });
}
Also used : BufferedWebResponse(org.apache.wicket.protocol.http.BufferedWebResponse) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) MockWebRequest(org.apache.wicket.mock.MockWebRequest) Request(org.apache.wicket.request.Request)

Aggregations

Request (org.apache.wicket.request.Request)63 Test (org.junit.Test)28 IRequestHandler (org.apache.wicket.request.IRequestHandler)26 Url (org.apache.wicket.request.Url)23 WebRequest (org.apache.wicket.request.http.WebRequest)9 Response (org.apache.wicket.request.Response)8 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)6 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)6 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)6 IPageRequestHandler (org.apache.wicket.core.request.handler.IPageRequestHandler)5 ResourceReferenceRequestHandler (org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler)5 MockApplication (org.apache.wicket.mock.MockApplication)4 MockHttpServletRequest (org.apache.wicket.protocol.http.mock.MockHttpServletRequest)4 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)3 Attributes (org.apache.wicket.request.resource.IResource.Attributes)3 PackageResourceReference (org.apache.wicket.request.resource.PackageResourceReference)3 UrlAttributes (org.apache.wicket.request.resource.ResourceReference.UrlAttributes)3 ByteArrayResponse (org.apache.wicket.response.ByteArrayResponse)3