Search in sources :

Example 26 with WikiContext

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

the class RSSGeneratorTest method testBlogRSS.

@Test
public void testBlogRSS() throws Exception {
    WeblogEntryPlugin plugin = new WeblogEntryPlugin();
    m_testEngine.saveText("TestBlog", "Foo1");
    String newPage = plugin.getNewEntryPage(m_testEngine, "TestBlog");
    m_testEngine.saveText(newPage, "!Title1\r\nFoo");
    newPage = plugin.getNewEntryPage(m_testEngine, "TestBlog");
    m_testEngine.saveText(newPage, "!Title2\r\n__Bar__");
    RSSGenerator gen = m_testEngine.getRSSGenerator();
    WikiContext context = new WikiContext(m_testEngine, m_testEngine.getPage("TestBlog"));
    WeblogPlugin blogplugin = new WeblogPlugin();
    List<?> entries = blogplugin.findBlogEntries(m_testEngine, "TestBlog", new Date(0), new Date(Long.MAX_VALUE));
    Feed feed = new RSS10Feed(context);
    String blog = gen.generateBlogRSS(context, entries, feed);
    Assert.assertTrue("has Foo", blog.indexOf("<description>Foo</description>") != -1);
    Assert.assertTrue("has proper Bar", blog.indexOf("&lt;b&gt;Bar&lt;/b&gt;") != -1);
}
Also used : WikiContext(org.apache.wiki.WikiContext) WeblogPlugin(org.apache.wiki.plugin.WeblogPlugin) WeblogEntryPlugin(org.apache.wiki.plugin.WeblogEntryPlugin) Date(java.util.Date) Test(org.junit.Test)

Example 27 with WikiContext

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

the class SearchManagerTest method testSimpleSearch4.

@Test
public void testSimpleSearch4() 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);
    Thread.yield();
    Collection res = waitForIndex("mankind", "testSimpleSearch4");
    Assert.assertNotNull("found results", res);
    Assert.assertEquals("result not found", 1, res.size());
    m_engine.saveText(ctx, "[{ALLOW view Authenticated}] It was the dawn of the third age of mankind... page is blocked");
    res = m_mgr.findPages("mankind", ctx);
    Assert.assertNotNull("null result", res);
    Assert.assertEquals("result found, should be blocked", 0, res.size());
    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 28 with WikiContext

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

the class SearchManagerTest method waitForIndex.

/**
 * Should cover for both index and initial delay
 */
Collection waitForIndex(String text, String testName) throws Exception {
    Collection res = null;
    for (long l = 0; l < SLEEP_COUNT; l++) {
        if (res == null || res.isEmpty()) {
            Thread.sleep(SLEEP_TIME);
        } else {
            break;
        }
        MockHttpServletRequest request = m_engine.newHttpRequest();
        WikiContext ctx = m_engine.createContext(request, WikiContext.EDIT);
        res = m_mgr.findPages(text, ctx);
    // debugSearchResults( res );
    }
    return res;
}
Also used : WikiContext(org.apache.wiki.WikiContext) MockHttpServletRequest(net.sourceforge.stripes.mock.MockHttpServletRequest) Collection(java.util.Collection)

Example 29 with WikiContext

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

the class IfPluginTest method testIfPluginIPNotAllowed.

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

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

the class IfPluginTest method getJanneBasedWikiContextFor.

/**
 * Returns a {@link WikiContext} for the given page, with user {@link Users#JANNE} logged in.
 *
 * @param page given {@link WikiPage}.
 * @return {@link WikiContext} associated to given {@link WikiPage}.
 * @throws WikiException problems while logging in.
 */
WikiContext getJanneBasedWikiContextFor(WikiPage page) throws WikiException {
    MockHttpServletRequest request = testEngine.newHttpRequest();
    WikiSession session = WikiSession.getWikiSession(testEngine, request);
    testEngine.getAuthenticationManager().login(session, request, Users.JANNE, Users.JANNE_PASS);
    return new WikiContext(testEngine, request, page);
}
Also used : WikiSession(org.apache.wiki.WikiSession) WikiContext(org.apache.wiki.WikiContext) MockHttpServletRequest(net.sourceforge.stripes.mock.MockHttpServletRequest)

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