use of org.xwiki.rendering.macro.cache.CacheMacroParameters in project xwiki-platform by xwiki.
the class CacheMacroTest method executeWithDifferentTimeToLive.
@Test
public void executeWithDifferentTimeToLive() throws Exception {
CacheMacroParameters params = new CacheMacroParameters();
MacroTransformationContext context = createMacroTransformationContext();
params.setId("id");
params.setMaxEntries(10);
params.setTimeToLive(100);
List<Block> result1 = this.cacheMacro.execute(params, "content1", context);
// Execute a second time with different content but with different time to live param. This means another
// cache will be used and thus the first cached content won't be returned.
params.setTimeToLive(200);
List<Block> result2 = this.cacheMacro.execute(params, "content2", context);
assertFalse(result2.equals(result1));
}
use of org.xwiki.rendering.macro.cache.CacheMacroParameters in project xwiki-platform by xwiki.
the class CacheMacroTest method executeWithDifferentMaxEntries.
@Test
public void executeWithDifferentMaxEntries() throws Exception {
CacheMacroParameters params = new CacheMacroParameters();
MacroTransformationContext context = createMacroTransformationContext();
params.setId("id");
params.setMaxEntries(10);
params.setTimeToLive(100);
List<Block> result1 = this.cacheMacro.execute(params, "content1", context);
// Execute a second time with different content but with different time to live param. This means another
// cache will be used and thus the first cached content won't be returned.
params.setMaxEntries(11);
List<Block> result2 = this.cacheMacro.execute(params, "content2", context);
assertFalse(result2.equals(result1));
}
use of org.xwiki.rendering.macro.cache.CacheMacroParameters in project xwiki-platform by xwiki.
the class CacheMacroTest method executeWithIdGeneratedByVelocityMacro.
@Test
public void executeWithIdGeneratedByVelocityMacro() throws Exception {
VelocityManager velocityManager = getComponentManager().getInstance(VelocityManager.class);
StringWriter writer = new StringWriter();
velocityManager.getVelocityEngine().evaluate(velocityManager.getVelocityContext(), writer, "template", "#set ($var = 'generatedid')");
CacheMacroParameters params = new CacheMacroParameters();
params.setId("{{velocity}}$var{{/velocity}}");
MacroTransformationContext context = createMacroTransformationContext();
List<Block> result1 = this.cacheMacro.execute(params, "whatever", context);
// Execute a second time with the same id (specified explicitly this time) and ensures that the returned result
// is the same even the cache macro content is different.
params.setId("generatedid");
List<Block> result2 = this.cacheMacro.execute(params, "something else", context);
assertEquals(result1, result2);
}
use of org.xwiki.rendering.macro.cache.CacheMacroParameters in project xwiki-platform by xwiki.
the class CacheMacroTest method executeWhenNoIdAndSameContent.
@Test
public void executeWhenNoIdAndSameContent() throws Exception {
String expected = "beginDocument\n" + "beginMacroMarkerStandalone [velocity] [] [$var]\n" + "beginParagraph\n" + "onWord [content]\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(expected, result, this.rendererFactory);
// Execute a second time with a different value for the velocity $var variable to ensure the returned result
// is the cached one.
velocityManager.getVelocityEngine().evaluate(velocityManager.getVelocityContext(), writer, "template", "#set ($var = 'newcontent')");
result = this.cacheMacro.execute(params, "{{velocity}}$var{{/velocity}}", context);
assertBlocks(expected, result, this.rendererFactory);
}
use of org.xwiki.rendering.macro.cache.CacheMacroParameters in project xwiki-platform by xwiki.
the class CacheMacroTest method executeWhenSameIdAndDifferentContent.
@Test
public void executeWhenSameIdAndDifferentContent() throws Exception {
String expected = "beginDocument\n" + "beginMacroMarkerStandalone [velocity] [] [$var]\n" + "beginParagraph\n" + "onWord [content]\n" + "endParagraph\n" + "endMacroMarkerStandalone [velocity] [] [$var]\n" + "endDocument";
CacheMacroParameters params = new CacheMacroParameters();
params.setId("uniqueid");
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(expected, result, this.rendererFactory);
// Execute a second time with a different content but with the same id, to ensure the returned result
// is the cached one.
result = this.cacheMacro.execute(params, "whatever here...", context);
assertBlocks(expected, result, this.rendererFactory);
}
Aggregations