Search in sources :

Example 6 with UrlAttributes

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

Example 7 with UrlAttributes

use of org.apache.wicket.request.resource.ResourceReference.UrlAttributes in project wicket by apache.

the class PackageResourceReferenceTest method sessionAttributesRelevance.

/**
 * Asserting if user did not set any locale or style, those from session get used if any
 */
@Test
public void sessionAttributesRelevance() {
    for (Locale locale : new Locale[] { new Locale("en"), new Locale("en", "US") }) {
        tester.getSession().setLocale(locale);
        for (String style : styles) {
            tester.getSession().setStyle(style);
            for (String variation : variations) {
                ResourceReference reference = new PackageResourceReference(scope, "resource.txt", null, null, variation);
                UrlAttributes urlAttributes = reference.getUrlAttributes();
                assertEquals(tester.getSession().getLocale(), urlAttributes.getLocale());
                assertEquals(tester.getSession().getStyle(), urlAttributes.getStyle());
                assertEquals(variation, urlAttributes.getVariation());
            }
        }
    }
}
Also used : Locale(java.util.Locale) UrlAttributes(org.apache.wicket.request.resource.ResourceReference.UrlAttributes) Test(org.junit.Test)

Aggregations

UrlAttributes (org.apache.wicket.request.resource.ResourceReference.UrlAttributes)7 Test (org.junit.Test)7 Locale (java.util.Locale)3 Url (org.apache.wicket.request.Url)2 Attributes (org.apache.wicket.request.resource.IResource.Attributes)1 ResourceReference (org.apache.wicket.request.resource.ResourceReference)1 ByteArrayResponse (org.apache.wicket.response.ByteArrayResponse)1