@Test public void loadContentTest() throws Exception { this.storeFile.getParentFile().mkdirs(); OutputStream os = new FileOutputStream(this.storeFile, false); IOUtils.copy(HELLO_STREAM, os); os.close(); getMockery().checking(new Expectations() { { oneOf(mockAttach).setAttachment_content(with(any(FilesystemAttachmentContent.class))); will(new CustomAction("Check to make sure the attachment content is correct.") { @Override public Object invoke(final Invocation invoc) { final FilesystemAttachmentContent content = (FilesystemAttachmentContent) invoc.getParameter(0); try { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(content.getContentInputStream(), baos); final String output = new String(baos.toByteArray(), "UTF-8"); Assert.assertEquals(HELLO.length(), content.getLongSize()); Assert.assertEquals(HELLO.length(), content.getSize()); Assert.assertEquals("Not the same attachment content.", HELLO, output); return null; } catch (IOException e) { throw new RuntimeException("Exception getting attachment content.", e); } } }); oneOf(mockAttach).setContentStore("file"); } }); this.attachStore.loadAttachmentContent(this.mockAttach, this.mockContext, false); }
@Override public void loadAttachmentContent(final XWikiAttachment attachment, final XWikiContext context, final boolean bTransaction) throws XWikiException { final File attachFile = this.fileTools.getAttachmentFileProvider(attachment.getReference()).getAttachmentContentFile(); if (!attachFile.exists()) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_FILENOTFOUND, String.format("The attachment [%s] (file %s) could not be found in the filesystem attachment store.", attachment.getReference(), attachFile)); } FilesystemAttachmentContent content = new FilesystemAttachmentContent(attachFile); content.setContentDirty(false); attachment.setAttachment_content(content); attachment.setContentStore(FileSystemStoreUtils.HINT); }
FilesystemAttachmentStore implements XWikiAttachmentStoreInterface { @Override public void loadAttachmentContent(final XWikiAttachment attachment, final XWikiContext context, final boolean bTransaction) throws XWikiException { final File attachFile = this.fileTools.getAttachmentFileProvider(attachment.getReference()).getAttachmentContentFile(); if (!attachFile.exists()) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_FILENOTFOUND, String.format("The attachment [%s] (file %s) could not be found in the filesystem attachment store.", attachment.getReference(), attachFile)); } FilesystemAttachmentContent content = new FilesystemAttachmentContent(attachFile); content.setContentDirty(false); attachment.setAttachment_content(content); attachment.setContentStore(FileSystemStoreUtils.HINT); } }
FilesystemAttachmentStore implements XWikiAttachmentStoreInterface { @Override public void loadAttachmentContent(final XWikiAttachment attachment, final XWikiContext context, final boolean bTransaction) throws XWikiException { final File attachFile = this.fileTools.getAttachmentFileProvider(attachment.getReference()).getAttachmentContentFile(); if (!attachFile.exists()) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_FILENOTFOUND, String.format("The attachment [%s] (file %s) could not be found in the filesystem attachment store.", attachment.getReference(), attachFile)); } FilesystemAttachmentContent content = new FilesystemAttachmentContent(attachFile); content.setContentDirty(false); attachment.setAttachment_content(content); attachment.setContentStore(FileSystemStoreUtils.HINT); }  }
FilesystemAttachmentStore implements XWikiAttachmentStoreInterface { @Override public void loadAttachmentContent(final XWikiAttachment attachment, final XWikiContext context, final boolean bTransaction) throws XWikiException { final File attachFile = this.fileTools.getAttachmentFileProvider(attachment.getReference()).getAttachmentContentFile(); if (!attachFile.exists()) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_FILENOTFOUND, String.format("The attachment [%s] (file %s) could not be found in the filesystem attachment store.", attachment.getReference(), attachFile)); } FilesystemAttachmentContent content = new FilesystemAttachmentContent(attachFile); content.setContentDirty(false); attachment.setAttachment_content(content); attachment.setContentStore(FileSystemStoreUtils.HINT); }  @Override String getHint(); @Override void saveAttachmentContent(final XWikiAttachment attachment, final XWikiContext context,
        final boolean bTransaction); @Override void saveAttachmentContent(final XWikiAttachment attachment, final boolean updateDocument,
        final XWikiContext context, final boolean bTransaction); @Override void saveAttachmentsContent(final List<XWikiAttachment> attachments, final XWikiDocument doc,
        final boolean updateDocument, final XWikiContext context, final boolean bTransaction); @Override void loadAttachmentContent(final XWikiAttachment attachment, final XWikiContext context,
        final boolean bTransaction); @Override void deleteXWikiAttachment(final XWikiAttachment attachment, final XWikiContext context,
        final boolean bTransaction); @Override void deleteXWikiAttachment(final XWikiAttachment attachment, final boolean parentUpdate,
        final XWikiContext context, final boolean bTransaction); @Override void cleanUp(XWikiContext context); }
FilesystemAttachmentStore implements XWikiAttachmentStoreInterface { @Override public void loadAttachmentContent(final XWikiAttachment attachment, final XWikiContext context, final boolean bTransaction) throws XWikiException { final File attachFile = this.fileTools.getAttachmentFileProvider(attachment.getReference()).getAttachmentContentFile(); if (!attachFile.exists()) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_FILENOTFOUND, String.format("The attachment [%s] (file %s) could not be found in the filesystem attachment store.", attachment.getReference(), attachFile)); } FilesystemAttachmentContent content = new FilesystemAttachmentContent(attachFile); content.setContentDirty(false); attachment.setAttachment_content(content); attachment.setContentStore(FileSystemStoreUtils.HINT); }  @Override String getHint(); @Override void saveAttachmentContent(final XWikiAttachment attachment, final XWikiContext context,
        final boolean bTransaction); @Override void saveAttachmentContent(final XWikiAttachment attachment, final boolean updateDocument,
        final XWikiContext context, final boolean bTransaction); @Override void saveAttachmentsContent(final List<XWikiAttachment> attachments, final XWikiDocument doc,
        final boolean updateDocument, final XWikiContext context, final boolean bTransaction); @Override void loadAttachmentContent(final XWikiAttachment attachment, final XWikiContext context,
        final boolean bTransaction); @Override void deleteXWikiAttachment(final XWikiAttachment attachment, final XWikiContext context,
        final boolean bTransaction); @Override void deleteXWikiAttachment(final XWikiAttachment attachment, final boolean parentUpdate,
        final XWikiContext context, final boolean bTransaction); @Override void cleanUp(XWikiContext context);  }