Search in sources :

Example 26 with Attachment

use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.

the class JSPWikiMarkupParserTest method testCollectingLinksAttachment.

@Test
public void testCollectingLinksAttachment() throws Exception {
    try {
        testEngine.saveText(PAGE_NAME, "content");
        Attachment att = new Attachment(testEngine, PAGE_NAME, "TestAtt.txt");
        att.setAuthor("FirstPost");
        testEngine.getAttachmentManager().storeAttachment(att, testEngine.makeAttachmentFile());
        LinkCollector coll = new LinkCollector();
        LinkCollector coll_others = new LinkCollector();
        String src = "[TestAtt.txt]";
        WikiContext context = new WikiContext(testEngine, new WikiPage(testEngine, PAGE_NAME));
        MarkupParser p = new JSPWikiMarkupParser(context, new BufferedReader(new StringReader(src)));
        p.addLocalLinkHook(coll_others);
        p.addExternalLinkHook(coll_others);
        p.addAttachmentLinkHook(coll);
        p.parse();
        Collection<String> links = coll.getLinks();
        Assert.assertEquals("no links found", 1, links.size());
        Assert.assertEquals("wrong link", PAGE_NAME + "/TestAtt.txt", links.iterator().next());
        Assert.assertEquals("wrong links found", 0, coll_others.getLinks().size());
    } finally {
        String files = testEngine.getWikiProperties().getProperty(BasicAttachmentProvider.PROP_STORAGEDIR);
        File storagedir = new File(files, PAGE_NAME + BasicAttachmentProvider.DIR_EXTENSION);
        if (storagedir.exists() && storagedir.isDirectory())
            TestEngine.deleteAll(storagedir);
    }
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) Attachment(org.apache.wiki.attachment.Attachment) LinkCollector(org.apache.wiki.LinkCollector) File(java.io.File) Test(org.junit.Test)

Example 27 with Attachment

use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.

the class JSPWikiMarkupParserTest method testAttachmentLink.

@Test
public void testAttachmentLink() throws Exception {
    newPage("Test");
    Attachment att = new Attachment(testEngine, "Test", "TestAtt.txt");
    att.setAuthor("FirstPost");
    testEngine.getAttachmentManager().storeAttachment(att, testEngine.makeAttachmentFile());
    String src = "This should be an [attachment link|Test/TestAtt.txt]";
    Assert.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(src));
}
Also used : Attachment(org.apache.wiki.attachment.Attachment) Test(org.junit.Test)

Example 28 with Attachment

use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.

the class BasicAttachmentProviderTest method testListAllExtrafileInAttachmentDir.

/**
 *  Check that the system does not Assert.fail if there are extra files in the
 *  attachment directory.
 */
@Test
public void testListAllExtrafileInAttachmentDir() throws Exception {
    File in = makeAttachmentFile();
    File sDir = new File(m_engine.getWikiProperties().getProperty(BasicAttachmentProvider.PROP_STORAGEDIR));
    File attDir = new File(sDir, NAME1 + "-att");
    Attachment att = new Attachment(m_engine, NAME1, "test1.txt");
    m_provider.putAttachmentData(att, new FileInputStream(in));
    File extrafile = makeExtraFile(attDir, "ping.pong");
    try {
        // So that we get a bit of granularity.
        Thread.sleep(2000L);
        Attachment att2 = new Attachment(m_engine, NAME2, "test2.txt");
        m_provider.putAttachmentData(att2, new FileInputStream(in));
        List res = m_provider.listAllChanged(new Date(0L));
        Assert.assertEquals("list size", 2, res.size());
        // Most recently changed
        Attachment a2 = (Attachment) res.get(0);
        // Least recently changed
        Attachment a1 = (Attachment) res.get(1);
        Assert.assertEquals("a1 name", att.getName(), a1.getName());
        Assert.assertEquals("a2 name", att2.getName(), a2.getName());
    } finally {
        extrafile.delete();
    }
}
Also used : Attachment(org.apache.wiki.attachment.Attachment) List(java.util.List) File(java.io.File) FileInputStream(java.io.FileInputStream) Date(java.util.Date) Test(org.junit.Test)

