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