outFilter.setPriority(20);
outFilter.setRenderService(RenderService.getInstance());
RenderContext context = new RenderContext(paramBean.getRequest(), paramBean.getResponse(), admin);
context.setSite(site);
Resource resource = new Resource(node.getNode("testType"), "html", null, Resource.CONFIGURATION_PAGE);
context.setMainResource(resource);
// test on a resource with 'html' template type
BaseAttributesFilter baseAttributesFilter = new BaseAttributesFilter();
baseAttributesFilter.setRenderService(RenderService.getInstance());
baseAttributesFilter.setPriority(0);
TestFilter conditionalFilter = new TestFilter();
conditionalFilter.setRenderService(RenderService.getInstance());
conditionalFilter.setApplyOnTemplateTypes("html");
conditionalFilter.setPriority(10);
RenderChain chain = new RenderChain(baseAttributesFilter, conditionalFilter, outFilter);
String result = chain.doFilter(context, resource);
assertTrue("TestFilter is not applied for resource, having 'html' template type", result.contains(
"TestFilter"));
// test on a resource with 'xml' template type
resource = new Resource(node.getNode("testType"), "html", null, Resource.CONFIGURATION_PAGE);
context.setMainResource(resource);
conditionalFilter = new TestFilter();
conditionalFilter.setRenderService(RenderService.getInstance());
conditionalFilter.setApplyOnTemplateTypes("rss");
conditionalFilter.setPriority(10);
chain = new RenderChain(baseAttributesFilter, conditionalFilter, outFilter);
result = chain.doFilter(context, resource);
assertTrue("TestFilter is applied for resource that does not have 'rss' template", !result.contains(
"TestFilter"));
// test multiple template types condition
resource = new Resource(node.getNode("testType"), "html", null, Resource.CONFIGURATION_PAGE);
context.setMainResource(resource);
conditionalFilter = new TestFilter();
conditionalFilter.setRenderService(RenderService.getInstance());
conditionalFilter.setApplyOnTemplateTypes("xml,html");
conditionalFilter.setPriority(10);
chain = new RenderChain(baseAttributesFilter, conditionalFilter, outFilter);
result = chain.doFilter(context, resource);
assertTrue("TestFilter is not applied for resource, having 'html' template type", result.contains(
"TestFilter"));
// test NOT condition
resource = new Resource(node.getNode("testType"), "html", null, Resource.CONFIGURATION_PAGE);
context.setMainResource(resource);
conditionalFilter = new TestFilter();
conditionalFilter.setRenderService(RenderService.getInstance());
conditionalFilter.setSkipOnTemplateTypes("xml,html");
conditionalFilter.setPriority(10);