Example 29 with Attachment

use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.

the class PageRenamerTest method testAttachmentChange.

@Test
public void testAttachmentChange() throws Exception {
    m_engine.saveText("TestPage", "foofoo");
    m_engine.saveText("TestPage2", "[TestPage/foo.txt] [linktext|TestPage/bar.jpg]");
    m_engine.addAttachment("TestPage", "foo.txt", "testing".getBytes());
    m_engine.addAttachment("TestPage", "bar.jpg", "pr0n".getBytes());
    WikiPage p = m_engine.getPage("TestPage");
    WikiContext context = new WikiContext(m_engine, p);
    m_engine.renamePage(context, "TestPage", "FooTest", true);
    String data = m_engine.getPureText("TestPage2", WikiProvider.LATEST_VERSION);
    Assert.assertEquals("no rename", "[FooTest/foo.txt] [linktext|FooTest/bar.jpg]", data.trim());
    Attachment att = m_engine.getAttachmentManager().getAttachmentInfo("FooTest/foo.txt");
    Assert.assertNotNull("footext", att);
    att = m_engine.getAttachmentManager().getAttachmentInfo("FooTest/bar.jpg");
    Assert.assertNotNull("barjpg", att);
    att = m_engine.getAttachmentManager().getAttachmentInfo("TestPage/bar.jpg");
    Assert.assertNull("testpage/bar.jpg exists", att);
    att = m_engine.getAttachmentManager().getAttachmentInfo("TestPage/foo.txt");
    Assert.assertNull("testpage/foo.txt exists", att);
    Collection<String> refs = m_engine.getReferenceManager().findReferrers("TestPage/bar.jpg");
    Assert.assertNull("oldpage", refs);
    refs = m_engine.getReferenceManager().findReferrers("FooTest/bar.jpg");
    Assert.assertEquals("new size", 1, refs.size());
    Assert.assertEquals("wrong ref", "TestPage2", (String) refs.iterator().next());
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Attachment(org.apache.wiki.attachment.Attachment) Test(org.junit.Test)

Example 30 with Attachment

use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.

the class BasicAttachmentProviderTest method testListAll.

@Test
public void testListAll() throws Exception {
    File in = makeAttachmentFile();
    Attachment att = new Attachment(m_engine, NAME1, "test1.txt");
    m_provider.putAttachmentData(att, new FileInputStream(in));
    // So that we get a bit of granularity.
    Thread.sleep(2000L);
    Attachment att2 = new Attachment(m_engine, NAME2, "test2.txt");
    m_provider.putAttachmentData(att2, new FileInputStream(in));
    List res = m_provider.listAllChanged(new Date(0L));
    Assert.assertEquals("list size", 2, res.size());
    // Most recently changed
    Attachment a2 = (Attachment) res.get(0);
    // Least recently changed
    Attachment a1 = (Attachment) res.get(1);
    Assert.assertEquals("a1 name", att.getName(), a1.getName());
    Assert.assertEquals("a2 name", att2.getName(), a2.getName());
}
Also used : Attachment(org.apache.wiki.attachment.Attachment) List(java.util.List) File(java.io.File) FileInputStream(java.io.FileInputStream) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Attachment (org.apache.wiki.attachment.Attachment)62 WikiPage (org.apache.wiki.WikiPage)26 Test (org.junit.Test)23 File (java.io.File)20 ProviderException (org.apache.wiki.api.exceptions.ProviderException)17 Collection (java.util.Collection)13 Date (java.util.Date)11 Iterator (java.util.Iterator)10 WikiEngine (org.apache.wiki.WikiEngine)10 AttachmentManager (org.apache.wiki.attachment.AttachmentManager)7 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)6 List (java.util.List)6 Vector (java.util.Vector)6 WikiContext (org.apache.wiki.WikiContext)5 Hashtable (java.util.Hashtable)4 Element (net.sf.ehcache.Element)4 PagePermission (org.apache.wiki.auth.permissions.PagePermission)4 ArrayList (java.util.ArrayList)3 Calendar (java.util.Calendar)3