Search in sources :

Example 56 with Attachment

use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.

the class DefaultPageManagerTest method testDeletePageAndAttachments.

@Test
public void testDeletePageAndAttachments() throws Exception {
    engine.saveText(NAME1, "Test");
    final Attachment att = Wiki.contents().attachment(engine, NAME1, "TestAtt.txt");
    att.setAuthor("FirstPost");
    engine.getManager(AttachmentManager.class).storeAttachment(att, engine.makeAttachmentFile());
    final String files = engine.getWikiProperties().getProperty(FileSystemProvider.PROP_PAGEDIR);
    final File saved = new File(files, NAME1 + FileSystemProvider.FILE_EXT);
    final String atts = engine.getWikiProperties().getProperty(AttachmentProvider.PROP_STORAGEDIR);
    final File attfile = new File(atts, NAME1 + "-att/TestAtt.txt-dir");
    Assertions.assertTrue(saved.exists(), "Didn't create it!");
    Assertions.assertTrue(attfile.exists(), "Attachment dir does not exist");
    final Page page = engine.getManager(PageManager.class).getPage(NAME1, WikiProvider.LATEST_VERSION);
    engine.getManager(PageManager.class).deletePage(page.getName());
    Assertions.assertFalse(saved.exists(), "Page has not been removed!");
    Assertions.assertFalse(attfile.exists(), "Attachment has not been removed");
}
Also used : Attachment(org.apache.wiki.api.core.Attachment) Page(org.apache.wiki.api.core.Page) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 57 with Attachment

use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.

the class JSPWikiMarkupParserTest method testAttachmentLink3.

/**
 * Are attachments parsed correctly also when using gappy text?
 */
@Test
public void testAttachmentLink3() throws Exception {
    final TestEngine testEngine2 = TestEngine.build();
    testEngine2.saveText("TestPage", "foo ");
    created.addElement("TestPage");
    final Attachment att = Wiki.contents().attachment(testEngine2, "TestPage", "TestAtt.txt");
    att.setAuthor("FirstPost");
    testEngine2.getManager(AttachmentManager.class).storeAttachment(att, testEngine.makeAttachmentFile());
    final String src = "[Test page/TestAtt.txt]";
    Assertions.assertEquals("<a class=\"attachment\" href=\"/test/attach/TestPage/TestAtt.txt\">Test page/TestAtt.txt</a>" + "<a href=\"/test/PageInfo.jsp?page=TestPage/TestAtt.txt\" class=\"infolink\"><img src=\"/test/images/attachment_small.png\" border=\"0\" alt=\"(info)\" /></a>", translate(testEngine2, src));
}
Also used : Attachment(org.apache.wiki.api.core.Attachment) TestEngine(org.apache.wiki.TestEngine) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) Test(org.junit.jupiter.api.Test)

Example 58 with Attachment

use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.

the class JSPWikiMarkupParserTest method testAttachmentLink2.

@Test
public void testAttachmentLink2() throws Exception {
    final TestEngine testEngine2 = TestEngine.build(with("jspwiki.encoding", StandardCharsets.ISO_8859_1.name()));
    testEngine2.saveText("Test", "foo ");
    created.addElement("Test");
    final Attachment att = Wiki.contents().attachment(testEngine2, "Test", "TestAtt.txt");
    att.setAuthor("FirstPost");
    testEngine2.getManager(AttachmentManager.class).storeAttachment(att, testEngine.makeAttachmentFile());
    final String src = "This should be an [attachment link|Test/TestAtt.txt]";
    Assertions.assertEquals("This should be an <a class=\"attachment\" href=\"/test/attach/Test/TestAtt.txt\">attachment link</a>" + "<a href=\"/test/PageInfo.jsp?page=Test/TestAtt.txt\" class=\"infolink\"><img src=\"/test/images/attachment_small.png\" border=\"0\" alt=\"(info)\" /></a>", translate(testEngine2, src));
}
Also used : Attachment(org.apache.wiki.api.core.Attachment) TestEngine(org.apache.wiki.TestEngine) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) Test(org.junit.jupiter.api.Test)

Example 59 with Attachment

use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.

the class JSPWikiMarkupParserTest method testAttachmentLink4.

@Test
public void testAttachmentLink4() throws Exception {
    final TestEngine testEngine2 = TestEngine.build();
    testEngine2.saveText("TestPage", "foo ");
    created.addElement("TestPage");
    final Attachment att = Wiki.contents().attachment(testEngine2, "TestPage", "TestAtt.txt");
    att.setAuthor("FirstPost");
    testEngine2.getManager(AttachmentManager.class).storeAttachment(att, testEngine.makeAttachmentFile());
    final String src = "[" + testEngine2.getManager(RenderingManager.class).beautifyTitle("TestPage/TestAtt.txt") + "]";
    Assertions.assertEquals("<a class=\"attachment\" href=\"/test/attach/TestPage/TestAtt.txt\">Test Page/TestAtt.txt</a>" + "<a href=\"/test/PageInfo.jsp?page=TestPage/TestAtt.txt\" class=\"infolink\"><img src=\"/test/images/attachment_small.png\" border=\"0\" alt=\"(info)\" /></a>", translate(testEngine2, src));
}
Also used : RenderingManager(org.apache.wiki.render.RenderingManager) Attachment(org.apache.wiki.api.core.Attachment) TestEngine(org.apache.wiki.TestEngine) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) Test(org.junit.jupiter.api.Test)

Example 60 with Attachment

use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.

the class BasicAttachmentProviderTest method testPutAttachmentUTF8.

/**
 *  Can we save attachments with names in UTF-8 range?
 */
@Test
public void testPutAttachmentUTF8() throws Exception {
    final File in = makeAttachmentFile();
    final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "\u3072\u3048\u308b\u00e5\u00e4\u00f6test.f\u00fc\u00fc");
    m_provider.putAttachmentData(att, new FileInputStream(in));
    final List<Attachment> res = m_provider.listAllChanged(new Date(0L));
    final Attachment a0 = res.get(0);
    Assertions.assertEquals(att.getName(), a0.getName(), "name");
}
Also used : Attachment(org.apache.wiki.api.core.Attachment) File(java.io.File) FileInputStream(java.io.FileInputStream) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

Attachment (org.apache.wiki.api.core.Attachment)76 Test (org.junit.jupiter.api.Test)37 AttachmentManager (org.apache.wiki.attachment.AttachmentManager)35 Page (org.apache.wiki.api.core.Page)27 ProviderException (org.apache.wiki.api.exceptions.ProviderException)20 PageManager (org.apache.wiki.pages.PageManager)19 File (java.io.File)15 Date (java.util.Date)10 Engine (org.apache.wiki.api.core.Engine)10 ReferenceManager (org.apache.wiki.references.ReferenceManager)9 InputStream (java.io.InputStream)8 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)6 InputStreamReader (java.io.InputStreamReader)6 StringWriter (java.io.StringWriter)6 Vector (java.util.Vector)6 WikiContext (org.apache.wiki.WikiContext)6 Permission (java.security.Permission)4 ArrayList (java.util.ArrayList)4 Hashtable (java.util.Hashtable)4