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")));
}
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);
}
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)));
}
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());
}
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));
}
Aggregations