use of org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler in project wicket by apache.
the class WicketTesterTest method setQueryParameterWhenRequestHasAnQueryUrl.
/**
* Asserting that parameters set in request get processed, even if the request URL already has
* query parameters
*/
@Test
public void setQueryParameterWhenRequestHasAnQueryUrl() {
PageParameters parameters = new PageParameters();
parameters.set("q_1", "q_1_value");
IPageProvider testPageProvider = new PageProvider(MockPageParametersAware.class, parameters);
IRequestHandler pageRequestHandler = new BookmarkablePageRequestHandler(testPageProvider);
Url url = tester.getApplication().getRootRequestMapper().mapHandler(pageRequestHandler);
tester.getRequest().setParameter("q_2", "q_2_value");
tester.getRequest().setUrl(url);
tester.processRequest();
MockPageParametersAware page = (MockPageParametersAware) tester.getLastRenderedPage();
assertEquals("q_1_value", page.getLastQueryParameters().getParameterValue("q_1").toString());
assertEquals("q_2_value", page.getLastQueryParameters().getParameterValue("q_2").toString());
}
use of org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler in project wicket by apache.
the class ISecuritySettingsTest method enforceMountsWithCryptoMapper.
/**
* https://issues.apache.org/jira/browse/WICKET-5560
*/
@Test
public void enforceMountsWithCryptoMapper() {
WebApplication app = tester.getApplication();
IRequestHandler handler = new BookmarkablePageRequestHandler(new PageProvider(UnknownPage.class));
String plainTextNonMountedUrl = tester.urlFor(handler).toString();
assertTrue("Plain text non mounted url should start with wicket/bookmarkable/: " + plainTextNonMountedUrl, plainTextNonMountedUrl.startsWith("wicket/bookmarkable/"));
tester.executeUrl(plainTextNonMountedUrl);
tester.assertRenderedPage(UnknownPage.class);
app.setRootRequestMapper(new CryptoMapper(app.getRootRequestMapper(), app));
/*
* Execute dummy request to get WicketTester to re-initialise with CryptoMapper in place.
*/
tester.executeUrl("");
String encryptedNonMountedUrl = tester.urlFor(handler).toString();
assertFalse("Encrypted URL should not start with wicket/bookmarkable/" + encryptedNonMountedUrl, encryptedNonMountedUrl.startsWith("wicket/bookmarkable/"));
tester.executeUrl(plainTextNonMountedUrl);
assertNull(tester.getLastRenderedPage());
tester.executeUrl(encryptedNonMountedUrl);
tester.assertRenderedPage(UnknownPage.class);
app.mountPackage("unknown", UnknownPage.class);
tester.executeUrl(plainTextNonMountedUrl);
assertNull(tester.getLastRenderedPage());
tester.executeUrl(encryptedNonMountedUrl);
tester.assertRenderedPage(UnknownPage.class);
app.getSecuritySettings().setEnforceMounts(true);
tester.executeUrl(plainTextNonMountedUrl);
assertNull(tester.getLastRenderedPage());
tester.executeUrl(encryptedNonMountedUrl);
assertNull(tester.getLastRenderedPage());
}
use of org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler in project wicket by apache.
the class BaseWicketTester method startPage.
/**
* Renders a <code>Page</code> from its default constructor.
*
* @param <C>
* @param pageClass
* a test <code>Page</code> class with default constructor
* @param parameters
* the parameters to use for the class.
* @return the rendered <code>Page</code>
*/
@SuppressWarnings("unchecked")
public final <C extends Page> C startPage(final Class<C> pageClass, final PageParameters parameters) {
Args.notNull(pageClass, "pageClass");
// must be null for Pages
componentInPage = null;
// prepare the request
request.setUrl(application.getRootRequestMapper().mapHandler(new BookmarkablePageRequestHandler(new PageProvider(pageClass, parameters))));
// process the request
processRequest();
// The last rendered page
return (C) getLastRenderedPage();
}
use of org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler in project wicket by apache.
the class AbstractBookmarkableMapper method mapHandler.
@Override
public Url mapHandler(IRequestHandler requestHandler) {
// eliminate the need for IRequestHandlerDelegate
while (requestHandler instanceof IRequestHandlerDelegate) {
requestHandler = ((IRequestHandlerDelegate) requestHandler).getDelegateHandler();
}
if (requestHandler instanceof BookmarkablePageRequestHandler) {
// simple bookmarkable URL with no page instance information
BookmarkablePageRequestHandler handler = (BookmarkablePageRequestHandler) requestHandler;
if (!checkPageClass(handler.getPageClass())) {
return null;
}
PageInfo info = new PageInfo();
UrlInfo urlInfo = new UrlInfo(new PageComponentInfo(info, null), handler.getPageClass(), handler.getPageParameters());
return buildUrl(urlInfo);
} else if (requestHandler instanceof RenderPageRequestHandler) {
// possibly hybrid URL - bookmarkable URL with page instance information
// but only allowed if the page was created by bookmarkable URL
RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler;
if (!checkPageClass(handler.getPageClass())) {
return null;
}
if (handler.getPageProvider().isNewPageInstance()) {
// no existing page instance available, don't bother creating new page instance
PageInfo info = new PageInfo();
UrlInfo urlInfo = new UrlInfo(new PageComponentInfo(info, null), handler.getPageClass(), handler.getPageParameters());
return buildUrl(urlInfo);
}
IRequestablePage page = handler.getPage();
if (checkPageInstance(page) && (!pageMustHaveBeenCreatedBookmarkable() || page.wasCreatedBookmarkable())) {
PageInfo info = getPageInfo(handler);
PageComponentInfo pageComponentInfo = new PageComponentInfo(info, null);
UrlInfo urlInfo = new UrlInfo(pageComponentInfo, page.getClass(), handler.getPageParameters());
return buildUrl(urlInfo);
} else {
return null;
}
} else if (requestHandler instanceof BookmarkableListenerRequestHandler) {
// request listener URL with page class information
BookmarkableListenerRequestHandler handler = (BookmarkableListenerRequestHandler) requestHandler;
Class<? extends IRequestablePage> pageClass = handler.getPageClass();
if (!checkPageClass(pageClass)) {
return null;
}
Integer renderCount = null;
if (handler.includeRenderCount()) {
renderCount = handler.getRenderCount();
}
PageInfo pageInfo = getPageInfo(handler);
ComponentInfo componentInfo = new ComponentInfo(renderCount, handler.getComponentPath(), handler.getBehaviorIndex());
PageParameters parameters = getRecreateMountedPagesAfterExpiry() ? new PageParameters(handler.getPage().getPageParameters()).mergeWith(handler.getPageParameters()) : handler.getPageParameters();
UrlInfo urlInfo = new UrlInfo(new PageComponentInfo(pageInfo, componentInfo), pageClass, parameters);
return buildUrl(urlInfo);
}
return null;
}
use of org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler in project wicket by apache.
the class BookmarkableMapperTest method encode1.
/**
*/
@Test
public void encode1() {
PageProvider provider = new PageProvider(MockPage.class, new PageParameters());
provider.setPageSource(context);
IRequestHandler handler = new BookmarkablePageRequestHandler(provider);
Url url = encoder.mapHandler(handler);
assertEquals("wicket/bookmarkable/" + PAGE_CLASS_NAME, url.toString());
}
Aggregations