Search in sources :

Example 1 with AttachmentProvider

use of org.apache.wiki.api.providers.AttachmentProvider in project jspwiki by apache.

the class WikiProviderAdaptersTest method testAttachmentProvider.

@Test
public void testAttachmentProvider() throws Exception {
    final AttachmentProvider attachmentProvider = engine.getManager(AttachmentManager.class).getCurrentProvider();
    final Attachment att11 = new Attachment(engine, "page1", "att11.txt");
    final Attachment att13 = new Attachment(engine, "page1", "att13.txt");
    final QueryItem qi = new QueryItem();
    qi.word = "doesn't matter will be ignored";
    qi.type = QueryItem.REQUESTED;
    Assertions.assertEquals("com.example.providers.TwoXWikiAttachmentProvider", attachmentProvider.getProviderInfo());
    Assertions.assertEquals(2, attachmentProvider.listAttachments(new WikiPage(engine, "page1")).size());
    final byte[] attDataArray = new byte[attachmentProvider.getAttachmentData(att11).available()];
    attachmentProvider.getAttachmentData(att11).read(attDataArray);
    Assertions.assertArrayEquals("blurb".getBytes(StandardCharsets.UTF_8), attDataArray);
    Assertions.assertEquals(0, attachmentProvider.findAttachments(new QueryItem[] { qi }).size());
    Assertions.assertEquals(3, attachmentProvider.listAllChanged(new Date(0L)).size());
    Assertions.assertEquals(att11.getName(), attachmentProvider.getAttachmentInfo(new WikiPage(engine, "page1"), "att11.txt", 0).getName());
    Assertions.assertEquals(1, attachmentProvider.getVersionHistory(att11).size());
    attachmentProvider.putAttachmentData(att13, new ByteArrayInputStream("blorb".getBytes(StandardCharsets.UTF_8)));
    Assertions.assertEquals(3, attachmentProvider.listAttachments(new WikiPage(engine, "page1")).size());
    attachmentProvider.putAttachmentData(att13, new ByteArrayInputStream("blorb".getBytes(StandardCharsets.UTF_8)));
    Assertions.assertEquals(2, attachmentProvider.getVersionHistory(att13).size());
    attachmentProvider.deleteVersion(attachmentProvider.getVersionHistory(att13).get(1));
    Assertions.assertEquals(1, attachmentProvider.getVersionHistory(att13).size());
    attachmentProvider.deleteAttachment(att13);
    Assertions.assertEquals(0, attachmentProvider.getVersionHistory(att13).size());
    Assertions.assertEquals(2, attachmentProvider.listAttachments(new WikiPage(engine, "page1")).size());
    attachmentProvider.moveAttachmentsForPage("page1", "page0");
    Assertions.assertEquals(2, attachmentProvider.listAttachments(new WikiPage(engine, "page0")).size());
    Assertions.assertEquals(0, attachmentProvider.listAttachments(new WikiPage(engine, "page1")).size());
}
Also used : QueryItem(org.apache.wiki.api.search.QueryItem) ByteArrayInputStream(java.io.ByteArrayInputStream) WikiPage(org.apache.wiki.WikiPage) Attachment(org.apache.wiki.attachment.Attachment) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) Date(java.util.Date) AttachmentProvider(org.apache.wiki.api.providers.AttachmentProvider) Test(org.junit.jupiter.api.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 Date (java.util.Date)1 WikiPage (org.apache.wiki.WikiPage)1 AttachmentProvider (org.apache.wiki.api.providers.AttachmentProvider)1 QueryItem (org.apache.wiki.api.search.QueryItem)1 Attachment (org.apache.wiki.attachment.Attachment)1 AttachmentManager (org.apache.wiki.attachment.AttachmentManager)1 Test (org.junit.jupiter.api.Test)1