Search in sources :

Example 26 with PageProvider

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

the class MountedMapperTest method placeholderEncode2.

/**
 */
@Test
public void placeholderEncode2() {
    PageParameters parameters = new PageParameters();
    parameters.set(0, "i1");
    parameters.set(1, "i2");
    parameters.set("a", "b", INamedParameters.Type.QUERY_STRING);
    parameters.set("b", "c", INamedParameters.Type.QUERY_STRING);
    parameters.set("param1", "p1", INamedParameters.Type.PATH);
    parameters.set("param2", "p2", INamedParameters.Type.PATH);
    PageProvider provider = new PageProvider(MockPage.class, parameters);
    provider.setPageSource(context);
    IRequestHandler handler = new BookmarkablePageRequestHandler(provider);
    Url url = placeholderEncoder.mapHandler(handler);
    assertEquals("some/p1/path/p2/i1/i2?a=b&b=c", url.toString());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) BookmarkablePageRequestHandler(org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 27 with PageProvider

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

the class MountedMapperTest method encode3.

/**
 */
@Test
public void encode3() {
    PageParameters parameters = new PageParameters();
    parameters.set(0, "i1");
    parameters.set(1, "i2");
    parameters.set("a", "b", INamedParameters.Type.QUERY_STRING);
    parameters.set("b", "c", INamedParameters.Type.QUERY_STRING);
    PageProvider provider = new PageProvider(MockPage.class, parameters);
    provider.setPageSource(context);
    IRequestHandler handler = new BookmarkablePageRequestHandler(provider);
    Url url = encoder.mapHandler(handler);
    assertEquals("some/mount/path/i1/i2?a=b&b=c", url.toString());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) BookmarkablePageRequestHandler(org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 28 with PageProvider

use of org.apache.wicket.core.request.handler.PageProvider 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 PageProvider

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

the class MountedMapperTest method decode4.

/**
 * 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).
 *
 * Since Wicket 7.0.0 (WICKET-4441) if a new request to hybrid url
 * (a url with both mount path and pageId) has different page parameters
 * than the resolved page then a new page instance with the new parameters
 * is created.
 * This way if a user manipulates manually the product id in url like:
 * /products/23?3
 * to
 * /products/24?3
 * then Wicket will create a new page that will show product=24
 */
@Test
public void decode4() {
    Url url = Url.parse("some/mount/path/i1/i2?15&a=b&b=c");
    IRequestHandler handler = encoder.mapRequest(getRequest(url));
    assertThat(handler, instanceOf(RenderPageRequestHandler.class));
    RenderPageRequestHandler h = (RenderPageRequestHandler) handler;
    ((PageProvider) h.getPageProvider()).setPageSource(context);
    IRequestablePage page = h.getPage();
    checkPage(page, 1);
    PageParameters p = page.getPageParameters();
    assertEquals(2, p.getIndexedCount());
    assertEquals(2, p.getNamedKeys().size());
}
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) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 30 with PageProvider

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

the class MountedMapperTest method optionPlaceholderEncode2.

/**
 */
@Test
public void optionPlaceholderEncode2() {
    PageParameters parameters = new PageParameters();
    parameters.set(0, "i1");
    parameters.set(1, "i2");
    parameters.set("a", "b", INamedParameters.Type.QUERY_STRING);
    parameters.set("b", "c", INamedParameters.Type.QUERY_STRING);
    parameters.set("param2", "p2", INamedParameters.Type.PATH);
    parameters.set("param3", "p3", INamedParameters.Type.PATH);
    PageProvider provider = new PageProvider(MockPage.class, parameters);
    provider.setPageSource(context);
    IRequestHandler handler = new BookmarkablePageRequestHandler(provider);
    Url url = optionPlaceholderEncoder.mapHandler(handler);
    assertEquals("some/path/p2/p3/i1/i2?a=b&b=c", url.toString());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) BookmarkablePageRequestHandler(org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Aggregations

PageProvider (org.apache.wicket.core.request.handler.PageProvider)60 Test (org.junit.Test)49 IRequestHandler (org.apache.wicket.request.IRequestHandler)45 Url (org.apache.wicket.request.Url)38 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)36 IPageProvider (org.apache.wicket.core.request.handler.IPageProvider)34 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)23 BookmarkablePageRequestHandler (org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler)17 MockPage (org.apache.wicket.MockPage)16 Page (org.apache.wicket.Page)5 TestMapperContext (org.apache.wicket.core.request.mapper.TestMapperContext)4 IRequestMapper (org.apache.wicket.request.IRequestMapper)4 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 WebPage (org.apache.wicket.markup.html.WebPage)3 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)3 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)3 MockPageParametersAware (org.apache.wicket.MockPageParametersAware)2 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)2 ExceptionErrorPage (org.apache.wicket.markup.html.pages.ExceptionErrorPage)2