Search in sources :

Example 56 with PageProvider

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

the class WicketTesterTest method setMultiValueQueryParameter.

/**
 * Asserting that multiple parameters added in request and PageParameters get processed
 */
@Test
public void setMultiValueQueryParameter() {
    PageParameters parameters = new PageParameters();
    parameters.add("q_1", "q_1_value_1");
    parameters.add("q_1", "q_1_value_2");
    IPageProvider testPageProvider = new PageProvider(MockPageParametersAware.class, parameters);
    IRequestHandler pageRequestHandler = new BookmarkablePageRequestHandler(testPageProvider);
    Url url = tester.getApplication().getRootRequestMapper().mapHandler(pageRequestHandler);
    tester.getRequest().addParameter("q_2", "q_2_value_1");
    tester.getRequest().addParameter("q_2", "q_2_value_2");
    tester.getRequest().setUrl(url);
    tester.processRequest();
    MockPageParametersAware page = (MockPageParametersAware) tester.getLastRenderedPage();
    IRequestParameters lastQueryParameter = page.getLastQueryParameters();
    List<StringValue> q1ParameterValues = lastQueryParameter.getParameterValues("q_1");
    assertTrue(q1ParameterValues.contains(StringValue.valueOf("q_1_value_1")));
    assertTrue(q1ParameterValues.contains(StringValue.valueOf("q_1_value_2")));
    List<StringValue> q2ParameterValues = lastQueryParameter.getParameterValues("q_2");
    assertTrue(q2ParameterValues.contains(StringValue.valueOf("q_2_value_1")));
    assertTrue(q2ParameterValues.contains(StringValue.valueOf("q_2_value_2")));
}
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) MockPageParametersAware(org.apache.wicket.MockPageParametersAware) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) StringValue(org.apache.wicket.util.string.StringValue) Url(org.apache.wicket.request.Url) IRequestParameters(org.apache.wicket.request.IRequestParameters) Test(org.junit.Test)

Example 57 with PageProvider

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

the class DefaultExceptionMapper method mapUnexpectedExceptions.

/**
 * Maps unexpected exceptions to their corresponding {@link IRequestHandler}.
 *
 * @param e
 * 			the current exception
 * @param application
 * 			the current application object
 * @return the {@link IRequestHandler} for the current exception
 */
protected IRequestHandler mapUnexpectedExceptions(Exception e, final Application application) {
    final ExceptionSettings.UnexpectedExceptionDisplay unexpectedExceptionDisplay = application.getExceptionSettings().getUnexpectedExceptionDisplay();
    logger.error("Unexpected error occurred", e);
    if (ExceptionSettings.SHOW_EXCEPTION_PAGE.equals(unexpectedExceptionDisplay)) {
        Page currentPage = extractCurrentPage();
        return createPageRequestHandler(new PageProvider(new ExceptionErrorPage(e, currentPage)));
    } else if (ExceptionSettings.SHOW_INTERNAL_ERROR_PAGE.equals(unexpectedExceptionDisplay)) {
        return createPageRequestHandler(new PageProvider(application.getApplicationSettings().getInternalErrorPage()));
    }
    // IExceptionSettings.SHOW_NO_EXCEPTION_PAGE
    return new ErrorCodeRequestHandler(500);
}
Also used : ExceptionErrorPage(org.apache.wicket.markup.html.pages.ExceptionErrorPage) ErrorCodeRequestHandler(org.apache.wicket.request.http.handler.ErrorCodeRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) ExceptionErrorPage(org.apache.wicket.markup.html.pages.ExceptionErrorPage) ExceptionSettings(org.apache.wicket.settings.ExceptionSettings)

Example 58 with PageProvider

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

the class HttpsMapperTest method mapRequest.

@Test
public void mapRequest() {
    IRequestMapper delegate = mock(IRequestMapper.class);
    HttpsMapper mapper = new HttpsMapper(delegate, new HttpsConfig());
    ServletWebRequest request = mock(ServletWebRequest.class);
    HttpServletRequest req = mock(HttpServletRequest.class);
    when(request.getContainerRequest()).thenReturn(req);
    // https handler on http request, redirect to https
    setupRequest(req, "http", "localhost", 80, "/ctx", "foo=bar");
    IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(SecurePage.class));
    when(delegate.mapRequest(request)).thenReturn(handler);
    IRequestHandler resolved = mapper.mapRequest(request);
    assertThat(resolved, is(instanceOf(RedirectHandler.class)));
    assertThat(((RedirectHandler) resolved).getUrl(), is("https://localhost/ctx?foo=bar"));
    // http handler on http request, return the original handler
    handler = new RenderPageRequestHandler(new PageProvider(InsecurePage.class));
    reset(delegate);
    when(delegate.mapRequest(request)).thenReturn(handler);
    setupRequest(req, "http", "localhost", 80, "/ctx", "foo=bar");
    resolved = mapper.mapRequest(request);
    assertThat(resolved, is(sameInstance(handler)));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IRequestMapper(org.apache.wicket.request.IRequestMapper) ServletWebRequest(org.apache.wicket.protocol.http.servlet.ServletWebRequest) Test(org.junit.Test)

Example 59 with PageProvider

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

the class PageProviderTest method testPageProperties_stored.

@Test
public void testPageProperties_stored() {
    TestMapperContext mapperContext = new TestMapperContext();
    Page page = new TestPage();
    mapperContext.getPageManager().touchPage(page);
    mapperContext.getPageManager().commitRequest();
    // by cleaning session cache we make sure of not being testing the same in-memory instance
    mapperContext.cleanSessionCache();
    PageProvider provider = mapperContext.new TestPageProvider(page.getPageId(), 0);
    assertTrue(provider.hasPageInstance());
    assertFalse(provider.doesProvideNewPage());
}
Also used : PageProvider(org.apache.wicket.core.request.handler.PageProvider) MockPage(org.apache.wicket.MockPage) Page(org.apache.wicket.Page) WebPage(org.apache.wicket.markup.html.WebPage) TestMapperContext(org.apache.wicket.core.request.mapper.TestMapperContext) Test(org.junit.Test)

Example 60 with PageProvider

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

the class PageProviderTest method pageProviderIsSerializeble.

@Test
public void pageProviderIsSerializeble() throws Exception {
    TestMapperContext mapperContext = new TestMapperContext();
    Page page = new TestPage();
    mapperContext.getPageManager().touchPage(page);
    mapperContext.getPageManager().commitRequest();
    PageProvider pageProvider = new PageProvider(page.getPageId(), page.getRenderCount());
    JavaSerializer javaSerializer = new JavaSerializer("app");
    byte[] serialized = javaSerializer.serialize(pageProvider);
    PageProvider deserialized = (PageProvider) javaSerializer.deserialize(serialized);
    deserialized.setPageSource(mapperContext);
    assertThat(deserialized.getPageInstance(), is(page));
}
Also used : PageProvider(org.apache.wicket.core.request.handler.PageProvider) MockPage(org.apache.wicket.MockPage) Page(org.apache.wicket.Page) WebPage(org.apache.wicket.markup.html.WebPage) TestMapperContext(org.apache.wicket.core.request.mapper.TestMapperContext) JavaSerializer(org.apache.wicket.serialize.java.JavaSerializer) 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