Search in sources :

Example 46 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class CryptoMapperTest method resourceReferenceWithLessSegments.

/**
 * Relative ResourceReferences, WICKET-3514
 */
@Test
public void resourceReferenceWithLessSegments() {
    PackageResourceReference resource = new PackageResourceReference(getClass(), "crypt/crypt.txt");
    Url url = mapper.mapHandler(new ResourceReferenceRequestHandler(resource));
    url.getSegments().remove(url.getSegments().size() - 1);
    url.getSegments().remove(url.getSegments().size() - 1);
    url.getSegments().add("less-crypt.txt");
    Request request = getRequest(url);
    IRequestHandler requestHandler = mapper.mapRequest(request);
    assertNotNull(requestHandler);
    requestHandler = unwrapRequestHandlerDelegate(requestHandler);
    assertThat(requestHandler, instanceOf(ResourceReferenceRequestHandler.class));
    ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler) requestHandler;
    assertEquals(getClass(), handler.getResourceReference().getScope());
    assertEquals("less-crypt.txt", handler.getResourceReference().getName());
}
Also used : ResourceReferenceRequestHandler(org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler) IRequestHandler(org.apache.wicket.request.IRequestHandler) PackageResourceReference(org.apache.wicket.request.resource.PackageResourceReference) Request(org.apache.wicket.request.Request) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 47 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class CryptoMapperTest method resourceReferenceWithMoreSegments.

/**
 * Relative ResourceReferences, WICKET-3514
 */
@Test
public void resourceReferenceWithMoreSegments() {
    PackageResourceReference resource = new PackageResourceReference(getClass(), "crypt/crypt.txt");
    Url url = mapper.mapHandler(new ResourceReferenceRequestHandler(resource));
    url.getSegments().remove(url.getSegments().size() - 1);
    url.getSegments().add("more");
    url.getSegments().add("more-crypt.txt");
    Request request = getRequest(url);
    IRequestHandler requestHandler = mapper.mapRequest(request);
    assertNotNull(requestHandler);
    requestHandler = unwrapRequestHandlerDelegate(requestHandler);
    ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler) requestHandler;
    assertEquals(getClass(), handler.getResourceReference().getScope());
    assertEquals("crypt/more/more-crypt.txt", handler.getResourceReference().getName());
}
Also used : ResourceReferenceRequestHandler(org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler) IRequestHandler(org.apache.wicket.request.IRequestHandler) PackageResourceReference(org.apache.wicket.request.resource.PackageResourceReference) Request(org.apache.wicket.request.Request) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 48 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class LocaleAwarePageParametersTest method newApplication.

@Override
protected WebApplication newApplication() {
    return new MockApplication() {

        @Override
        protected void init() {
            super.init();
            mountPage("unaware", LocaleUnawarePageParametersPage.class);
            mount(new MountedMapper("aware", LocaleAwarePageParametersPage.class) {

                @Override
                protected Locale resolveLocale() {
                    return resolveUserLocale();
                }
            });
        }

        @Override
        public Session newSession(Request request, Response response) {
            final Session session = super.newSession(request, response);
            session.setLocale(Locale.GERMANY);
            return session;
        }
    };
}
Also used : Locale(java.util.Locale) Response(org.apache.wicket.request.Response) MockApplication(org.apache.wicket.mock.MockApplication) Request(org.apache.wicket.request.Request) Session(org.apache.wicket.Session)

Example 49 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class MountedMapperTest method exactMountGetsBetterScore_ThanParameterOne_ThenOptionalOne.

@Test
public void exactMountGetsBetterScore_ThanParameterOne_ThenOptionalOne() throws Exception {
    final Url url = Url.parse("all/sindex");
    final MountedMapper exactMount = new MountedMapper("/all/sindex", MockPage.class);
    final MountedMapper requiredParam = new MountedMapper("/all/${exp}", MockPage.class);
    final MountedMapper optionalParameter = new MountedMapper("/all/#{exp}", MockPage.class);
    final MountedMapper requiredOptionalParam = new MountedMapper("/all/${exp}/#{opt}", MockPage.class);
    Request request = getRequest(url);
    final int exactCompatScore = exactMount.getCompatibilityScore(request);
    final int requiredParamScore = requiredParam.getCompatibilityScore(request);
    final int optCompatScore = optionalParameter.getCompatibilityScore(request);
    final int requiredOptCompatScore = requiredOptionalParam.getCompatibilityScore(request);
    // all the mappers above must be eligible for the give URL (i.e. their score must be > 0)
    assertTrue("exactMount mapper must be eligible to handle the request", exactCompatScore > 0);
    assertTrue("requiredParam mapper must be eligible to handle the request", requiredParamScore > 0);
    assertTrue("optionalParameter mapper must be eligible to handle the request", optCompatScore > 0);
    assertTrue("requiredOptionalParam mapper must be eligible to handle the request", requiredOptCompatScore > 0);
    assertTrue("exactCompatScore should have greater compatibility score than required one" + " got exact = " + exactCompatScore + " and required= " + requiredParamScore, exactCompatScore > requiredParamScore);
    assertTrue("exactCompatScore should have greater compatibility score than required+optional one" + " got exact = " + exactCompatScore + " and requiredOptional= " + requiredOptCompatScore, exactCompatScore > requiredOptCompatScore);
    assertTrue("exactCompatScore should have greater compatibility score than optional one" + " got exact = " + exactCompatScore + " and optional = " + optCompatScore, requiredParamScore > optCompatScore);
}
Also used : WebRequest(org.apache.wicket.request.http.WebRequest) Request(org.apache.wicket.request.Request) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 50 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class ResourceMapperTest method validPathWithParams.

/**
 * testValidPathWithParams()
 */
@Test
public void validPathWithParams() {
    Request request = createRequest("test/resource/1/fred");
    IRequestHandler requestHandler = mapper.mapRequest(request);
    assertNotNull(requestHandler);
    assertEquals(ResourceReferenceRequestHandler.class, requestHandler.getClass());
    assertEquals(request.getUrl(), mapper.mapHandler(requestHandler));
    tester.processRequest(requestHandler);
    PageParameters params = resource.pageParameters;
    assertNotNull(params);
    assertEquals(0, params.getAllNamed().size());
    assertEquals(2, params.getIndexedCount());
    StringValue paramId = params.get(0);
    assertNotNull(paramId);
    assertEquals(1, paramId.toInt());
    StringValue paramName = params.get(1);
    assertNotNull(paramName);
    assertEquals("fred", paramName.toString());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) StringValue(org.apache.wicket.util.string.StringValue) Test(org.junit.Test)

Aggregations

Request (org.apache.wicket.request.Request)63 Test (org.junit.Test)28 IRequestHandler (org.apache.wicket.request.IRequestHandler)26 Url (org.apache.wicket.request.Url)23 WebRequest (org.apache.wicket.request.http.WebRequest)9 Response (org.apache.wicket.request.Response)8 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)6 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)6 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)6 IPageRequestHandler (org.apache.wicket.core.request.handler.IPageRequestHandler)5 ResourceReferenceRequestHandler (org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler)5 MockApplication (org.apache.wicket.mock.MockApplication)4 MockHttpServletRequest (org.apache.wicket.protocol.http.mock.MockHttpServletRequest)4 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)3 Attributes (org.apache.wicket.request.resource.IResource.Attributes)3 PackageResourceReference (org.apache.wicket.request.resource.PackageResourceReference)3 UrlAttributes (org.apache.wicket.request.resource.ResourceReference.UrlAttributes)3 ByteArrayResponse (org.apache.wicket.response.ByteArrayResponse)3