Search in sources :

Example 11 with Response

use of org.apache.wicket.request.Response 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 12 with Response

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

Example 13 with Response

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

the class PackageResourceReferenceTest method testContentRangeHeaders.

/**
 * See WICKET-5819 - Media tags
 */
@Test
public void testContentRangeHeaders() {
    // Test header fields
    ResourceReference reference = new PackageResourceReference(scope, "resource.txt", locales[1], styles[1], variations[1]);
    Request request = tester.getRequestCycle().getRequest();
    Response response = tester.getRequestCycle().getResponse();
    MockHttpServletResponse mockHttpServletResponse = (MockHttpServletResponse) response.getContainerResponse();
    Attributes mockAttributes = new Attributes(request, response);
    reference.getResource().respond(mockAttributes);
    Assert.assertEquals(ContentRangeType.BYTES.getTypeName(), mockHttpServletResponse.getHeader("Accept-Range"));
    // For normal: If a resource supports content range no content is delivered
    // if no "Range" header is given, but we have to deliver it, because
    // other resources then media should get the content. (e.g. CSS, JS, etc.) Browsers
    // detecting media requests and automatically add the "Range" header for
    // partial content and they don't make an initial request to detect if a media
    // resource supports Content-Range (by the Accept-Range header)
    Assert.assertEquals("resource_var_style_en.txt", new String(mockHttpServletResponse.getBinaryContent()));
}
Also used : MockHttpServletResponse(org.apache.wicket.protocol.http.mock.MockHttpServletResponse) Response(org.apache.wicket.request.Response) ByteArrayResponse(org.apache.wicket.response.ByteArrayResponse) MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) Request(org.apache.wicket.request.Request) Attributes(org.apache.wicket.request.resource.IResource.Attributes) UrlAttributes(org.apache.wicket.request.resource.ResourceReference.UrlAttributes) MockHttpServletResponse(org.apache.wicket.protocol.http.mock.MockHttpServletResponse) Test(org.junit.Test)

Example 14 with Response

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

the class FilteringHeaderResponseTest method createBucketOnTheFlyForFilteredHeaderItem.

/**
 * https://issues.apache.org/jira/browse/WICKET-5057
 * @throws Exception
 */
@Test
public void createBucketOnTheFlyForFilteredHeaderItem() throws Exception {
    try (FilteringHeaderResponse headerResponse = new FilteringHeaderResponse(new HeaderResponse() {

        @Override
        protected Response getRealResponse() {
            return new StringResponse();
        }
    }, "headerBucketName", Collections.emptyList())) {
        String filterName = "filterName";
        String headerContent = "content";
        FilteredHeaderItem item = new FilteredHeaderItem(StringHeaderItem.forString(headerContent), filterName);
        headerResponse.render(item);
        CharSequence realContent = headerResponse.getContent(filterName);
        assertEquals(headerContent, realContent.toString());
    }
}
Also used : StringResponse(org.apache.wicket.response.StringResponse) HeaderResponse(org.apache.wicket.markup.head.internal.HeaderResponse) Response(org.apache.wicket.request.Response) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) HeaderResponse(org.apache.wicket.markup.head.internal.HeaderResponse) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) StringResponse(org.apache.wicket.response.StringResponse) Test(org.junit.Test)

Example 15 with Response

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

the class SessionSizeModelTest method testToleranceOnProblematicSessions.

/**
 * @see <a href="https://issues.apache.org/jira/browse/WICKET-3355">WICKET-3355</a>
 */
@Test
public void testToleranceOnProblematicSessions() {
    new WicketTester(new MockApplication() {

        @Override
        public Session newSession(final Request request, final Response response) {
            return new TestSession(request);
        }
    });
    SessionSizeModel model = new SessionSizeModel();
    assertEquals(null, model.getObject());
}
Also used : Response(org.apache.wicket.request.Response) MockApplication(org.apache.wicket.mock.MockApplication) Request(org.apache.wicket.request.Request) WicketTester(org.apache.wicket.util.tester.WicketTester) Session(org.apache.wicket.Session) WebSession(org.apache.wicket.protocol.http.WebSession) Test(org.junit.Test)

Aggregations

Response (org.apache.wicket.request.Response)30 IHeaderResponse (org.apache.wicket.markup.head.IHeaderResponse)9 WebResponse (org.apache.wicket.request.http.WebResponse)9 StringResponse (org.apache.wicket.response.StringResponse)9 Request (org.apache.wicket.request.Request)8 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)8 HeaderResponse (org.apache.wicket.markup.head.internal.HeaderResponse)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)4 MockApplication (org.apache.wicket.mock.MockApplication)4 Before (org.junit.Before)4 Session (org.apache.wicket.Session)3 IRequestCycle (org.apache.wicket.request.IRequestCycle)3 WicketTester (org.apache.wicket.util.tester.WicketTester)3 Test (org.junit.Test)3 Component (org.apache.wicket.Component)2 WebSession (org.apache.wicket.protocol.http.WebSession)2 Member (com.hazelcast.core.Member)1 MemberAttributeEvent (com.hazelcast.core.MemberAttributeEvent)1 MembershipEvent (com.hazelcast.core.MembershipEvent)1