use of org.xwiki.rendering.transformation.MacroTransformationContext in project xwiki-platform by xwiki.
the class VelocityMacroIsolationTest method testVelocityMacroIsolation.
@Test
public void testVelocityMacroIsolation() throws Exception {
String expected = "beginDocument\n" + "beginParagraph\n" + "onSpecialSymbol [#]\n" + "onWord [testMacrosAreLocal]\n" + "onSpecialSymbol [(]\n" + "onSpecialSymbol [)]\n" + "endParagraph\n" + "endDocument";
VelocityMacroParameters params = new VelocityMacroParameters();
MacroTransformationContext context = new MacroTransformationContext();
context.setSyntax(Syntax.XWIKI_2_0);
context.setCurrentMacroBlock(new MacroBlock("velocity", Collections.<String, String>emptyMap(), false));
// Execute the velocity macro in the context of a first page
context.setId("page1");
this.velocityMacro.execute(params, "#macro(testMacrosAreLocal)mymacro#end", context);
// And then in the context of a second independent page
context.setId("page2");
PrintRendererFactory eventRendererFactory = getComponentManager().getInstance(PrintRendererFactory.class, "event/1.0");
assertBlocks(expected, this.velocityMacro.execute(params, "#testMacrosAreLocal()", context), eventRendererFactory);
}
use of org.xwiki.rendering.transformation.MacroTransformationContext in project xwiki-platform by xwiki.
the class MacroContentExecutorTest method executeWhenTransformationException.
@Test
public void executeWhenTransformationException() throws Exception {
XDOM parsedBlocks = new XDOM(Collections.emptyList());
ContentParser contentParser = this.mocker.getInstance(ContentParser.class);
when(contentParser.parse("", Syntax.PLAIN_1_0)).thenReturn(parsedBlocks);
TransformationContext transformationContext = new TransformationContext();
MacroTransformationContext context = new MacroTransformationContext(transformationContext);
Transformation macroTransformation = this.mocker.getInstance(Transformation.class, "macro");
doThrow(new TransformationException("error")).when(macroTransformation).transform(parsedBlocks, transformationContext);
try {
this.mocker.getComponentUnderTest().execute("", Syntax.PLAIN_1_0, context);
fail("Should have raised a ContentExecutorException");
} catch (ContentExecutorException expected) {
assertEquals("Failed to execute content", expected.getMessage());
}
}
use of org.xwiki.rendering.transformation.MacroTransformationContext in project xwiki-platform by xwiki.
the class MacroContentExecutorTest method executeWithSource.
@Test
public void executeWithSource() throws Exception {
XDOM parsedBlocks = new XDOM(Collections.emptyList());
ContentParser contentParser = this.mocker.getInstance(ContentParser.class);
when(contentParser.parse("", Syntax.PLAIN_1_0, DOCUMENT_REFERENCE)).thenReturn(parsedBlocks);
TransformationContext transformationContext = new TransformationContext();
MacroTransformationContext context = new MacroTransformationContext(transformationContext);
this.mocker.getComponentUnderTest().execute("", Syntax.PLAIN_1_0, DOCUMENT_REFERENCE, context);
// The test is here: Verify that the Macro Transformation has been called
Transformation macroTransformation = this.mocker.getInstance(Transformation.class, "macro");
verify(macroTransformation).transform(parsedBlocks, transformationContext);
}
use of org.xwiki.rendering.transformation.MacroTransformationContext in project xwiki-platform by xwiki.
the class MacroContentExecutorTest method executeWithNoSource.
@Test
public void executeWithNoSource() throws Exception {
XDOM parsedBlocks = new XDOM(Collections.emptyList());
ContentParser contentParser = this.mocker.getInstance(ContentParser.class);
when(contentParser.parse("", Syntax.PLAIN_1_0)).thenReturn(parsedBlocks);
TransformationContext transformationContext = new TransformationContext();
MacroTransformationContext context = new MacroTransformationContext(transformationContext);
this.mocker.getComponentUnderTest().execute("", Syntax.PLAIN_1_0, context);
// The test is here: Verify that the Macro Transformation has been called
Transformation macroTransformation = this.mocker.getInstance(Transformation.class, "macro");
verify(macroTransformation).transform(parsedBlocks, transformationContext);
}
use of org.xwiki.rendering.transformation.MacroTransformationContext in project xwiki-platform by xwiki.
the class DisplayMacroTest method runDisplayMacro.
private List<Block> runDisplayMacro(DisplayMacroParameters parameters, String displayedContent) throws Exception {
final DocumentReference displayedDocumentReference = new DocumentReference("wiki", "Space", "DisplayedPage");
String displayedDocStringRef = "wiki:space.page";
setUpDocumentMock(displayedDocStringRef, displayedDocumentReference, displayedContent);
getMockery().checking(new Expectations() {
{
allowing(mockSetup.bridge).isDocumentViewable(with(same(displayedDocumentReference)));
will(returnValue(true));
oneOf(mockSetup.bridge).pushDocumentInContext(with(any(Map.class)), with(same(mockDocument)));
atMost(1).of(mockSetup.bridge).getCurrentDocumentReference();
will(returnValue(displayedDocumentReference));
oneOf(mockSetup.bridge).popDocumentFromContext(with(any(Map.class)));
}
});
this.displayMacro.setDocumentAccessBridge(this.mockSetup.bridge);
parameters.setReference(displayedDocStringRef);
// Create a Macro transformation context with the Macro transformation object defined so that the display
// macro can transform displayed page which is using a new context.
MacroTransformation macroTransformation = (MacroTransformation) getComponentManager().getInstance(Transformation.class, "macro");
MacroTransformationContext macroContext = createMacroTransformationContext(displayedDocStringRef, false);
macroContext.setId("wiki:Space.DisplayingPage");
macroContext.setTransformation(macroTransformation);
return this.displayMacro.execute(parameters, null, macroContext);
}
Aggregations