Search in sources :

Example 6 with CacheMacroParameters

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);
}
Also used : CacheMacroParameters(org.xwiki.rendering.macro.cache.CacheMacroParameters) StringWriter(java.io.StringWriter) VelocityManager(org.xwiki.velocity.VelocityManager) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) Block(org.xwiki.rendering.block.Block) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 Block (org.xwiki.rendering.block.Block)6 CacheMacroParameters (org.xwiki.rendering.macro.cache.CacheMacroParameters)6 MacroTransformationContext (org.xwiki.rendering.transformation.MacroTransformationContext)6 StringWriter (java.io.StringWriter)4 VelocityManager (org.xwiki.velocity.VelocityManager)4