use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class WikiEngineTest method testAttachmentRefs.
/**
* Checks, if ReferenceManager is informed of new attachments.
*/
@Test
public void testAttachmentRefs() throws Exception {
final ReferenceManager refMgr = m_engine.getManager(ReferenceManager.class);
final AttachmentManager attMgr = m_engine.getManager(AttachmentManager.class);
m_engine.saveText(NAME1, "fooBar");
final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "TestAtt.txt");
att.setAuthor("FirstPost");
attMgr.storeAttachment(att, m_engine.makeAttachmentFile());
// and check post-conditions
Collection<String> c = refMgr.findUncreated();
Assertions.assertTrue(c == null || c.size() == 0, "attachment exists: " + c);
c = refMgr.findUnreferenced();
Assertions.assertEquals(2, c.size(), "unreferenced count");
final Iterator<String> i = c.iterator();
final String first = i.next();
final String second = i.next();
Assertions.assertTrue((first.equals(NAME1) && second.equals(NAME1 + "/TestAtt.txt")) || (first.equals(NAME1 + "/TestAtt.txt") && second.equals(NAME1)), "unreferenced");
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class RPCHandler method getRecentChanges.
/**
* {@inheritDoc}
*/
@Override
public Vector<Hashtable<String, Object>> getRecentChanges(Date since) {
checkPermission(PagePermission.VIEW);
final Set<Page> pages = m_engine.getManager(PageManager.class).getRecentChanges();
final Vector<Hashtable<String, Object>> result = new Vector<>();
final Calendar cal = Calendar.getInstance();
cal.setTime(since);
//
// Convert UTC to our time.
//
cal.add(Calendar.MILLISECOND, (cal.get(Calendar.ZONE_OFFSET) + (cal.getTimeZone().inDaylightTime(since) ? cal.get(Calendar.DST_OFFSET) : 0)));
since = cal.getTime();
for (final Page page : pages) {
if (page.getLastModified().after(since) && !(page instanceof Attachment)) {
result.add(encodeWikiPage(page));
}
}
return result;
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class AuthorizationManagerTest method testInheritedPermissions.
@Test
public void testInheritedPermissions() throws Exception {
// Create test page & attachment
final String src = "[{ALLOW edit Alice}] ";
m_engine.saveText("Test", src);
final File f = m_engine.makeAttachmentFile();
final Attachment att = Wiki.contents().attachment(m_engine, "Test", "test1.txt");
att.setAuthor("FirstPost");
m_engine.getManager(AttachmentManager.class).storeAttachment(att, f);
final Attachment p = (Attachment) m_engine.getManager(PageManager.class).getPage("Test/test1.txt");
final Permission view = PermissionFactory.getPagePermission(p, "view");
final Permission edit = PermissionFactory.getPagePermission(p, "edit");
// Create authenticated session with user 'Alice', who can read & edit (in ACL)
Session session = WikiSessionTest.authenticatedSession(m_engine, Users.ALICE, Users.ALICE_PASS);
Assertions.assertTrue(m_auth.checkPermission(session, view), "Alice view Test/test1.txt");
Assertions.assertTrue(m_auth.checkPermission(session, edit), "Alice view Test/test1.txt");
// Create authenticated session with user 'Bob', who can't read or edit (not in ACL)
session = WikiSessionTest.authenticatedSession(m_engine, Users.BOB, Users.BOB_PASS);
Assertions.assertFalse(m_auth.checkPermission(session, view), "Bob !view Test/test1.txt");
Assertions.assertFalse(m_auth.checkPermission(session, edit), "Bob !view Test/test1.txt");
// Delete test page & attachment
m_engine.getManager(AttachmentManager.class).deleteAttachment(att);
m_engine.getManager(PageManager.class).deletePage("Test");
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class AuthorizationManagerTest method testInheritedAclPermissions.
@Test
public void testInheritedAclPermissions() throws Exception {
// Create test page & attachment
final String src = "[{ALLOW view Alice}] ";
m_engine.saveText("Test", src);
final File f = m_engine.makeAttachmentFile();
final Attachment att = Wiki.contents().attachment(m_engine, "Test", "test1.txt");
att.setAuthor("FirstPost");
m_engine.getManager(AttachmentManager.class).storeAttachment(att, f);
final Attachment p = (Attachment) m_engine.getManager(PageManager.class).getPage("Test/test1.txt");
final Permission view = PermissionFactory.getPagePermission(p, "view");
final Permission edit = PermissionFactory.getPagePermission(p, "edit");
// Create session with user 'Alice', who can read (in ACL)
Session session = WikiSessionTest.authenticatedSession(m_engine, Users.ALICE, Users.ALICE_PASS);
Assertions.assertTrue(m_auth.checkPermission(session, view), "Foo view Test");
Assertions.assertFalse(m_auth.checkPermission(session, edit), "Foo !edit Test");
// Create session with user 'Bob', who can't read or edit (not in ACL)
session = WikiSessionTest.authenticatedSession(m_engine, Users.BOB, Users.BOB_PASS);
Assertions.assertFalse(m_auth.checkPermission(session, view), "Bar !view Test");
Assertions.assertFalse(m_auth.checkPermission(session, view), "Bar !edit Test");
// Delete test page & attachment
m_engine.getManager(AttachmentManager.class).deleteAttachment(att);
m_engine.getManager(PageManager.class).deletePage("Test");
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class AttachmentManagerTest method testExistsUTF2.
@Test
public void testExistsUTF2() throws Exception {
final Attachment att = Wiki.contents().attachment(m_engine, NAMEU, "test\u00e4.bin");
att.setAuthor("FirstPost");
m_manager.storeAttachment(att, makeAttachmentFile());
Assertions.assertTrue(m_engine.getManager(PageManager.class).wikiPageExists(att.getName()), "attachment disappeared");
}
Aggregations