Search in sources :

Example 1 with Syntax

use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.

the class DefaultIOTargetServiceTest method testGettersWhenTargetIsTypedRelativeDocument.

@Test
public void testGettersWhenTargetIsTypedRelativeDocument() throws Exception {
    final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class);
    getMockery().checking(new Expectations() {

        {
            // default resolver should be used
            allowing(dabMock).getTranslatedDocumentInstance(new DocumentReference("xwiki", "Space", "Page"));
            will(returnValue(dmb));
            oneOf(dmb).getContent();
            will(returnValue("defcontent"));
            oneOf(dmb).getSyntax();
            will(returnValue(new Syntax(SyntaxType.XWIKI, "2.0")));
        }
    });
    String reference = "DOCUMENT://Space.Page";
    assertEquals("defcontent", ioTargetService.getSource(reference));
    assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference));
}
Also used : Expectations(org.jmock.Expectations) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) Syntax(org.xwiki.rendering.syntax.Syntax) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 2 with Syntax

use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.

the class DefaultIOTargetServiceTest method testGetterWhenTargetIsTypedIndexedRelativeObjectProperty.

@Test
public void testGetterWhenTargetIsTypedIndexedRelativeObjectProperty() throws Exception {
    final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class);
    getMockery().checking(new Expectations() {

        {
            // this will fail if defaults fail, not very well isolated
            allowing(classResolver).resolve("Classes.Class", new DocumentReference("xwiki", "Main", "WebHome"));
            will(returnValue(new DocumentReference("xwiki", "Classes", "Class")));
            oneOf(dabMock).getProperty(new DocumentReference("xwiki", "Main", "WebHome"), new DocumentReference("xwiki", "Classes", "Class"), 3, "property");
            will(returnValue("defcontent"));
            oneOf(dabMock).getTranslatedDocumentInstance(new DocumentReference("xwiki", "Main", "WebHome"));
            will(returnValue(dmb));
            oneOf(dmb).getSyntax();
            will(returnValue(new Syntax(SyntaxType.XWIKI, "2.0")));
        }
    });
    String reference = "OBJECT_PROPERTY://Classes.Class[3].property";
    assertEquals("defcontent", ioTargetService.getSource(reference));
    assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference));
}
Also used : Expectations(org.jmock.Expectations) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) Syntax(org.xwiki.rendering.syntax.Syntax) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 3 with Syntax

use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.

the class DefaultIOTargetServiceTest method testGettersWhenTargetIsNonTypedDocument.

@Test
public void testGettersWhenTargetIsNonTypedDocument() throws Exception {
    final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class);
    getMockery().checking(new Expectations() {

        {
            allowing(dabMock).getTranslatedDocumentInstance(new DocumentReference("wiki", "Space", "Page"));
            will(returnValue(dmb));
            oneOf(dmb).getContent();
            will(returnValue("defcontent"));
            oneOf(dmb).getSyntax();
            will(returnValue(new Syntax(SyntaxType.XWIKI, "2.0")));
        }
    });
    String reference = "wiki:Space.Page";
    assertEquals("defcontent", ioTargetService.getSource(reference));
    assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference));
}
Also used : Expectations(org.jmock.Expectations) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) Syntax(org.xwiki.rendering.syntax.Syntax) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 4 with Syntax

use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.

the class DefaultIOTargetServiceTest method testGettersWhenTargetIsTypedDocument.

@Test
public void testGettersWhenTargetIsTypedDocument() throws Exception {
    final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class);
    getMockery().checking(new Expectations() {

        {
            allowing(dabMock).getTranslatedDocumentInstance(new DocumentReference("wiki", "Space", "Page"));
            will(returnValue(dmb));
            oneOf(dmb).getContent();
            will(returnValue("defcontent"));
            oneOf(dmb).getSyntax();
            will(returnValue(new Syntax(SyntaxType.XWIKI, "2.0")));
        }
    });
    String reference = "DOCUMENT://wiki:Space.Page";
    assertEquals("defcontent", ioTargetService.getSource(reference));
    assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference));
}
Also used : Expectations(org.jmock.Expectations) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) Syntax(org.xwiki.rendering.syntax.Syntax) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 5 with Syntax

use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.

the class DefaultIOTargetServiceTest method testGetterWhenTargetIsTypedObjectPropertyInRelativeDocument.

@Test
public void testGetterWhenTargetIsTypedObjectPropertyInRelativeDocument() throws Exception {
    final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class);
    getMockery().checking(new Expectations() {

        {
            allowing(classResolver).resolve("XWiki.Class", new DocumentReference("xwiki", "Main", "Page"));
            will(returnValue(new DocumentReference("xwiki", "XWiki", "Class")));
            oneOf(dabMock).getProperty(new DocumentReference("xwiki", "Main", "Page"), new DocumentReference("xwiki", "XWiki", "Class"), "property");
            will(returnValue("defcontent"));
            oneOf(dabMock).getTranslatedDocumentInstance(new DocumentReference("xwiki", "Main", "Page"));
            will(returnValue(dmb));
            oneOf(dmb).getSyntax();
            will(returnValue(new Syntax(SyntaxType.XWIKI, "2.0")));
        }
    });
    String reference = "OBJECT_PROPERTY://Page^XWiki.Class.property";
    assertEquals("defcontent", ioTargetService.getSource(reference));
    assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference));
}
Also used : Expectations(org.jmock.Expectations) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) Syntax(org.xwiki.rendering.syntax.Syntax) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

Syntax (org.xwiki.rendering.syntax.Syntax)35 Test (org.junit.Test)16 DocumentReference (org.xwiki.model.reference.DocumentReference)15 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)11 Expectations (org.jmock.Expectations)10 SyntaxType (org.xwiki.rendering.syntax.SyntaxType)7 ParseException (org.xwiki.rendering.parser.ParseException)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)4 IOException (java.io.IOException)4 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)4 Parser (org.xwiki.rendering.parser.Parser)4 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)3 HashMap (java.util.HashMap)3 ConfigurationSource (org.xwiki.configuration.ConfigurationSource)3 XDOM (org.xwiki.rendering.block.XDOM)3 CoreConfiguration (com.xpn.xwiki.CoreConfiguration)2 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 AbstractInstanceFilterStreamTest (com.xpn.xwiki.internal.filter.AbstractInstanceFilterStreamTest)2 ParseGroovyFromString (com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString)2 BaseObject (com.xpn.xwiki.objects.BaseObject)2