Search in sources :

Example 41 with DocumentModelBridge

use of org.xwiki.bridge.DocumentModelBridge in project xwiki-platform by xwiki.

the class DefaultIOTargetServiceTest method testGetterWhenTargetIsTypedIndexedObjectProperty.

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

        {
            allowing(classResolver).resolve("XWiki.Class", new DocumentReference("wiki", "Space", "Page"));
            will(returnValue(new DocumentReference("wiki", "XWiki", "Class")));
            oneOf(dabMock).getProperty(new DocumentReference("wiki", "Space", "Page"), new DocumentReference("wiki", "XWiki", "Class"), 1, "property");
            will(returnValue("defcontent"));
            oneOf(dabMock).getTranslatedDocumentInstance(new DocumentReference("wiki", "Space", "Page"));
            will(returnValue(dmb));
            oneOf(dmb).getSyntax();
            will(returnValue(new Syntax(SyntaxType.XWIKI, "2.0")));
        }
    });
    String reference = "OBJECT_PROPERTY://wiki:Space.Page^XWiki.Class[1].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 42 with DocumentModelBridge

use of org.xwiki.bridge.DocumentModelBridge in project xwiki-platform by xwiki.

the class DefaultIOTargetServiceTest method testGettersWhenTargetIsTypedSpace.

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

        {
            // default resolver should be used
            oneOf(dabMock).getDocumentContent("SPACE://wiki:Space");
            will(returnValue("defcontent"));
            oneOf(dabMock).getDocumentSyntaxId("SPACE://wiki:Space");
            will(returnValue("xwiki/2.0"));
        }
    });
    // expect source ref to be used as is, as it doesn't parse to something acceptable
    String reference = "SPACE://wiki:Space";
    assertEquals("defcontent", ioTargetService.getSource(reference));
    assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference));
}
Also used : Expectations(org.jmock.Expectations) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) Test(org.junit.Test)

Example 43 with DocumentModelBridge

use of org.xwiki.bridge.DocumentModelBridge in project xwiki-platform by xwiki.

the class DefaultIOTargetServiceTest method testGettersWhenTargetIsEmptyString.

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

        {
            // default resolver should be used. Note that this will fail if default values change, not very well
            // isolated
            allowing(dabMock).getTranslatedDocumentInstance(new DocumentReference("xwiki", "Main", "WebHome"));
            will(returnValue(dmb));
            oneOf(dmb).getContent();
            will(returnValue("defcontent"));
            oneOf(dmb).getSyntax();
            will(returnValue(new Syntax(SyntaxType.XWIKI, "2.0")));
        }
    });
    // expect source ref to be used as is, as it doesn't parse to something acceptable
    String reference = "";
    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 44 with DocumentModelBridge

use of org.xwiki.bridge.DocumentModelBridge in project xwiki-platform by xwiki.

the class DefaultIOTargetServiceTest method testGetterWhenTargetIsTypedDefaultObjectProperty.

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

        {
            allowing(classResolver).resolve("XWiki.Class", new DocumentReference("wiki", "Space", "Page"));
            will(returnValue(new DocumentReference("wiki", "XWiki", "Class")));
            oneOf(dabMock).getProperty(new DocumentReference("wiki", "Space", "Page"), new DocumentReference("wiki", "XWiki", "Class"), "property");
            will(returnValue("defcontent"));
            oneOf(dabMock).getTranslatedDocumentInstance(new DocumentReference("wiki", "Space", "Page"));
            will(returnValue(dmb));
            oneOf(dmb).getSyntax();
            will(returnValue(new Syntax(SyntaxType.XWIKI, "2.0")));
        }
    });
    String reference = "OBJECT_PROPERTY://wiki:Space.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)

Example 45 with DocumentModelBridge

use of org.xwiki.bridge.DocumentModelBridge in project xwiki-platform by xwiki.

the class DefaultOfficeViewerScriptServiceTest method view.

@Test
public void view() throws Exception {
    Execution execution = mocker.getInstance(Execution.class);
    when(execution.getContext()).thenReturn(new ExecutionContext());
    AttachmentReference attachmentReference = new AttachmentReference("file.odt", new DocumentReference("wiki", "Space", "Page"));
    DocumentModelBridge document = mock(DocumentModelBridge.class);
    DocumentAccessBridge documentAccessBridge = mocker.getInstance(DocumentAccessBridge.class);
    when(documentAccessBridge.isDocumentViewable(attachmentReference.getDocumentReference())).thenReturn(true);
    when(documentAccessBridge.getTranslatedDocumentInstance(attachmentReference.getDocumentReference())).thenReturn(document);
    when(document.getSyntax()).thenReturn(Syntax.TEX_1_0);
    XDOM xdom = new XDOM(Collections.<Block>emptyList());
    OfficeViewer viewer = mocker.getInstance(OfficeViewer.class);
    when(viewer.createView(attachmentReference, Collections.<String, String>emptyMap())).thenReturn(xdom);
    BlockRenderer xhtmlRenderer = mocker.registerMockComponent(BlockRenderer.class, "xhtml/1.0");
    Assert.assertEquals("", mocker.getComponentUnderTest().view(attachmentReference));
    TransformationManager transformationManager = mocker.getInstance(TransformationManager.class);
    verify(transformationManager).performTransformations(eq(xdom), notNull(TransformationContext.class));
    verify(xhtmlRenderer).render(eq(xdom), notNull(WikiPrinter.class));
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) XDOM(org.xwiki.rendering.block.XDOM) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) OfficeViewer(org.xwiki.office.viewer.OfficeViewer) TransformationManager(org.xwiki.rendering.transformation.TransformationManager) TransformationContext(org.xwiki.rendering.transformation.TransformationContext) DocumentReference(org.xwiki.model.reference.DocumentReference) WikiPrinter(org.xwiki.rendering.renderer.printer.WikiPrinter) BlockRenderer(org.xwiki.rendering.renderer.BlockRenderer) Test(org.junit.Test)

Aggregations

DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)58 DocumentReference (org.xwiki.model.reference.DocumentReference)43 Test (org.junit.Test)39 Expectations (org.jmock.Expectations)18 XDOM (org.xwiki.rendering.block.XDOM)18 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)14 Syntax (org.xwiki.rendering.syntax.Syntax)11 MacroTransformationContext (org.xwiki.rendering.transformation.MacroTransformationContext)10 MacroBlock (org.xwiki.rendering.block.MacroBlock)9 DocumentDisplayerParameters (org.xwiki.display.internal.DocumentDisplayerParameters)8 ResourceReference (org.xwiki.rendering.listener.reference.ResourceReference)7 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)7 Block (org.xwiki.rendering.block.Block)6 HashMap (java.util.HashMap)5 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)5 DocumentDisplayer (org.xwiki.display.internal.DocumentDisplayer)5 MetaDataBlock (org.xwiki.rendering.block.MetaDataBlock)5 MetaData (org.xwiki.rendering.listener.MetaData)5 DocumentResourceReference (org.xwiki.rendering.listener.reference.DocumentResourceReference)5 StringReader (java.io.StringReader)4