Search in sources :

Example 51 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class SearchManagerTest method testSimpleSearch3.

@Test
public void testSimpleSearch3() throws Exception {
    String txt = "It was the dawn of the third age of mankind, ten years after the Earth-Minbari War.";
    MockHttpServletRequest request = m_engine.newHttpRequest();
    request.getParameterMap().put("page", new String[] { "TestPage" });
    WikiContext ctx = m_engine.createContext(request, WikiContext.EDIT);
    m_engine.saveText(ctx, txt);
    m_engine.saveText(ctx, "The Babylon Project was a dream given form. Its goal: to prevent another war by creating a place where humans and aliens could work out their differences peacefully.");
    Thread.yield();
    // wait until 2nd m_engine.saveText() takes effect
    Collection res = waitForIndex("Babylon", "testSimpleSearch3");
    // check for text present in 1st m_engine.saveText() but not in 2nd
    res = m_mgr.findPages("mankind", ctx);
    Assert.assertNotNull("found results", res);
    Assert.assertEquals("empty results", 0, res.size());
    res = m_mgr.findPages("Babylon", ctx);
    Assert.assertNotNull("null result", res);
    Assert.assertEquals("no pages", 1, res.size());
    Assert.assertEquals("page", "TestPage", ((SearchResult) res.iterator().next()).getPage().getName());
    m_engine.deleteTestPage("TestPage");
}
Also used : WikiContext(org.apache.wiki.WikiContext) MockHttpServletRequest(net.sourceforge.stripes.mock.MockHttpServletRequest) Collection(java.util.Collection) Test(org.junit.Test)

Example 52 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class InputValidatorTest method setUp.

@Before
public void setUp() throws Exception {
    Properties props = TestEngine.getTestProperties();
    testEngine = new TestEngine(props);
    WikiContext context = new WikiContext(testEngine, new WikiPage(testEngine, "dummyPage"));
    val = new InputValidator(TEST, context);
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) TestEngine(org.apache.wiki.TestEngine) Properties(java.util.Properties) Before(org.junit.Before)

Example 53 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class PluginBeanTest method testDoGet.

@Test
public void testDoGet() throws WikiException, NotCompliantMBeanException {
    testEngine = new TestEngine(props);
    WikiContext context = new WikiContext(testEngine, new WikiPage(testEngine, "TestPage01"));
    PluginBean pb = new PluginBean(testEngine);
    String expectedHtml = "<div>" + "<h4>Plugins</h4>" + "<table border=\"1\">" + "<tr><th>Name</th><th>Alias</th><th>Author</th><th>Notes</th></tr>" + "<tr><td>IfPlugin</td><td>If</td><td>Janne Jalkanen</td><td></td></tr>" + "<tr><td>Note</td><td></td><td>Janne Jalkanen</td><td></td></tr>" + "<tr><td>SamplePlugin</td><td>samplealias</td><td>Janne Jalkanen</td><td></td></tr>" + "<tr><td>SamplePlugin2</td><td>samplealias2</td><td>Janne Jalkanen</td><td></td></tr>" + "</table>" + "</div>";
    Assert.assertEquals(expectedHtml, pb.doGet(context));
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) TestEngine(org.apache.wiki.TestEngine) Test(org.junit.Test)

Example 54 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class IfPluginTest method testIfPluginUserAllowed.

/**
 * Checks that user access is granted.
 *
 * @throws WikiException test Assert.failing.
 */
@Test
public void testIfPluginUserAllowed() throws WikiException {
    String src = "[{IfPlugin user='Janne Jalkanen'\n" + "\n" + "Content visible for Janne Jalkanen}]";
    String expected = "<p>Content visible for Janne Jalkanen</p>\n";
    testEngine.saveText("Test", src);
    WikiPage page = testEngine.getPage("Test", WikiPageProvider.LATEST_VERSION);
    WikiContext context = getJanneBasedWikiContextFor(page);
    String res = testEngine.getHTML(context, page);
    Assert.assertEquals(expected, res);
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 55 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class IfPluginTest method testIfPluginIPAllowed.

/**
 * Checks that IP address is granted.
 *
 * @throws WikiException test Assert.failing.
 */
@Test
public void testIfPluginIPAllowed() throws WikiException {
    String src = "[{IfPlugin ip='127.0.0.1'\n" + "\n" + "Content visible for 127.0.0.1}]";
    String expected = "<p>Content visible for 127.0.0.1</p>\n";
    testEngine.saveText("Test", src);
    WikiPage page = testEngine.getPage("Test", WikiPageProvider.LATEST_VERSION);
    WikiContext context = getJanneBasedWikiContextFor(page);
    String res = testEngine.getHTML(context, page);
    Assert.assertEquals(expected, res);
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Aggregations

WikiContext (org.apache.wiki.WikiContext)90 WikiPage (org.apache.wiki.WikiPage)63 Test (org.junit.Test)40 TestEngine (org.apache.wiki.TestEngine)11 StringReader (java.io.StringReader)9 WikiEngine (org.apache.wiki.WikiEngine)9 ProviderException (org.apache.wiki.api.exceptions.ProviderException)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 Before (org.junit.Before)7 BufferedReader (java.io.BufferedReader)6 StringWriter (java.io.StringWriter)6 Collection (java.util.Collection)6 InputStreamReader (java.io.InputStreamReader)5 Date (java.util.Date)5 LinkCollector (org.apache.wiki.LinkCollector)5 Attachment (org.apache.wiki.attachment.Attachment)5 Properties (java.util.Properties)4 MockHttpServletRequest (net.sourceforge.stripes.mock.MockHttpServletRequest)4 WikiDocument (org.apache.wiki.parser.WikiDocument)4