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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations