Search in sources :

Example 31 with Attachment

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

the class BasicAttachmentProviderTest method testListAllExtrafile.

/**
 *  Check that the system does not Assert.fail if there are extra files in the directory.
 */
@Test
public void testListAllExtrafile() throws Exception {
    File in = makeAttachmentFile();
    File sDir = new File(m_engine.getWikiProperties().getProperty(BasicAttachmentProvider.PROP_STORAGEDIR));
    File extrafile = makeExtraFile(sDir, "foobar.blob");
    try {
        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());
    } 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 32 with Attachment

use of org.apache.wiki.attachment.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 {
    File in = makeAttachmentFile();
    Attachment att = new Attachment(m_engine, NAME1, "\u3072\u3048\u308b\u00e5\u00e4\u00f6test.f\u00fc\u00fc");
    m_provider.putAttachmentData(att, new FileInputStream(in));
    List res = m_provider.listAllChanged(new Date(0L));
    Attachment a0 = (Attachment) res.get(0);
    Assert.assertEquals("name", att.getName(), a0.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)

Example 33 with Attachment

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

the class BasicAttachmentProviderTest method testListAllNoExtension.

@Test
public void testListAllNoExtension() throws Exception {
    File in = makeAttachmentFile();
    Attachment att = new Attachment(m_engine, NAME1, "test1.");
    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.");
    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)

Example 34 with Attachment

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

the class BasicAttachmentProviderTest method testListAllExtradirInAttachmentDir.

/**
 *  Check that the system does not Assert.fail if there are extra dirs in the
 *  attachment directory.
 */
@Test
public void testListAllExtradirInAttachmentDir() 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));
    // This is our extraneous directory.
    File extrafile = new File(attDir, "ping.pong");
    extrafile.mkdir();
    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 35 with Attachment

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

the class RPCHandlerTest method testRecentChangesWithAttachments.

@Test
public void testRecentChangesWithAttachments() throws Exception {
    Date time = getCalendarTime(Calendar.getInstance().getTime());
    Vector previousChanges = m_handler.getRecentChanges(time);
    m_engine.saveText(NAME1, "Foo");
    Attachment att = new Attachment(m_engine, NAME1, "TestAtt.txt");
    att.setAuthor("FirstPost");
    m_engine.getAttachmentManager().storeAttachment(att, m_engine.makeAttachmentFile());
    WikiPage directInfo = m_engine.getPage(NAME1);
    time = getCalendarTime(directInfo.getLastModified());
    Vector recentChanges = m_handler.getRecentChanges(time);
    Assert.assertEquals("wrong number of changes", 1, recentChanges.size() - previousChanges.size());
}
Also used : WikiPage(org.apache.wiki.WikiPage) Attachment(org.apache.wiki.attachment.Attachment) Vector(java.util.Vector) 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