Search in sources :

Example 6 with ByteArrayResponse

use of org.apache.wicket.response.ByteArrayResponse 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 7 with ByteArrayResponse

use of org.apache.wicket.response.ByteArrayResponse 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

ByteArrayResponse (org.apache.wicket.response.ByteArrayResponse)7 Attributes (org.apache.wicket.request.resource.IResource.Attributes)6 UrlAttributes (org.apache.wicket.request.resource.ResourceReference.UrlAttributes)4 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Locale (java.util.Locale)2 MockHttpServletRequest (org.apache.wicket.protocol.http.mock.MockHttpServletRequest)2 Request (org.apache.wicket.request.Request)2 Graphics2D (java.awt.Graphics2D)1 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)1 MockWebRequest (org.apache.wicket.mock.MockWebRequest)1 Url (org.apache.wicket.request.Url)1 WriteCallback (org.apache.wicket.request.resource.AbstractResource.WriteCallback)1