Search in sources :

Example 1 with ResourceAggregator

use of org.apache.wicket.markup.head.ResourceAggregator in project wicket by apache.

the class ResourceAggregatorTest method setup.

/**
 * Setup the testcase, creating a new header response stub and wrapping it in a resource
 * aggregator
 */
@Before
public void setup() {
    responseStub = new TestHeaderResponse();
    aggregator = new ResourceAggregator(responseStub);
}
Also used : ResourceAggregator(org.apache.wicket.markup.head.ResourceAggregator) Before(org.junit.Before)

Example 2 with ResourceAggregator

use of org.apache.wicket.markup.head.ResourceAggregator in project wicket by apache.

the class FilteringHeaderResponseTest method footerDependsOnHeadItem.

@Test
public void footerDependsOnHeadItem() throws Exception {
    tester.getApplication().setHeaderResponseDecorator(new IHeaderResponseDecorator() {

        @Override
        public IHeaderResponse decorate(IHeaderResponse response) {
            // footer (after </body>)
            return new ResourceAggregator(new JavaScriptFilteredIntoFooterHeaderResponse(response, "footerJS"));
        }
    });
    executeTest(FilteredHeaderPage.class, "FilteredHeaderPageExpected.html");
}
Also used : IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) ResourceAggregator(org.apache.wicket.markup.head.ResourceAggregator) IHeaderResponseDecorator(org.apache.wicket.markup.html.IHeaderResponseDecorator) Test(org.junit.Test)

Example 3 with ResourceAggregator

use of org.apache.wicket.markup.head.ResourceAggregator in project wicket by apache.

the class FilteringHeaderResponseTest method deferred.

/**
 * WICKET-6498 all JavaScript resources have an "defer" attribute, all other JavaScript is
 * inside a {@code document.addEventListener('DOMContentLoaded', function() {}; } hook.
 */
@Test
public void deferred() throws Exception {
    tester.getApplication().setHeaderResponseDecorator(response -> new ResourceAggregator(new JavaScriptDeferHeaderResponse(response)));
    executeTest(DeferredPage.class, "DeferredPageExpected.html");
}
Also used : ResourceAggregator(org.apache.wicket.markup.head.ResourceAggregator) Test(org.junit.Test)

Example 4 with ResourceAggregator

use of org.apache.wicket.markup.head.ResourceAggregator in project wicket by apache.

the class ResourceDecorationApplication method init.

@Override
protected void init() {
    super.init();
    getResourceBundles().addCssBundle(ResourceDecorationApplication.class, "css-bundle.css", new CssResourceReference(HomePage.class, "footer.css"), new CssResourceReference(HomePage.class, "header.css"));
    setHeaderResponseDecorator(response -> {
        // footer (after </body>)
        return new ResourceAggregator(new JavaScriptFilteredIntoFooterHeaderResponse(response, "footerJS"));
    });
}
Also used : JavaScriptFilteredIntoFooterHeaderResponse(org.apache.wicket.markup.head.filter.JavaScriptFilteredIntoFooterHeaderResponse) ResourceAggregator(org.apache.wicket.markup.head.ResourceAggregator) CssResourceReference(org.apache.wicket.request.resource.CssResourceReference)

Example 5 with ResourceAggregator

use of org.apache.wicket.markup.head.ResourceAggregator in project wicket by apache.

the class DecoratingHeaderResponseTest method decoratedStringPrepend.

/**
 * Basic IHeaderResponseDecorator, just prepending the DECORATED string to resource name.
 *
 * @throws IOException
 * @throws ResourceStreamNotFoundException
 * @throws ParseException
 */
@Test
public void decoratedStringPrepend() throws IOException, ResourceStreamNotFoundException, ParseException {
    tester.getApplication().setHeaderResponseDecorator(new IHeaderResponseDecorator() {

        @Override
        public IHeaderResponse decorate(IHeaderResponse response) {
            return new ResourceAggregator(new DecoratingHeaderResponse(response) {

                @Override
                public void render(HeaderItem item) {
                    if (item instanceof JavaScriptReferenceHeaderItem) {
                        JavaScriptReferenceHeaderItem original = (JavaScriptReferenceHeaderItem) item;
                        item = JavaScriptHeaderItem.forReference(new PackageResourceReference("DECORATED-" + original.getReference().getName()), original.getId());
                    }
                    super.render(item);
                }
            });
        }
    });
    tester.startPage(TestPage.class);
    XmlPullParser parser = new XmlPullParser();
    parser.parse(tester.getLastResponseAsString());
    XmlTag tag = parser.nextTag();
    boolean isDecorated = false;
    do {
        if (tag.isOpen() && "script".equals(tag.getName())) {
            isDecorated = tag.getAttribute("src").toString().contains("DECORATED");
            if (!isDecorated) {
                fail();
            }
            break;
        }
    } while ((tag = parser.nextTag()) != null);
    assertTrue(isDecorated);
}
Also used : JavaScriptReferenceHeaderItem(org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem) PackageResourceReference(org.apache.wicket.request.resource.PackageResourceReference) XmlPullParser(org.apache.wicket.markup.parser.XmlPullParser) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) ResourceAggregator(org.apache.wicket.markup.head.ResourceAggregator) HeaderItem(org.apache.wicket.markup.head.HeaderItem) JavaScriptHeaderItem(org.apache.wicket.markup.head.JavaScriptHeaderItem) JavaScriptReferenceHeaderItem(org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem) XmlTag(org.apache.wicket.markup.parser.XmlTag) Test(org.junit.Test)

Aggregations

ResourceAggregator (org.apache.wicket.markup.head.ResourceAggregator)5 Test (org.junit.Test)3 IHeaderResponse (org.apache.wicket.markup.head.IHeaderResponse)2 HeaderItem (org.apache.wicket.markup.head.HeaderItem)1 JavaScriptHeaderItem (org.apache.wicket.markup.head.JavaScriptHeaderItem)1 JavaScriptReferenceHeaderItem (org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem)1 JavaScriptFilteredIntoFooterHeaderResponse (org.apache.wicket.markup.head.filter.JavaScriptFilteredIntoFooterHeaderResponse)1 IHeaderResponseDecorator (org.apache.wicket.markup.html.IHeaderResponseDecorator)1 XmlPullParser (org.apache.wicket.markup.parser.XmlPullParser)1 XmlTag (org.apache.wicket.markup.parser.XmlTag)1 CssResourceReference (org.apache.wicket.request.resource.CssResourceReference)1 PackageResourceReference (org.apache.wicket.request.resource.PackageResourceReference)1 Before (org.junit.Before)1