use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class DefaultAclManagerTest method testPrintAcl.
@Test
public void testPrintAcl() {
// Verify that the printed Acl for the test page is OK
final Page page = m_engine.getManager(PageManager.class).getPage("TestAclPage");
Acl acl = m_engine.getManager(AclManager.class).getPermissions(page);
final String aclString = DefaultAclManager.printAcl(acl);
Assertions.assertEquals("[{ALLOW edit Charlie,Herman}]\n", aclString);
// Create an ACL from scratch
acl = Wiki.acls().acl();
AclEntry entry = Wiki.acls().entry();
entry.setPrincipal(new WikiPrincipal("Charlie"));
entry.addPermission(PermissionFactory.getPagePermission("Main:Foo", "view"));
entry.addPermission(PermissionFactory.getPagePermission("Main:Foo", "edit"));
acl.addEntry(entry);
entry = Wiki.acls().entry();
entry.setPrincipal(new WikiPrincipal("Devin"));
entry.addPermission(PermissionFactory.getPagePermission("Main:Foo", "edit"));
entry.addPermission(PermissionFactory.getPagePermission("Main:Foo", "delete"));
acl.addEntry(entry);
// Verify that the printed ACL is OK
final String expectedValue = "[{ALLOW delete Devin}]\n[{ALLOW edit Charlie,Devin}]\n[{ALLOW view Charlie}]\n";
Assertions.assertEquals(expectedValue, DefaultAclManager.printAcl(acl));
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class DefaultPageManagerTest method testDeleteVersion.
@Test
public void testDeleteVersion() throws Exception {
final Properties props = engine.getWikiProperties();
props.setProperty("jspwiki.pageProvider", "VersioningFileProvider");
final TestEngine engine = new TestEngine(props);
engine.saveText(NAME1, "Test1");
engine.saveText(NAME1, "Test2");
engine.saveText(NAME1, "Test3");
final Page page = engine.getManager(PageManager.class).getPage(NAME1, 3);
engine.getManager(PageManager.class).deleteVersion(page);
Assertions.assertNull(engine.getManager(PageManager.class).getPage(NAME1, 3), "got page");
final String content = engine.getManager(PageManager.class).getText(NAME1, WikiProvider.LATEST_VERSION);
Assertions.assertEquals("Test2", content.trim(), "content");
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class TestEngine method getI18nHTML.
/**
* Some pages may produce some i18n text, so we enforce english locale in order to
* be able to compare properly to assertion texts.
*
* @param pagename name of the page.
* @return (english) contents corresponding to the given page name.
*/
public String getI18nHTML(final String pagename) {
final Page page = getManager(PageManager.class).getPage(pagename, PageProvider.LATEST_VERSION);
final Context context = Wiki.context().create(this, newHttpRequest(), page);
context.setRequestContext(ContextEnum.PAGE_NONE.getRequestContext());
return getManager(RenderingManager.class).getHTML(context, page);
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class AuthorizationManagerTest method testRoleAcl.
@Test
public void testRoleAcl() throws Exception {
// Create test page & attachment
final String src = "[{ALLOW edit Authenticated}] ";
m_engine.saveText("Test", src);
final Page p = m_engine.getManager(PageManager.class).getPage("Test");
final Permission view = PermissionFactory.getPagePermission(p, "view");
final Permission edit = PermissionFactory.getPagePermission(p, "edit");
// Create session with authenticated user 'Alice', who can read & edit
Session session = WikiSessionTest.authenticatedSession(m_engine, Users.ALICE, Users.ALICE_PASS);
Assertions.assertTrue(m_auth.checkPermission(session, view), "Alice view Test");
Assertions.assertTrue(m_auth.checkPermission(session, edit), "Alice edit Test");
// Create session with asserted user 'Bob', who can't read or edit (not in ACL)
session = WikiSessionTest.assertedSession(m_engine, Users.BOB);
Assertions.assertFalse(m_auth.checkPermission(session, view), "Bob !view Test");
Assertions.assertFalse(m_auth.checkPermission(session, edit), "Bob !edit Test");
// Cleanup
try {
m_engine.getManager(PageManager.class).deletePage("Test");
} catch (final ProviderException e) {
Assertions.fail(e.getMessage());
}
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class JSPWikiMarkupParserTest method testSet4.
@Test
public void testSet4() throws Exception {
final String src = "Foobar.[{SET name='Janne Jalkanen'}][{SET too='{$name}'}]";
final Page p = Wiki.contents().page(testEngine, PAGE_NAME);
final String res = translate(p, src);
Assertions.assertEquals("Foobar.", res, "Page text");
Assertions.assertEquals("Janne Jalkanen", p.getAttribute("name"));
Assertions.assertEquals("Janne Jalkanen", p.getAttribute("too"));
}
Aggregations