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 node that has jnt:contentList type
BaseAttributesFilter baseAttributesFilter = new BaseAttributesFilter();
baseAttributesFilter.setRenderService(RenderService.getInstance());
baseAttributesFilter.setPriority(0);
TestFilter conditionalFilter = new TestFilter();
conditionalFilter.setRenderService(RenderService.getInstance());
conditionalFilter.setApplyOnNodeTypes("jnt:contentList");
conditionalFilter.setPriority(10);
RenderChain chain = new RenderChain(baseAttributesFilter, conditionalFilter, outFilter);
String result = chain.doFilter(context, resource);
assertTrue("TestFilter is not applied for node, having jnt:tag type", result.contains("TestFilter"));
// test on a node that does not have jnt:contentList type
resource = new Resource(node.getNode("testType2"), "html", null, Resource.CONFIGURATION_PAGE);
context.setMainResource(resource);
chain = new RenderChain(baseAttributesFilter, conditionalFilter, outFilter);
result = chain.doFilter(context, resource);
assertTrue("TestFilter is applied for node that does not have jnt:contentList type", !result.contains(
"TestFilter"));
// test multiple node types condition
resource = new Resource(node.getNode("testType2"), "html", null, Resource.CONFIGURATION_PAGE);
context.setMainResource(resource);
conditionalFilter = new TestFilter();
conditionalFilter.setRenderService(RenderService.getInstance());
conditionalFilter.setApplyOnNodeTypes("jnt:page, jnt:mainContent");
conditionalFilter.setPriority(10);
chain = new RenderChain(baseAttributesFilter, conditionalFilter, outFilter);
result = chain.doFilter(context, resource);
assertTrue("TestFilter is not applied for node, having jnt:mainContent type", result.contains("TestFilter"));
// test mixin type jmix:tagged
resource = new Resource(node.getNode("testMixin"), "html", null, Resource.CONFIGURATION_PAGE);
context.setMainResource(resource);
conditionalFilter = new TestFilter();
conditionalFilter.setRenderService(RenderService.getInstance());
conditionalFilter.setApplyOnNodeTypes("jmix:tagged");
conditionalFilter.setPriority(10);