Search in sources :

Example 16 with Context

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

the class SaveWikiPageTaskTest method testSaveWikiPageTaskWithVersioningFileProvider.

@Test
public void testSaveWikiPageTaskWithVersioningFileProvider() throws Exception {
    final TestEngine engine = TestEngine.build(with("jspwiki.pageProvider", "VersioningFileProvider"), with("jspwiki.lucene.initialdelay", "0"), with("jspwiki.lucene.indexdelay", "1"));
    final String pageName = "TestSaveWikiPageTestPageWithVersioningFileProvider";
    final Page page = Wiki.contents().page(engine, pageName);
    engine.saveText(pageName, "initial text on first revision");
    final Context context = Wiki.context().create(engine, engine.newHttpRequest(), page);
    final SaveWikiPageTask task = new SaveWikiPageTask();
    task.setWorkflow(1, new HashMap<>());
    task.getWorkflowContext().put(WorkflowManager.WF_WP_SAVE_FACT_PROPOSED_TEXT, "It is based on ties of history, culture, language, ethnicity, kinship and geography");
    final Collection<SearchResult> res = new ArrayList<>();
    Assertions.assertEquals(Outcome.STEP_COMPLETE, task.execute(context));
    Awaitility.await("ensure latest version of page gets indexed").until(findsResultsFor(context, res, "kinship"));
    Assertions.assertEquals(1, res.size(), "no pages found");
    Assertions.assertEquals(pageName, res.iterator().next().getPage().getName(), "page");
}
Also used : Context(org.apache.wiki.api.core.Context) ArrayList(java.util.ArrayList) Page(org.apache.wiki.api.core.Page) SearchResult(org.apache.wiki.api.search.SearchResult) TestEngine(org.apache.wiki.TestEngine) Test(org.junit.jupiter.api.Test)

Example 17 with Context

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

the class FilterBeanTest method testDoGet.

@Test
public void testDoGet() throws WikiException, NotCompliantMBeanException {
    final Context context = Wiki.context().create(testEngine, Wiki.contents().page(testEngine, "TestPage01"));
    final FilterBean pb = new FilterBean(testEngine);
    final String expectedHtml = "<div>" + "<h4>Filters</h4>" + "<table border=\"1\">" + "<tr><th>Name</th><th>Author</th><th>Notes</th></tr>" + "<tr><td>org.apache.wiki.filters.SpamFilter</td><td>Janne Jalkanen</td><td></td></tr>" + "</table>" + "</div>";
    Assertions.assertEquals(expectedHtml, pb.doGet(context));
}
Also used : Context(org.apache.wiki.api.core.Context) Test(org.junit.jupiter.api.Test)

Example 18 with Context

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

the class ApprovalWorkflowTest method testSaveWikiPageWithApproval.

@Test
public void testSaveWikiPageWithApproval() throws WikiException {
    // Create a sample test page and try to save it
    final String pageName = "SaveWikiPageWorkflow-Test" + System.currentTimeMillis();
    final String text = "This is a test!";
    // Expected exception...
    Assertions.assertThrows(DecisionRequiredException.class, () -> m_engine.saveTextAsJanne(pageName, text));
    // How do we know the workflow works? Well, first of all the page shouldn't exist yet...
    Assertions.assertFalse(m_engine.getManager(PageManager.class).wikiPageExists(pageName));
    // Second, GroupPrincipal Admin should see a Decision in its queue
    Collection<Decision> decisions = m_dq.getActorDecisions(m_engine.adminSession());
    Assertions.assertEquals(1, decisions.size());
    // Now, approve the decision and it should go away, and page should appear.
    final Context context = Wiki.context().create(m_engine, Wiki.contents().page(m_engine, pageName));
    final Decision decision = decisions.iterator().next();
    decision.decide(Outcome.DECISION_APPROVE, context);
    Assertions.assertTrue(m_engine.getManager(PageManager.class).wikiPageExists(pageName));
    decisions = m_dq.getActorDecisions(m_engine.adminSession());
    Assertions.assertEquals(0, decisions.size());
    // Delete the page we created
    m_engine.getManager(PageManager.class).deletePage(pageName);
}
Also used : Context(org.apache.wiki.api.core.Context) PageManager(org.apache.wiki.pages.PageManager) Test(org.junit.jupiter.api.Test)

Example 19 with Context

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

the class UndefinedPagesPluginTest method testSimpleUndefined.

/**
 *  Tests that only correct undefined links are found.
 *  We also check against plural forms here, which should not
 *  be listed as non-existent.
 */
@Test
public void testSimpleUndefined() throws Exception {
    final Context context2 = Wiki.context().create(testEngine, Wiki.contents().page(testEngine, "Foobar"));
    final String res = manager.execute(context2, "{INSERT org.apache.wiki.plugin.UndefinedPagesPlugin");
    final String exp = "[Foobar 2]\\\\";
    Assertions.assertEquals(wikitize(exp), res);
}
Also used : Context(org.apache.wiki.api.core.Context) Test(org.junit.jupiter.api.Test)

Example 20 with Context

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

the class UndefinedPagesPluginTest method testUndefinedWithColumns.

@Test
public void testUndefinedWithColumns() throws Exception {
    final Context context2 = Wiki.context().create(testEngine, Wiki.contents().page(testEngine, "Foobar"));
    final String res = manager.execute(context2, "{UndefinedPagesPlugin columns=2");
    Assertions.assertTrue(res.startsWith("<div style=\"columns:2;-moz-columns:2;-webkit-columns:2;\"><a "));
}
Also used : Context(org.apache.wiki.api.core.Context) 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