use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class AttachmentManagerTest method testSimpleStore.
@Test
public void testSimpleStore() throws Exception {
final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "test1.txt");
att.setAuthor("FirstPost");
m_manager.storeAttachment(att, makeAttachmentFile());
final Attachment att2 = m_manager.getAttachmentInfo(new WikiContext(m_engine, Wiki.contents().page(m_engine, NAME1)), "test1.txt");
Assertions.assertNotNull(att2, "attachment disappeared");
Assertions.assertEquals(att.getName(), att2.getName(), "name");
Assertions.assertEquals(att.getAuthor(), att2.getAuthor(), "author");
Assertions.assertEquals(c_fileContents.length(), att2.getSize(), "size");
final InputStream in = m_manager.getAttachmentStream(att2);
Assertions.assertNotNull(in, "stream");
final StringWriter sout = new StringWriter();
FileUtil.copyContents(new InputStreamReader(in), sout);
in.close();
sout.close();
Assertions.assertEquals(c_fileContents, sout.toString(), "contents");
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class AttachmentManagerTest method testNonexistentPage.
@Test
public void testNonexistentPage() throws Exception {
try {
m_engine.saveText("TestPage", "xx");
final Attachment att = Wiki.contents().attachment(m_engine, "TestPages", "foo.bin");
att.setAuthor("MonicaBellucci");
m_manager.storeAttachment(att, makeAttachmentFile());
Assertions.fail("Attachment was stored even when the page does not exist");
} catch (final ProviderException ex) {
// This is the intended exception
} finally {
m_engine.getManager(PageManager.class).deletePage("TestPage");
}
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class AttachmentManagerTest method testSimpleStoreByVersion.
@Test
public void testSimpleStoreByVersion() throws Exception {
final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "test1.txt");
att.setAuthor("FirstPost");
m_manager.storeAttachment(att, makeAttachmentFile());
final Attachment att2 = m_manager.getAttachmentInfo(new WikiContext(m_engine, Wiki.contents().page(m_engine, NAME1)), "test1.txt", 1);
Assertions.assertNotNull(att2, "attachment disappeared");
Assertions.assertEquals(1, att2.getVersion(), "version");
Assertions.assertEquals(att.getName(), att2.getName(), "name");
Assertions.assertEquals(att.getAuthor(), att2.getAuthor(), "author");
Assertions.assertEquals(c_fileContents.length(), att2.getSize(), "size");
final InputStream in = m_manager.getAttachmentStream(att2);
Assertions.assertNotNull(in, "stream");
final StringWriter sout = new StringWriter();
FileUtil.copyContents(new InputStreamReader(in), sout);
in.close();
sout.close();
Assertions.assertEquals(c_fileContents, sout.toString(), "contents");
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class AttachmentManagerTest method testSimpleStoreSpace.
@Test
public void testSimpleStoreSpace() throws Exception {
final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "test file.txt");
att.setAuthor("FirstPost");
m_manager.storeAttachment(att, makeAttachmentFile());
final Attachment att2 = m_manager.getAttachmentInfo(new WikiContext(m_engine, Wiki.contents().page(m_engine, NAME1)), "test file.txt");
Assertions.assertNotNull(att2, "attachment disappeared");
Assertions.assertEquals(att.getName(), att2.getName(), "name");
Assertions.assertEquals(att.getAuthor(), att2.getAuthor(), "author");
Assertions.assertEquals(c_fileContents.length(), att2.getSize(), "size");
final InputStream in = m_manager.getAttachmentStream(att2);
Assertions.assertNotNull(in, "stream");
final StringWriter sout = new StringWriter();
FileUtil.copyContents(new InputStreamReader(in), sout);
in.close();
sout.close();
Assertions.assertEquals(c_fileContents, sout.toString(), "contents");
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class AttachmentManagerTest method testMultipleStore.
@Test
public void testMultipleStore() throws Exception {
final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "test1.txt");
att.setAuthor("FirstPost");
m_manager.storeAttachment(att, makeAttachmentFile());
att.setAuthor("FooBar");
m_manager.storeAttachment(att, makeAttachmentFile());
final Attachment att2 = m_manager.getAttachmentInfo(new WikiContext(m_engine, Wiki.contents().page(m_engine, NAME1)), "test1.txt");
Assertions.assertNotNull(att2, "attachment disappeared");
Assertions.assertEquals(att.getName(), att2.getName(), "name");
Assertions.assertEquals(att.getAuthor(), att2.getAuthor(), "author");
Assertions.assertEquals(2, att2.getVersion(), "version");
final InputStream in = m_manager.getAttachmentStream(att2);
Assertions.assertNotNull(in, "stream");
final StringWriter sout = new StringWriter();
FileUtil.copyContents(new InputStreamReader(in), sout);
in.close();
sout.close();
Assertions.assertEquals(c_fileContents, sout.toString(), "contents");
//
// Check that first author did not disappear
//
final Attachment att3 = m_manager.getAttachmentInfo(new WikiContext(m_engine, Wiki.contents().page(m_engine, NAME1)), "test1.txt", 1);
Assertions.assertEquals(1, att3.getVersion(), "version of v1");
Assertions.assertEquals("FirstPost", att3.getAuthor(), "name of v1");
}
Aggregations