Search in sources :

Example 96 with PageParameters

use of org.apache.wicket.request.mapper.parameter.PageParameters in project wicket by apache.

the class BookmarkableMapperTest 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:
 * /wicket/bookmarkable/my.Product?3&id=23
 * to
 * /wicket/bookmarkable/my.Product?3&id=24
 * then Wicket will create a new page that will show product=24
 */
@Test
void decode4() {
    Url url = Url.parse("wicket/bookmarkable/" + PAGE_CLASS_NAME + "/i1/i2?15&a=b&b=c");
    IRequestHandler handler = encoder.mapRequest(getRequest(url));
    assertThat(handler).isInstanceOf(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.jupiter.api.Test)

Example 97 with PageParameters

use of org.apache.wicket.request.mapper.parameter.PageParameters in project wicket by apache.

the class DefaultPageFactoryTest method privateConstructorWithParameters.

@Test
void privateConstructorWithParameters() {
    PageParameters parameters = new PageParameters();
    parameters.add("key", "value");
    Exception e = assertThrows(WicketRuntimeException.class, () -> {
        pageFactory.newPage(PrivateConstructorWithParametersPage.class, parameters);
    });
    assertEquals("Can't instantiate page using constructor 'private org.apache.wicket.session.DefaultPageFactoryTest$PrivateConstructorWithParametersPage(org.apache.wicket.request.mapper.parameter.PageParameters)' and argument 'key=[value]'. This constructor is private!", e.getMessage());
}
Also used : PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) ResetResponseException(org.apache.wicket.request.flow.ResetResponseException) Test(org.junit.jupiter.api.Test)

Example 98 with PageParameters

use of org.apache.wicket.request.mapper.parameter.PageParameters in project wicket by apache.

the class DefaultPageFactoryTest method abortAndRespondContract.

/**
 * Verifies page factory bubbles ResetResponseException
 */
@Test
void abortAndRespondContract() {
    try {
        pageFactory.newPage(AbortAndRespondPage1.class);
        fail();
    } catch (ResetResponseException e) {
    // noop
    }
    try {
        pageFactory.newPage(AbortAndRespondPage2.class);
        fail();
    } catch (ResetResponseException e) {
    // noop
    }
    try {
        pageFactory.newPage(AbortAndRespondPage2.class, new PageParameters());
        fail();
    } catch (ResetResponseException e) {
    // noop
    }
    try {
        pageFactory.newPage(AbortAndRespondPage3.class);
        fail();
    } catch (ResetResponseException e) {
    // noop
    }
    try {
        pageFactory.newPage(AbortAndRespondPage3.class, new PageParameters());
        fail();
    } catch (ResetResponseException e) {
    // noop
    }
    try {
        pageFactory.newPage(PageThrowingCheckedException.class);
        fail();
    } catch (WicketRuntimeException e) {
        assertNotNull(e.getCause());
        assertNotNull(e.getCause().getCause());
        assertEquals(PageThrowingCheckedException.EXCEPTION, e.getCause().getCause());
    } catch (Exception e) {
        fail();
    }
}
Also used : WicketRuntimeException(org.apache.wicket.WicketRuntimeException) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) ResetResponseException(org.apache.wicket.request.flow.ResetResponseException) ResetResponseException(org.apache.wicket.request.flow.ResetResponseException) Test(org.junit.jupiter.api.Test)

Example 99 with PageParameters

use of org.apache.wicket.request.mapper.parameter.PageParameters in project wicket by apache.

the class StatelessComponentTest method statelessComponentPageWithParamsWithIndexMount.

/**
 * @throws Exception
 */
@Test
void statelessComponentPageWithParamsWithIndexMount() throws Exception {
    PageParameters params = new PageParameters();
    params.set(0, "testValue1");
    params.set(1, "testValue2");
    tester.getApplication().mountPage("/stateless", StatelessComponentPageWithParams.class);
    // test is always the home page. it doesn't work then
    executeTest(StatelessComponentPageWithParams.class, params, "StatelessComponentPageWithParams_indexed_mount_result.html");
    tester.getRequest().setUrl(Url.parse("stateless/testValue1/testValue2?0-1.-link"));
    try {
        tester.processRequest();
        fail("An exception should have been thrown for this request!");
    } catch (Exception e) {
        assertEquals("wanted exception", e.getMessage());
    }
}
Also used : PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Test(org.junit.jupiter.api.Test)

Example 100 with PageParameters

use of org.apache.wicket.request.mapper.parameter.PageParameters in project wicket by apache.

the class StatelessFormTest method pageWithParameters.

/**
 * Tests if a stateless form renders an action url containing the pageparameters
 *
 * @throws Exception
 */
@Test
void pageWithParameters() throws Exception {
    PageParameters parameters = new PageParameters();
    parameters.add("first", "foo");
    parameters.add("second", "bar");
    executeTest(StatelessPageWithForm.class, parameters, "StatelessPageWithForm_expected.html");
}
Also used : PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Test(org.junit.jupiter.api.Test)

Aggregations

PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)272 Test (org.junit.jupiter.api.Test)79 Url (org.apache.wicket.request.Url)56 IRequestHandler (org.apache.wicket.request.IRequestHandler)39 PageProvider (org.apache.wicket.core.request.handler.PageProvider)27 StringValue (org.apache.wicket.util.string.StringValue)26 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)23 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)20 IPageProvider (org.apache.wicket.core.request.handler.IPageProvider)20 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)18 BookmarkablePageRequestHandler (org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler)17 ResourceUrl (org.apache.wicket.request.resource.caching.ResourceUrl)16 Test (org.junit.Test)16 Page (org.apache.wicket.Page)10 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)10 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)10 ResourceReferenceRequestHandler (org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler)10 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)8 IOException (java.io.IOException)8 WebPage (org.apache.wicket.markup.html.WebPage)8