Search in sources :

Example 6 with Attributes

use of org.apache.wicket.request.resource.IResource.Attributes in project wicket by apache.

the class MinifiedAwareResourceReferenceTest method renderResource.

private String renderResource(ResourceReference reference) {
    ByteArrayResponse byteResponse = new ByteArrayResponse();
    Attributes mockAttributes = new Attributes(tester.getRequestCycle().getRequest(), byteResponse);
    reference.getResource().respond(mockAttributes);
    return new String(byteResponse.getBytes());
}
Also used : Attributes(org.apache.wicket.request.resource.IResource.Attributes) ByteArrayResponse(org.apache.wicket.response.ByteArrayResponse)

Example 7 with Attributes

use of org.apache.wicket.request.resource.IResource.Attributes 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 8 with Attributes

use of org.apache.wicket.request.resource.IResource.Attributes in project wicket by apache.

the class PackageResourceReferenceTest method resourceResponse.

/**
 */
@Test
public void resourceResponse() {
    for (Locale locale : locales) {
        for (String style : styles) {
            for (String variation : variations) {
                ResourceReference reference = new PackageResourceReference(scope, "resource.txt", locale, style, variation);
                ByteArrayResponse byteResponse = new ByteArrayResponse();
                Attributes mockAttributes = new Attributes(tester.getRequestCycle().getRequest(), byteResponse);
                reference.getResource().respond(mockAttributes);
                String fileContent = new String(byteResponse.getBytes());
                if (locale != null) {
                    assertTrue(fileContent.contains(locale.getLanguage()));
                    if (locale.getCountry() != null) {
                        assertTrue(fileContent.contains(locale.getCountry()));
                    }
                }
                if (style != null) {
                    assertTrue(fileContent.contains(style));
                }
                if (variation != null) {
                    assertTrue(fileContent.contains(variation));
                }
            }
        }
    }
}
Also used : Locale(java.util.Locale) Attributes(org.apache.wicket.request.resource.IResource.Attributes) UrlAttributes(org.apache.wicket.request.resource.ResourceReference.UrlAttributes) ByteArrayResponse(org.apache.wicket.response.ByteArrayResponse) Test(org.junit.Test)

Example 9 with Attributes

use of org.apache.wicket.request.resource.IResource.Attributes in project wicket by apache.

the class PackageResourceReferenceTest method makeRangeRequestToBigResource.

private String makeRangeRequestToBigResource(String range) {
    ResourceReference reference = new PackageResourceReference(scope, "resource_gt_4096.txt", null, null, null);
    ByteArrayResponse byteResponse = new ByteArrayResponse();
    Request request = tester.getRequestCycle().getRequest();
    MockHttpServletRequest mockHttpServletRequest = (MockHttpServletRequest) request.getContainerRequest();
    mockHttpServletRequest.setHeader("range", range);
    Attributes mockAttributes = new Attributes(request, byteResponse);
    reference.getResource().respond(mockAttributes);
    return new String(byteResponse.getBytes());
}
Also used : MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) 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) ByteArrayResponse(org.apache.wicket.response.ByteArrayResponse)

Example 10 with Attributes

use of org.apache.wicket.request.resource.IResource.Attributes in project wicket by apache.

the class PackageResourceReferenceTest method makeRangeRequest.

private String makeRangeRequest(String range) {
    ResourceReference reference = new PackageResourceReference(scope, "resource.txt", locales[1], styles[1], variations[1]);
    ByteArrayResponse byteResponse = new ByteArrayResponse();
    Request request = tester.getRequestCycle().getRequest();
    MockHttpServletRequest mockHttpServletRequest = (MockHttpServletRequest) request.getContainerRequest();
    mockHttpServletRequest.setHeader("range", range);
    Attributes mockAttributes = new Attributes(request, byteResponse);
    reference.getResource().respond(mockAttributes);
    return new String(byteResponse.getBytes());
}
Also used : MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) 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) ByteArrayResponse(org.apache.wicket.response.ByteArrayResponse)

Aggregations

Attributes (org.apache.wicket.request.resource.IResource.Attributes)12 ByteArrayResponse (org.apache.wicket.response.ByteArrayResponse)7 Test (org.junit.Test)6 UrlAttributes (org.apache.wicket.request.resource.ResourceReference.UrlAttributes)5 MockHttpServletRequest (org.apache.wicket.protocol.http.mock.MockHttpServletRequest)3 Request (org.apache.wicket.request.Request)3 Locale (java.util.Locale)2 WebRequest (org.apache.wicket.request.http.WebRequest)2 WebResponse (org.apache.wicket.request.http.WebResponse)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 MockWebRequest (org.apache.wicket.mock.MockWebRequest)1 MockHttpServletResponse (org.apache.wicket.protocol.http.mock.MockHttpServletResponse)1 Response (org.apache.wicket.request.Response)1 Url (org.apache.wicket.request.Url)1 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)1 WriteCallback (org.apache.wicket.request.resource.AbstractResource.WriteCallback)1 ResourceStreamResource (org.apache.wicket.request.resource.ResourceStreamResource)1