Search in sources :

Example 26 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class MountedMapperTest method optionPlaceholderDecode3.

/**
 */
@Test
public void optionPlaceholderDecode3() {
    Url url = Url.parse("some/path/p2");
    IRequestHandler handler = optionPlaceholderEncoder.mapRequest(getRequest(url));
    assertThat(handler, instanceOf(RenderPageRequestHandler.class));
    IRequestablePage page = ((RenderPageRequestHandler) handler).getPage();
    assertEquals(0, page.getPageParameters().getIndexedCount());
    assertTrue(page.getPageParameters().getNamedKeys().size() == 1);
    assertFalse("param1 should not be set", page.getPageParameters().getNamedKeys().contains("param1"));
    assertEquals("p2", page.getPageParameters().get("param2").toString());
    assertFalse("param3 should not be set", page.getPageParameters().getNamedKeys().contains("param3"));
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 27 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class MountedMapperTest method optionalPlaceholdersBeforeRequiredPlaceholder.

/**
 * WICKET-6461
 */
@Test
public void optionalPlaceholdersBeforeRequiredPlaceholder() throws Exception {
    final MountedMapper mapper = new MountedMapper("/params/#{optional1}/#{optional2}/${required}", MockPage.class) {

        @Override
        protected IMapperContext getContext() {
            return context;
        }

        @Override
        boolean getRecreateMountedPagesAfterExpiry() {
            return true;
        }
    };
    IRequestHandler handler = mapper.mapRequest(getRequest(Url.parse("params/required")));
    assertThat(handler, instanceOf(RenderPageRequestHandler.class));
    IRequestablePage page = ((RenderPageRequestHandler) handler).getPage();
    PageParameters p = page.getPageParameters();
    assertEquals(1, p.getNamedKeys().size());
    assertEquals("required", p.get("required").toString());
    handler = mapper.mapRequest(getRequest(Url.parse("params/optional1/required")));
    assertThat(handler, instanceOf(RenderPageRequestHandler.class));
    page = ((RenderPageRequestHandler) handler).getPage();
    p = page.getPageParameters();
    assertEquals(2, p.getNamedKeys().size());
    assertEquals("required", p.get("required").toString());
    assertEquals("optional1", p.get("optional1").toString());
    handler = mapper.mapRequest(getRequest(Url.parse("params/optional1/optional2/required")));
    assertThat(handler, instanceOf(RenderPageRequestHandler.class));
    page = ((RenderPageRequestHandler) handler).getPage();
    p = page.getPageParameters();
    assertEquals(3, p.getNamedKeys().size());
    assertEquals("required", p.get("required").toString());
    assertEquals("optional1", p.get("optional1").toString());
    assertEquals("optional2", p.get("optional2").toString());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Test(org.junit.Test)

Example 28 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class MountedMapperTest method encode4.

/**
 */
@Test
public void encode4() {
    MockPage page = new MockPage(15);
    page.getPageParameters().set(0, "i1");
    page.getPageParameters().set(1, "i2");
    page.getPageParameters().set("a", "b", INamedParameters.Type.QUERY_STRING);
    page.getPageParameters().set("b", "c", INamedParameters.Type.QUERY_STRING);
    page.setCreatedBookmarkable(true);
    IPageProvider provider = new PageProvider(page);
    IRequestHandler handler = new RenderPageRequestHandler(provider);
    Url url = encoder.mapHandler(handler);
    assertEquals("some/mount/path/i1/i2?15&a=b&b=c", url.toString());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) MockPage(org.apache.wicket.MockPage) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 29 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class MountedMapperTest method optionPlaceholderDecode1.

/**
 */
@Test
public void optionPlaceholderDecode1() {
    Url url = Url.parse("some/p1/path/p2/p3");
    IRequestHandler handler = optionPlaceholderEncoder.mapRequest(getRequest(url));
    assertThat(handler, instanceOf(RenderPageRequestHandler.class));
    IRequestablePage page = ((RenderPageRequestHandler) handler).getPage();
    assertEquals(0, page.getPageParameters().getIndexedCount());
    assertEquals(3, page.getPageParameters().getNamedKeys().size());
    assertEquals("p1", page.getPageParameters().get("param1").toString());
    assertEquals("p2", page.getPageParameters().get("param2").toString());
    assertEquals("p3", page.getPageParameters().get("param3").toString());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 30 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class MountedMapperTest method decode3.

/**
 * The tests resolves pages by id as if they were existed in the page store.
 * These pages have no page parameters (i.e. page.getPageParameters() == null).
 *
 * The request that the encoder does also has no parameters (neither in the path
 * nor in the query string) so the resolved page is assumed to be valid.
 */
@Test
public void decode3() {
    Url url = Url.parse("some/mount/path?15");
    IRequestHandler handler = encoder.mapRequest(getRequest(url));
    assertThat(handler, instanceOf(RenderPageRequestHandler.class));
    IRequestablePage page = ((RenderPageRequestHandler) handler).getPage();
    checkPage(page, 15);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Aggregations

RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)75 IRequestHandler (org.apache.wicket.request.IRequestHandler)64 Test (org.junit.Test)61 Url (org.apache.wicket.request.Url)50 PageProvider (org.apache.wicket.core.request.handler.PageProvider)36 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)32 IPageProvider (org.apache.wicket.core.request.handler.IPageProvider)19 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)16 MockPage (org.apache.wicket.MockPage)13 Request (org.apache.wicket.request.Request)6 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)5 IRequestMapper (org.apache.wicket.request.IRequestMapper)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)3 ComponentInfo (org.apache.wicket.request.mapper.info.ComponentInfo)3 PageComponentInfo (org.apache.wicket.request.mapper.info.PageComponentInfo)3 Page (org.apache.wicket.Page)2 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)2 ListenerRequestHandler (org.apache.wicket.core.request.handler.ListenerRequestHandler)2 WebResponse (org.apache.wicket.request.http.WebResponse)2