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