Search in sources :

Example 1 with OfficeViewer

use of org.xwiki.office.viewer.OfficeViewer 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

Test (org.junit.Test)1 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)1 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)1 Execution (org.xwiki.context.Execution)1 ExecutionContext (org.xwiki.context.ExecutionContext)1 AttachmentReference (org.xwiki.model.reference.AttachmentReference)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 OfficeViewer (org.xwiki.office.viewer.OfficeViewer)1 XDOM (org.xwiki.rendering.block.XDOM)1 BlockRenderer (org.xwiki.rendering.renderer.BlockRenderer)1 WikiPrinter (org.xwiki.rendering.renderer.printer.WikiPrinter)1 TransformationContext (org.xwiki.rendering.transformation.TransformationContext)1 TransformationManager (org.xwiki.rendering.transformation.TransformationManager)1