use of com.xpn.xwiki.store.AttachmentVersioningStore in project xwiki-platform by xwiki.
the class XWikiAttachmentTest method getContentInputStreamFromArchive.
@Test
public void getContentInputStreamFromArchive() throws Exception {
XWikiDocument document = mock(XWikiDocument.class);
when(document.getDocumentReference()).thenReturn(new DocumentReference("wiki", "Space", "Page"));
when(this.oldcore.getXWikiContext().getWiki().getDocument(document.getDocumentReference(), this.oldcore.getXWikiContext())).thenReturn(document);
XWikiAttachment attachment = new XWikiAttachment(document, "file.txt");
attachment.setVersion("3.5");
XWikiAttachment newAttachment = new XWikiAttachment(document, attachment.getFilename());
newAttachment.setVersion("5.1");
when(document.getAttachment(attachment.getFilename())).thenReturn(newAttachment);
XWikiAttachmentContent content = mock(XWikiAttachmentContent.class);
when(content.getContentInputStream()).thenReturn(mock(InputStream.class));
XWikiAttachment archivedAttachment = new XWikiAttachment(document, attachment.getFilename());
archivedAttachment.setAttachment_content(content);
XWikiAttachmentArchive archive = mock(XWikiAttachmentArchive.class);
when(archive.getRevision(attachment, attachment.getVersion(), this.oldcore.getXWikiContext())).thenReturn(archivedAttachment);
AttachmentVersioningStore store = mock(AttachmentVersioningStore.class);
when(this.oldcore.getXWikiContext().getWiki().getDefaultAttachmentArchiveStore()).thenReturn(store);
when(store.loadArchive(attachment, this.oldcore.getXWikiContext(), true)).thenReturn(archive);
assertSame(content.getContentInputStream(), attachment.getContentInputStream(this.oldcore.getXWikiContext()));
}
use of com.xpn.xwiki.store.AttachmentVersioningStore in project xwiki-platform by xwiki.
the class XWikiAttachment method loadArchive.
public XWikiAttachmentArchive loadArchive(XWikiContext xcontext) {
if (this.attachment_archive == null) {
WikiReference currentWiki = xcontext.getWikiReference();
try {
// Make sure we work on the attachment's wiki
WikiReference attachmentWiki = getReference().getDocumentReference().getWikiReference();
if (attachmentWiki != null) {
xcontext.setWikiReference(attachmentWiki);
}
try {
AttachmentVersioningStore store = getAttachmentVersioningStore(xcontext);
this.attachment_archive = store.loadArchive(this, xcontext, true);
} catch (Exception e) {
LOGGER.warn("Failed to load archive for attachment [{}@{}]. " + "This attachment is broken, please consider re-uploading it", this.doc != null ? this.doc.getDocumentReference() : "<unknown>", getFilename(), e);
}
} finally {
if (currentWiki != null) {
xcontext.setWikiReference(currentWiki);
}
}
}
return this.attachment_archive;
}
Aggregations