Search in sources :

Example 16 with PageProvider

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

the class BookmarkableMapperTest 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("wicket/bookmarkable/" + PAGE_CLASS_NAME + "/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 17 with PageProvider

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

the class CryptoMapperTest method pageParameters.

/**
 * Tests that named and indexed parameters are properly (en|de)crypted
 */
@Test
public void pageParameters() {
    String expectedEncrypted = "L7ExSNbPC4sb6TPJDblCAopL53TWmZP5y7BQEaJSJAC05HXod5M5U7gT2yNT0lK5L6L09ZAOoZkGyUhseyPrC4S5tqUUrV6zipc4_Ni877FDOOoE5C_Cd7YCyK1xSScpVhno6LeBz2wiu5oWyf7hB1RKcv6zkhEBmbx8vU7K7-e4xe1_LO8Y3fhEjMSQyU9BVh7Uz4HKzkR2OxFo5LaDzQ/L7E59/yPr6a/5L6ae/OxF2c";
    PageParameters expectedParameters = new PageParameters();
    expectedParameters.add("namedKey1", "namedValue1");
    expectedParameters.add("namedKey2", "namedValue2");
    expectedParameters.set(0, "indexedValue1");
    expectedParameters.set(1, "indexedValue2");
    RenderPageRequestHandler renderPageRequestHandler = new RenderPageRequestHandler(new PageProvider(Page2.class, expectedParameters));
    Url url = mapper.mapHandler(renderPageRequestHandler);
    assertEquals(expectedEncrypted, url.toString());
    Request request = getRequest(url);
    IRequestHandler requestHandler = mapper.mapRequest(request);
    assertNotNull(requestHandler);
    requestHandler = unwrapRequestHandlerDelegate(requestHandler);
    assertThat(requestHandler, instanceOf(RenderPageRequestHandler.class));
    RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler;
    assertEquals(Page2.class, handler.getPageClass());
    PageParameters actualParameters = handler.getPageParameters();
    assertEquals(expectedParameters, actualParameters);
}
Also used : RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) IRequestHandler(org.apache.wicket.request.IRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) 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 18 with PageProvider

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

the class CryptoMapperTest method homePageWithNonEncryptedQueryParameters.

/**
 * Verifies that the home page can be reached with non-encrypted query parameters.
 * https://issues.apache.org/jira/browse/WICKET-4345
 *
 * Also, test that the URL for the home page with non-encrypted parameters is not encrypted, to avoid unnecessary redirects.
 */
@Test
public void homePageWithNonEncryptedQueryParameters() {
    String expectedEncrypted = "?namedKey1=namedValue1";
    PageParameters expectedParameters = new PageParameters();
    expectedParameters.add("namedKey1", "namedValue1");
    RenderPageRequestHandler renderPageRequestHandler = new RenderPageRequestHandler(new PageProvider(tester.getApplication().getHomePage(), expectedParameters));
    Url url = mapper.mapHandler(renderPageRequestHandler);
    assertEquals(expectedEncrypted, url.toString());
    Request request = getRequest(url);
    IRequestHandler requestHandler = mapper.mapRequest(request);
    assertNotNull(requestHandler);
    requestHandler = unwrapRequestHandlerDelegate(requestHandler);
    assertThat(requestHandler, instanceOf(RenderPageRequestHandler.class));
    RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler;
    assertEquals(tester.getApplication().getHomePage(), handler.getPageClass());
    StringValue queryParam = handler.getPageParameters().get("namedKey1");
    assertEquals("namedValue1", queryParam.toOptionalString());
}
Also used : RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) IRequestHandler(org.apache.wicket.request.IRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) Request(org.apache.wicket.request.Request) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) StringValue(org.apache.wicket.util.string.StringValue) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 19 with PageProvider

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

the class CryptoMapperTest method bookmarkablePageEncrypt.

/**
 * Tests that URLs for bookmarkable pages are encrypted.
 */
@Test
public void bookmarkablePageEncrypt() {
    IRequestHandler renderPage2BookmarkableHandler = new RenderPageRequestHandler(new PageProvider(Page2.class, new PageParameters()));
    Url plainTextUrl = mapper.getDelegateMapper().mapHandler(renderPage2BookmarkableHandler);
    assertEquals(PLAIN_BOOKMARKABLE_URL, plainTextUrl.toString());
    Url encryptedUrl = mapper.mapHandler(renderPage2BookmarkableHandler);
    assertEquals(ENCRYPTED_BOOKMARKABLE_URL, encryptedUrl.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) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 20 with PageProvider

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

the class CryptoMapperTest method expiredMarkedEncryptedUrlThrowsPageExpiredException.

@Test(expected = PageExpiredException.class)
public void expiredMarkedEncryptedUrlThrowsPageExpiredException() {
    mapper.setMarkEncryptedUrls(true);
    Url encryptedUrl = mapper.mapHandler(new RenderPageRequestHandler(new PageProvider(Page2.class)));
    assertTrue(encryptedUrl.getSegments().get(0).startsWith("crypt."));
    encryptedUrl.getSegments().remove(0);
    encryptedUrl.getSegments().add(0, "crypt.no decryptable");
    mapper.mapRequest(getRequest(encryptedUrl));
}
Also used : RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) 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