Search in sources :

Example 66 with Context

use of org.apache.wiki.api.core.Context in project jspwiki by apache.

the class IfPluginTest method testIfPluginUserAllowed.

/**
 * Checks that user access is granted.
 *
 * @throws WikiException test Assertions.failing.
 */
@Test
public void testIfPluginUserAllowed() throws WikiException {
    final String src = "[{IfPlugin user='Janne Jalkanen'\n\nContent visible for Janne Jalkanen}]";
    final String expected = "<p>Content visible for Janne Jalkanen</p>\n";
    testEngine.saveText("Test", src);
    final Page page = testEngine.getManager(PageManager.class).getPage("Test", PageProvider.LATEST_VERSION);
    final Context context = getJanneBasedWikiContextFor(page);
    final String res = testEngine.getManager(RenderingManager.class).getHTML(context, page);
    Assertions.assertEquals(expected, res);
}
Also used : Context(org.apache.wiki.api.core.Context) WikiContext(org.apache.wiki.WikiContext) PageManager(org.apache.wiki.pages.PageManager) RenderingManager(org.apache.wiki.render.RenderingManager) Page(org.apache.wiki.api.core.Page) Test(org.junit.jupiter.api.Test)

Example 67 with Context

use of org.apache.wiki.api.core.Context in project jspwiki by apache.

the class IfPluginTest method testIfPluginIPAllowed.

/**
 * Checks that IP address is granted.
 *
 * @throws WikiException test Assertions.failing.
 */
@Test
public void testIfPluginIPAllowed() throws WikiException {
    final String src = "[{IfPlugin ip='127.0.0.1'\n\nContent visible for 127.0.0.1}]";
    final String expected = "<p>Content visible for 127.0.0.1</p>\n";
    testEngine.saveText("Test", src);
    final Page page = testEngine.getManager(PageManager.class).getPage("Test", PageProvider.LATEST_VERSION);
    final Context context = getJanneBasedWikiContextFor(page);
    final String res = testEngine.getManager(RenderingManager.class).getHTML(context, page);
    Assertions.assertEquals(expected, res);
}
Also used : Context(org.apache.wiki.api.core.Context) WikiContext(org.apache.wiki.WikiContext) PageManager(org.apache.wiki.pages.PageManager) RenderingManager(org.apache.wiki.render.RenderingManager) Page(org.apache.wiki.api.core.Page) Test(org.junit.jupiter.api.Test)

Example 68 with Context

use of org.apache.wiki.api.core.Context in project jspwiki by apache.

the class VersioningFileProviderTest method testChangeNoteOldVersion.

@Test
public void testChangeNoteOldVersion() throws Exception {
    final Page p = Wiki.contents().page(engine, NAME1);
    final Context context = Wiki.context().create(engine, p);
    context.getPage().setAttribute(Page.CHANGENOTE, "Test change");
    engine.getManager(PageManager.class).saveText(context, "test");
    context.getPage().setAttribute(Page.CHANGENOTE, "Change 2");
    engine.getManager(PageManager.class).saveText(context, "test2");
    final Page p2 = engine.getManager(PageManager.class).getPage(NAME1, 1);
    Assertions.assertEquals("Test change", p2.getAttribute(Page.CHANGENOTE));
    final Page p3 = engine.getManager(PageManager.class).getPage(NAME1, 2);
    Assertions.assertEquals("Change 2", p3.getAttribute(Page.CHANGENOTE));
}
Also used : Context(org.apache.wiki.api.core.Context) PageManager(org.apache.wiki.pages.PageManager) WikiPage(org.apache.wiki.WikiPage) Page(org.apache.wiki.api.core.Page) Test(org.junit.jupiter.api.Test)

Example 69 with Context

use of org.apache.wiki.api.core.Context in project jspwiki by apache.

the class VersioningFileProviderTest method testChangeNoteOldVersion2.

@Test
public void testChangeNoteOldVersion2() throws Exception {
    final Page p = Wiki.contents().page(engine, NAME1);
    final Context context = Wiki.context().create(engine, p);
    context.getPage().setAttribute(Page.CHANGENOTE, "Test change");
    engine.getManager(PageManager.class).saveText(context, "test");
    for (int i = 0; i < 5; i++) {
        final Page p2 = engine.getManager(PageManager.class).getPage(NAME1).clone();
        p2.removeAttribute(Page.CHANGENOTE);
        context.setPage(p2);
        engine.getManager(PageManager.class).saveText(context, "test" + i);
    }
    final Page p3 = engine.getManager(PageManager.class).getPage(NAME1, -1);
    Assertions.assertNull(p3.getAttribute(Page.CHANGENOTE));
}
Also used : Context(org.apache.wiki.api.core.Context) PageManager(org.apache.wiki.pages.PageManager) WikiPage(org.apache.wiki.WikiPage) Page(org.apache.wiki.api.core.Page) Test(org.junit.jupiter.api.Test)

Example 70 with Context

use of org.apache.wiki.api.core.Context in project jspwiki by apache.

the class PageViewPluginTest method testShowCountsSorted.

@Test
public void testShowCountsSorted() throws Exception {
    final Page page1 = testEngine.getManager(PageManager.class).getPage("TestPage01");
    final Context context1 = Wiki.context().create(testEngine, page1);
    final Page page2 = testEngine.getManager(PageManager.class).getPage("TestPage02");
    final Context context2 = Wiki.context().create(testEngine, page2);
    // generate counts:
    testEngine.getManager(RenderingManager.class).getHTML(context1, page1);
    testEngine.getManager(RenderingManager.class).getHTML(context2, page2);
    testEngine.getManager(RenderingManager.class).getHTML(context2, page2);
    // mind the double \n in the following string:
    final String pageViewPageContent = "[{PageViewPlugin show='list' sort=count '\n\n* {1} ({2} views)\n}]";
    testEngine.saveText("PageViews", pageViewPageContent);
    final Page pageviews = testEngine.getManager(PageManager.class).getPage("PageViews");
    final Context contextPV = Wiki.context().create(testEngine, pageviews);
    final String result = testEngine.getManager(RenderingManager.class).getHTML(contextPV, pageviews);
    // System.out.println( result );
    final int start1 = result.indexOf("Test Page 01");
    final int start2 = result.indexOf("Test Page 02");
    // page2 should be showed before page1
    Assertions.assertTrue(start2 < start1);
}
Also used : Context(org.apache.wiki.api.core.Context) PageManager(org.apache.wiki.pages.PageManager) RenderingManager(org.apache.wiki.render.RenderingManager) Page(org.apache.wiki.api.core.Page) Test(org.junit.jupiter.api.Test)

Aggregations

Context (org.apache.wiki.api.core.Context)81 Page (org.apache.wiki.api.core.Page)46 PageManager (org.apache.wiki.pages.PageManager)42 Test (org.junit.jupiter.api.Test)40 RenderingManager (org.apache.wiki.render.RenderingManager)15 PageContext (javax.servlet.jsp.PageContext)11 Engine (org.apache.wiki.api.core.Engine)9 ReferenceManager (org.apache.wiki.references.ReferenceManager)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 ServletContext (javax.servlet.ServletContext)6 ProviderException (org.apache.wiki.api.exceptions.ProviderException)6 WikiContext (org.apache.wiki.WikiContext)5 StringReader (java.io.StringReader)4 Properties (java.util.Properties)4 MockHttpServletRequest (net.sourceforge.stripes.mock.MockHttpServletRequest)4 WikiSessionTest (org.apache.wiki.WikiSessionTest)4 Attachment (org.apache.wiki.api.core.Attachment)4 SearchResult (org.apache.wiki.api.search.SearchResult)4