コード例 #1
0
  @Test
  public void getContentInputStreamForLatestVersion() 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");
    when(document.getAttachment(attachment.getFilename())).thenReturn(attachment);
    attachment.setVersion("3.5");

    try {
      attachment.getContentInputStream(this.oldcore.getXWikiContext());
      fail();
    } catch (NullPointerException e) {
      // Expected because the attachment content is not set. The attachment content is normally set
      // by the
      // loadAttachmentContent call we verify below.
    }

    verify(document).loadAttachmentContent(attachment, this.oldcore.getXWikiContext());
  }
コード例 #2
0
  @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().getAttachmentVersioningStore()).thenReturn(store);
    when(store.loadArchive(attachment, this.oldcore.getXWikiContext(), true)).thenReturn(archive);

    assertSame(
        content.getContentInputStream(),
        attachment.getContentInputStream(this.oldcore.getXWikiContext()));
  }