Search in sources :

Example 11 with Attributes

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

the class WriteCallbackTest method writeStream.

/**
 */
@Test
public void writeStream() throws IOException {
    WriteCallback callback = new WriteCallback() {

        @Override
        public void writeData(Attributes attributes) {
        }
    };
    ByteArrayResponse response = new ByteArrayResponse();
    Attributes attributes = new Attributes(new MockWebRequest(new Url()), response);
    byte[] srcData = new byte[5000];
    for (int i = 0; i < srcData.length; i++) {
        srcData[i] = (byte) i;
    }
    InputStream in = new ByteArrayInputStream(srcData);
    callback.writeStream(attributes, in);
    assertTrue("Content not equal", Arrays.equals(response.getBytes(), srcData));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Attributes(org.apache.wicket.request.resource.IResource.Attributes) WriteCallback(org.apache.wicket.request.resource.AbstractResource.WriteCallback) MockWebRequest(org.apache.wicket.mock.MockWebRequest) ByteArrayResponse(org.apache.wicket.response.ByteArrayResponse) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 12 with Attributes

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

the class PackageResourceReferenceTest method resourceResolution.

/**
 */
@Test
public void resourceResolution() {
    for (Locale locale : locales) {
        for (String style : styles) {
            for (String variation : variations) {
                ResourceReference reference = new PackageResourceReference(scope, "resource.txt", locale, style, variation);
                UrlAttributes urlAttributes = reference.getUrlAttributes();
                assertEquals(locale, urlAttributes.getLocale());
                assertEquals(style, urlAttributes.getStyle());
                assertEquals(variation, urlAttributes.getVariation());
                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) UrlAttributes(org.apache.wicket.request.resource.ResourceReference.UrlAttributes) 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)

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