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