Search in sources :

Example 31 with Context

use of org.apache.wiki.api.core.Context 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 32 with Context

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

the class IfPluginTest method testIfPluginIPNotAllowed.

/**
 * Checks that IP address is granted.
 *
 * @throws WikiException test Assertions.failing.
 */
@Test
public void testIfPluginIPNotAllowed() throws WikiException {
    final String src = "[{IfPlugin ip='!127.0.0.1'\n\nContent NOT visible for 127.0.0.1}]";
    final String expected = "\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 33 with Context

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

the class IfPluginTest method testIfPluginUserNotAllowed.

/**
 * Checks that user access is forbidden.
 *
 * @throws WikiException test Assertions.failing.
 */
@Test
public void testIfPluginUserNotAllowed() throws WikiException {
    final String src = "[{IfPlugin user='!Janne Jalkanen'\n\nContent NOT visible for Janne Jalkanen}]";
    final String expected = "\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 34 with Context

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

the class PageRenamerTest method testReferrerChangeCC.

@Test
public void testReferrerChangeCC() throws Exception {
    m_engine.saveText("TestPage", "foofoo");
    m_engine.saveText("TestPage2", "TestPage");
    final Page p = m_engine.getManager(PageManager.class).getPage("TestPage");
    final Context context = Wiki.context().create(m_engine, p);
    m_engine.getManager(PageRenamer.class).renamePage(context, "TestPage", "FooTest", true);
    final String data = m_engine.getManager(PageManager.class).getPureText("TestPage2", WikiProvider.LATEST_VERSION);
    Assertions.assertEquals("FooTest", data.trim(), "no rename");
    Collection<String> refs = m_engine.getManager(ReferenceManager.class).findReferrers("TestPage");
    Assertions.assertNull(refs, "oldpage");
    refs = m_engine.getManager(ReferenceManager.class).findReferrers("FooTest");
    Assertions.assertEquals(1, refs.size(), "new size");
    Assertions.assertEquals("TestPage2", refs.iterator().next(), "wrong ref");
}
Also used : Context(org.apache.wiki.api.core.Context) PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page) ReferenceManager(org.apache.wiki.references.ReferenceManager) Test(org.junit.jupiter.api.Test)

Example 35 with Context

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

the class PageRenamerTest method testReferrerChangeMultilink.

@Test
public void testReferrerChangeMultilink() throws Exception {
    m_engine.saveText("TestPage", "foofoo");
    m_engine.saveText("TestPage2", "[TestPage] [TestPage] [linktext|TestPage] TestPage [linktext|TestPage] [TestPage#Anchor] [TestPage] TestPage [TestPage]");
    final Page p = m_engine.getManager(PageManager.class).getPage("TestPage");
    final Context context = Wiki.context().create(m_engine, p);
    m_engine.getManager(PageRenamer.class).renamePage(context, "TestPage", "FooTest", true);
    final String data = m_engine.getManager(PageManager.class).getPureText("TestPage2", WikiProvider.LATEST_VERSION);
    Assertions.assertEquals("[FooTest] [FooTest] [linktext|FooTest] FooTest [linktext|FooTest] [FooTest#Anchor] [FooTest] FooTest [FooTest]", data.trim(), "no rename");
    Collection<String> refs = m_engine.getManager(ReferenceManager.class).findReferrers("TestPage");
    Assertions.assertNull(refs, "oldpage");
    refs = m_engine.getManager(ReferenceManager.class).findReferrers("FooTest");
    Assertions.assertEquals(1, refs.size(), "new size");
    Assertions.assertEquals("TestPage2", refs.iterator().next(), "wrong ref");
}
Also used : Context(org.apache.wiki.api.core.Context) PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page) ReferenceManager(org.apache.wiki.references.ReferenceManager) 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