Search in sources :

Example 1 with ContentParser

use of org.xwiki.rendering.parser.ContentParser 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());
    }
}
Also used : Transformation(org.xwiki.rendering.transformation.Transformation) TransformationException(org.xwiki.rendering.transformation.TransformationException) XDOM(org.xwiki.rendering.block.XDOM) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) ContentParser(org.xwiki.rendering.parser.ContentParser) ContentExecutorException(org.xwiki.rendering.executor.ContentExecutorException) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) TransformationContext(org.xwiki.rendering.transformation.TransformationContext) Test(org.junit.Test)

Example 2 with ContentParser

use of org.xwiki.rendering.parser.ContentParser 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);
}
Also used : Transformation(org.xwiki.rendering.transformation.Transformation) XDOM(org.xwiki.rendering.block.XDOM) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) ContentParser(org.xwiki.rendering.parser.ContentParser) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) TransformationContext(org.xwiki.rendering.transformation.TransformationContext) Test(org.junit.Test)

Example 3 with ContentParser

use of org.xwiki.rendering.parser.ContentParser 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);
}
Also used : Transformation(org.xwiki.rendering.transformation.Transformation) XDOM(org.xwiki.rendering.block.XDOM) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) ContentParser(org.xwiki.rendering.parser.ContentParser) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) TransformationContext(org.xwiki.rendering.transformation.TransformationContext) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 XDOM (org.xwiki.rendering.block.XDOM)3 ContentParser (org.xwiki.rendering.parser.ContentParser)3 MacroTransformationContext (org.xwiki.rendering.transformation.MacroTransformationContext)3 Transformation (org.xwiki.rendering.transformation.Transformation)3 TransformationContext (org.xwiki.rendering.transformation.TransformationContext)3 ContentExecutorException (org.xwiki.rendering.executor.ContentExecutorException)1 TransformationException (org.xwiki.rendering.transformation.TransformationException)1