Search in sources :

Example 1 with MockPageParametersAware

use of org.apache.wicket.MockPageParametersAware in project wicket by apache.

the class WicketTesterTest method multiValueParametersOnFormSubmit.

/**
 * Asserting the parameters set by user on request get processed when submitting a form
 */
@Test
public void multiValueParametersOnFormSubmit() {
    tester.startPage(MockPageParametersAware.class);
    FormTester formTester = tester.newFormTester("form");
    formTester.setValue("textfield", "v1");
    tester.getRequest().getPostParameters().setParameterValue("p_1", "p_1_value");
    tester.getRequest().setParameter("q_1", "q_1_value");
    formTester.submit();
    MockPageParametersAware page = (MockPageParametersAware) tester.getLastRenderedPage();
    assertEquals("v1", page.getLastPostParameters().getParameterValue("textfield").toString());
    assertEquals("p_1_value", page.getLastPostParameters().getParameterValue("p_1").toString());
    assertEquals("q_1_value", page.getLastQueryParameters().getParameterValue("q_1").toString());
}
Also used : MockPageParametersAware(org.apache.wicket.MockPageParametersAware) Test(org.junit.Test)

Example 2 with MockPageParametersAware

use of org.apache.wicket.MockPageParametersAware in project wicket by apache.

the class WicketTesterTest method parametersOnFormSubmit.

/**
 * Asserting the parameters set by user in request get processed when submitting a form
 */
@Test
public void parametersOnFormSubmit() {
    tester.startPage(MockPageParametersAware.class);
    FormTester formTester = tester.newFormTester("form");
    formTester.setValue("textfield", "v1");
    tester.getRequest().getPostParameters().setParameterValue("p_1", "p_1_value");
    tester.getRequest().setParameter("q_1", "q_1_value");
    formTester.submit();
    MockPageParametersAware page = (MockPageParametersAware) tester.getLastRenderedPage();
    assertEquals("v1", page.getLastPostParameters().getParameterValue("textfield").toString());
    assertEquals("p_1_value", page.getLastPostParameters().getParameterValue("p_1").toString());
    assertEquals("q_1_value", page.getLastQueryParameters().getParameterValue("q_1").toString());
}
Also used : MockPageParametersAware(org.apache.wicket.MockPageParametersAware) Test(org.junit.Test)

Example 3 with MockPageParametersAware

use of org.apache.wicket.MockPageParametersAware 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());
}
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) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 4 with MockPageParametersAware

use of org.apache.wicket.MockPageParametersAware in project wicket by apache.

the class WicketTesterTest method setQueryParameter.

/**
 * Asserting that parameters set by user in request make part of the processed request
 * parameters
 */
@Test
public void setQueryParameter() {
    tester.getRequest().setParameter("p1", "v1");
    tester.startPage(MockPageParametersAware.class);
    MockPageParametersAware page = (MockPageParametersAware) tester.getLastRenderedPage();
    assertEquals("v1", page.getLastQueryParameters().getParameterValue("p1").toString());
}
Also used : MockPageParametersAware(org.apache.wicket.MockPageParametersAware) Test(org.junit.Test)

Example 5 with MockPageParametersAware

use of org.apache.wicket.MockPageParametersAware 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)

Aggregations

MockPageParametersAware (org.apache.wicket.MockPageParametersAware)5 Test (org.junit.Test)5 BookmarkablePageRequestHandler (org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler)2 IPageProvider (org.apache.wicket.core.request.handler.IPageProvider)2 PageProvider (org.apache.wicket.core.request.handler.PageProvider)2 IRequestHandler (org.apache.wicket.request.IRequestHandler)2 Url (org.apache.wicket.request.Url)2 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)2 IRequestParameters (org.apache.wicket.request.IRequestParameters)1 StringValue (org.apache.wicket.util.string.StringValue)1