use of org.xwiki.rendering.macro.cache.CacheMacroParameters in project xwiki-platform by xwiki.
the class CacheMacroTest method executeWhenNoIdAndDifferentContent.
@Test
public void executeWhenNoIdAndDifferentContent() throws Exception {
String expected1 = "beginDocument\n" + "beginMacroMarkerStandalone [velocity] [] [$var]\n" + "beginParagraph\n" + "onWord [content]\n" + "endParagraph\n" + "endMacroMarkerStandalone [velocity] [] [$var]\n" + "endDocument";
String expected2 = "beginDocument\n" + "beginMacroMarkerStandalone [velocity] [] [$var##]\n" + "beginParagraph\n" + "onWord [newcontent]\n" + "endParagraph\n" + "endMacroMarkerStandalone [velocity] [] [$var##]\n" + "endDocument";
CacheMacroParameters params = new CacheMacroParameters();
MacroTransformationContext context = createMacroTransformationContext();
VelocityManager velocityManager = getComponentManager().getInstance(VelocityManager.class);
StringWriter writer = new StringWriter();
velocityManager.getVelocityEngine().evaluate(velocityManager.getVelocityContext(), writer, "template", "#set ($var = 'content')");
List<Block> result = this.cacheMacro.execute(params, "{{velocity}}$var{{/velocity}}", context);
assertBlocks(expected1, result, this.rendererFactory);
// Execute a second time with a different cache macro content to ensure it's not cached
velocityManager.getVelocityEngine().evaluate(velocityManager.getVelocityContext(), writer, "template", "#set ($var = 'newcontent')");
result = this.cacheMacro.execute(params, "{{velocity}}$var##{{/velocity}}", context);
assertBlocks(expected2, result, this.rendererFactory);
}
Aggregations