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