Search in sources :

Example 21 with Request

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

the class PageInstanceMapperTest method decode10.

@Test
public void decode10() {
    final Url url = Url.parse("page?4");
    Request request = new Request() {

        @Override
        public Url getUrl() {
            return url;
        }

        @Override
        public Locale getLocale() {
            return null;
        }

        @Override
        public Charset getCharset() {
            return Charset.forName("UTF-8");
        }

        @Override
        public Url getClientUrl() {
            return Url.parse("page");
        }

        @Override
        public Object getContainerRequest() {
            return null;
        }
    };
    IRequestHandler handler = encoder.mapRequest(request);
    IRequestablePage page = ((IPageRequestHandler) handler).getPage();
    checkPage(page, 4);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) IPageRequestHandler(org.apache.wicket.core.request.handler.IPageRequestHandler) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 22 with Request

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

the class PageInstanceMapperTest method decode9.

@Test
public void decode9() {
    final Url url = Url.parse("page?4");
    Request request = new Request() {

        @Override
        public Url getUrl() {
            return url;
        }

        @Override
        public Locale getLocale() {
            return null;
        }

        @Override
        public Charset getCharset() {
            return Charset.forName("UTF-8");
        }

        @Override
        public Url getClientUrl() {
            return Url.parse("wicket/page");
        }

        @Override
        public Object getContainerRequest() {
            return null;
        }
    };
    IRequestHandler handler = encoder.mapRequest(request);
    IRequestablePage page = ((IPageRequestHandler) handler).getPage();
    checkPage(page, 4);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) IPageRequestHandler(org.apache.wicket.core.request.handler.IPageRequestHandler) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 23 with Request

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

the class Session method setAttribute.

/**
 * Adds or replaces the attribute with the given name and value.
 *
 * @param name
 *            The name of the attribute
 * @param value
 *            The value of the attribute
 */
public final Session setAttribute(String name, Serializable value) {
    if (!isTemporary()) {
        RequestCycle cycle = RequestCycle.get();
        if (cycle == null) {
            throw new IllegalStateException("Cannot set the attribute: no RequestCycle available.  If you get this error when using WicketTester.startPage(Page), make sure to call WicketTester.createRequestCycle() beforehand.");
        }
        ISessionStore store = getSessionStore();
        Request request = cycle.getRequest();
        // extra check on session binding event
        if (value == this) {
            Object current = store.getAttribute(request, name);
            if (current == null) {
                String id = store.getSessionId(request, false);
                if (id != null) {
                    // this is a new instance. wherever it came from, bind
                    // the session now
                    store.bind(request, (Session) value);
                }
            }
        }
        // Set the actual attribute
        store.setAttribute(request, name, value);
    } else {
        // session instance gets shared across threads
        if (temporarySessionAttributes == null) {
            temporarySessionAttributes = new HashMap<>(3);
        }
        temporarySessionAttributes.put(name, value);
    }
    return this;
}
Also used : ISessionStore(org.apache.wicket.session.ISessionStore) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) Request(org.apache.wicket.request.Request)

Example 24 with Request

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

the class HeaderResponseTest method before.

/**
 * Prepare
 */
@Before
public void before() {
    final Response realResponse = new StringResponse();
    headerResponse = new HeaderResponse() {

        @Override
        protected Response getRealResponse() {
            return realResponse;
        }
    };
    reference = new ResourceReference("testReference") {

        private static final long serialVersionUID = 1L;

        @Override
        public IResource getResource() {
            return null;
        }
    };
    RequestCycle requestCycle = mock(RequestCycle.class);
    when(requestCycle.urlFor(any(IRequestHandler.class))).thenReturn(RESOURCE_NAME);
    when(requestCycle.find(any())).thenReturn(Optional.empty());
    Request request = mock(Request.class);
    when(request.getCharset()).thenReturn(Charset.defaultCharset());
    when(requestCycle.getRequest()).thenReturn(request);
    UrlRenderer urlRenderer = mock(UrlRenderer.class);
    when(urlRenderer.renderContextRelativeUrl((any(String.class)))).thenReturn(RESOURCE_NAME);
    when(requestCycle.getUrlRenderer()).thenReturn(urlRenderer);
    ThreadContext.setRequestCycle(requestCycle);
}
Also used : HeaderResponse(org.apache.wicket.markup.head.internal.HeaderResponse) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) StringResponse(org.apache.wicket.response.StringResponse) Response(org.apache.wicket.request.Response) HeaderResponse(org.apache.wicket.markup.head.internal.HeaderResponse) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) IRequestHandler(org.apache.wicket.request.IRequestHandler) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) Request(org.apache.wicket.request.Request) StringResponse(org.apache.wicket.response.StringResponse) ResourceReference(org.apache.wicket.request.resource.ResourceReference) UrlRenderer(org.apache.wicket.request.UrlRenderer) IResource(org.apache.wicket.request.resource.IResource) Before(org.junit.Before)

Example 25 with Request

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

the class RequestCycleUrlForTest method before.

@Before
public void before() {
    Request request = mock(Request.class);
    Url baseUrl = Url.parse("");
    when(request.getClientUrl()).thenReturn(baseUrl);
    Response response = new StringResponse() {

        @Override
        public String encodeURL(CharSequence url) {
            return url + JSESSIONID;
        }
    };
    IRequestMapper mapper = mock(IRequestMapper.class);
    Url bookmarkablePageUrl = Url.parse(BOOKMARKABLE_PAGE_URL);
    when(mapper.mapHandler(argThat(new ExactClassMatcher<BookmarkablePageRequestHandler>(BookmarkablePageRequestHandler.class)))).thenReturn(bookmarkablePageUrl);
    Url resourceUrl = Url.parse(RESOURCE_URL);
    when(mapper.mapHandler(argThat(new ExactClassMatcher<ResourceRequestHandler>(ResourceRequestHandler.class)))).thenReturn(resourceUrl);
    Url resourceReferenceUrl = Url.parse(RES_REF_URL);
    when(mapper.mapHandler(argThat(new ExactClassMatcher<ResourceReferenceRequestHandler>(ResourceReferenceRequestHandler.class)))).thenReturn(resourceReferenceUrl);
    IExceptionMapper exceptionMapper = mock(IExceptionMapper.class);
    RequestCycleContext context = new RequestCycleContext(request, response, mapper, exceptionMapper);
    requestCycle = new RequestCycle(context);
    requestCycle.getUrlRenderer().setBaseUrl(baseUrl);
}
Also used : StringResponse(org.apache.wicket.response.StringResponse) Response(org.apache.wicket.request.Response) Request(org.apache.wicket.request.Request) StringResponse(org.apache.wicket.response.StringResponse) IExceptionMapper(org.apache.wicket.request.IExceptionMapper) IRequestMapper(org.apache.wicket.request.IRequestMapper) Url(org.apache.wicket.request.Url) Before(org.junit.Before)

Aggregations

Request (org.apache.wicket.request.Request)61 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 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)6 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 IPageRequestHandler (org.apache.wicket.core.request.handler.IPageRequestHandler)5 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)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 Session (org.apache.wicket.Session)3 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