Search in sources :

Example 66 with Page

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));
}
Also used : PageManager(org.apache.wiki.pages.PageManager) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) AclEntry(org.apache.wiki.api.core.AclEntry) Page(org.apache.wiki.api.core.Page) Acl(org.apache.wiki.api.core.Acl) Test(org.junit.jupiter.api.Test)

Example 67 with Page

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");
}
Also used : Page(org.apache.wiki.api.core.Page) TestEngine(org.apache.wiki.TestEngine) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 68 with Page

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);
}
Also used : Context(org.apache.wiki.api.core.Context) MockServletContext(net.sourceforge.stripes.mock.MockServletContext) ServletContext(javax.servlet.ServletContext) PageManager(org.apache.wiki.pages.PageManager) RenderingManager(org.apache.wiki.render.RenderingManager) Page(org.apache.wiki.api.core.Page)

Example 69 with 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());
    }
}
Also used : PageManager(org.apache.wiki.pages.PageManager) ProviderException(org.apache.wiki.api.exceptions.ProviderException) WikiPermission(org.apache.wiki.auth.permissions.WikiPermission) PagePermission(org.apache.wiki.auth.permissions.PagePermission) AllPermission(org.apache.wiki.auth.permissions.AllPermission) Permission(java.security.Permission) Page(org.apache.wiki.api.core.Page) Session(org.apache.wiki.api.core.Session) WikiSessionTest(org.apache.wiki.WikiSessionTest) Test(org.junit.jupiter.api.Test)

Example 70 with Page

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"));
}
Also used : Page(org.apache.wiki.api.core.Page) Test(org.junit.jupiter.api.Test)

Aggregations

Page (org.apache.wiki.api.core.Page)181 PageManager (org.apache.wiki.pages.PageManager)106 Test (org.junit.jupiter.api.Test)71 Context (org.apache.wiki.api.core.Context)46 Engine (org.apache.wiki.api.core.Engine)30 Attachment (org.apache.wiki.api.core.Attachment)27 ProviderException (org.apache.wiki.api.exceptions.ProviderException)22 Date (java.util.Date)21 WikiPage (org.apache.wiki.WikiPage)18 ReferenceManager (org.apache.wiki.references.ReferenceManager)16 RenderingManager (org.apache.wiki.render.RenderingManager)15 AttachmentManager (org.apache.wiki.attachment.AttachmentManager)14 File (java.io.File)11 ArrayList (java.util.ArrayList)10 Calendar (java.util.Calendar)10 Hashtable (java.util.Hashtable)10 IOException (java.io.IOException)9 Vector (java.util.Vector)9 TestEngine (org.apache.wiki.TestEngine)9 PagePermission (org.apache.wiki.auth.permissions.PagePermission)8