Search in sources :

Example 1 with ContentParser

use of org.xwiki.component.wiki.internal.bridge.ContentParser in project xwiki-platform by xwiki.

the class DefaultWikiComponentBridgeTest method getHandledMethods.

@Test
public void getHandledMethods() throws Exception {
    final ComponentManager componentManager = getComponentManager().getInstance(ComponentManager.class);
    final ContentParser contentParser = getComponentManager().getInstance(ContentParser.class);
    final Parser parser = getMockery().mock(Parser.class);
    final XDOM xdom = new XDOM(new ArrayList<Block>());
    final BaseObject methodObject = getMockery().mock(BaseObject.class, "method");
    final Vector<BaseObject> methodObjects = new Vector<BaseObject>();
    methodObjects.add(methodObject);
    getMockery().checking(new Expectations() {

        {
            oneOf(componentDoc).getObjectNumbers(METHOD_CLASS);
            will(returnValue(1));
            oneOf(componentDoc).getObjects(METHOD_CLASS);
            will(returnValue(methodObjects));
            allowing(methodObject).getStringValue(METHOD_NAME_FIELD);
            will(returnValue("test"));
            allowing(methodObject).getStringValue(METHOD_CODE_FIELD);
            will(returnValue("test"));
            oneOf(componentDoc).getSyntax();
            will(returnValue(Syntax.XWIKI_2_1));
            oneOf(contentParser).parse("test", Syntax.XWIKI_2_1, DOC_REFERENCE);
            will(returnValue(xdom));
        }
    });
    Assert.assertEquals(1, bridge.getHandledMethods(DOC_REFERENCE).size());
}
Also used : Expectations(org.jmock.Expectations) XDOM(org.xwiki.rendering.block.XDOM) ComponentManager(org.xwiki.component.manager.ComponentManager) ContentParser(org.xwiki.component.wiki.internal.bridge.ContentParser) Block(org.xwiki.rendering.block.Block) Vector(java.util.Vector) ContentParser(org.xwiki.component.wiki.internal.bridge.ContentParser) Parser(org.xwiki.rendering.parser.Parser) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 2 with ContentParser

use of org.xwiki.component.wiki.internal.bridge.ContentParser in project xwiki-platform by xwiki.

the class WikiUIExtensionComponentBuilderTest method buildComponents.

@Test
public void buildComponents() throws Exception {
    BaseObject extensionObject = createExtensionObject("name", "extensionPointId", "content", "key=value=foo\nkey2=value2\ninvalid=\n\n=invalid", "user");
    ContentParser contentParser = this.mocker.getInstance(ContentParser.class);
    VelocityManager velocityManager = this.mocker.getInstance(VelocityManager.class);
    List<WikiComponent> components = this.mocker.getComponentUnderTest().buildComponents(extensionObject);
    assertEquals(1, components.size());
    verify(contentParser).parse("content", Syntax.XWIKI_2_1, DOC_REF);
    UIExtension uiExtension = (UIExtension) components.get(0);
    Map<String, String> parameters = uiExtension.getParameters();
    assertEquals(2, parameters.size());
    verify(velocityManager.getVelocityEngine()).evaluate(any(VelocityContext.class), any(StringWriter.class), eq("name:key"), eq("value=foo"));
    verify(velocityManager.getVelocityEngine()).evaluate(any(VelocityContext.class), any(StringWriter.class), eq("name:key2"), eq("value2"));
}
Also used : StringWriter(java.io.StringWriter) VelocityManager(org.xwiki.velocity.VelocityManager) WikiComponent(org.xwiki.component.wiki.WikiComponent) VelocityContext(org.apache.velocity.VelocityContext) ContentParser(org.xwiki.component.wiki.internal.bridge.ContentParser) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 3 with ContentParser

use of org.xwiki.component.wiki.internal.bridge.ContentParser in project xwiki-platform by xwiki.

the class WikiUIExtensionRendererTest method setUp.

@Before
public void setUp() throws Exception {
    execution = cm.registerMockComponent(Execution.class);
    ExecutionContext executionContext = mock(ExecutionContext.class);
    renderingContext = mock(MutableRenderingContext.class);
    cm.registerComponent(RenderingContext.class, renderingContext);
    cm.registerMockComponent(Transformation.class, "macro");
    contentParser = cm.registerMockComponent(ContentParser.class);
    when(execution.getContext()).thenReturn(executionContext);
    xdom = mock(XDOM.class);
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) XDOM(org.xwiki.rendering.block.XDOM) ContentParser(org.xwiki.component.wiki.internal.bridge.ContentParser) MutableRenderingContext(org.xwiki.rendering.internal.transformation.MutableRenderingContext) Before(org.junit.Before)

Aggregations

ContentParser (org.xwiki.component.wiki.internal.bridge.ContentParser)3 BaseObject (com.xpn.xwiki.objects.BaseObject)2 Test (org.junit.Test)2 XDOM (org.xwiki.rendering.block.XDOM)2 StringWriter (java.io.StringWriter)1 Vector (java.util.Vector)1 VelocityContext (org.apache.velocity.VelocityContext)1 Expectations (org.jmock.Expectations)1 Before (org.junit.Before)1 ComponentManager (org.xwiki.component.manager.ComponentManager)1 WikiComponent (org.xwiki.component.wiki.WikiComponent)1 Execution (org.xwiki.context.Execution)1 ExecutionContext (org.xwiki.context.ExecutionContext)1 Block (org.xwiki.rendering.block.Block)1 MutableRenderingContext (org.xwiki.rendering.internal.transformation.MutableRenderingContext)1 Parser (org.xwiki.rendering.parser.Parser)1 VelocityManager (org.xwiki.velocity.VelocityManager)1