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));
}
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));
}
}
}
}
}
Aggregations