Search in sources :

Example 46 with WikiContext

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

the class VersioningFileProviderTest method testChangeNoteOldVersion2.

@Test
public void testChangeNoteOldVersion2() throws Exception {
    WikiPage p = new WikiPage(engine, NAME1);
    WikiContext context = new WikiContext(engine, p);
    context.getPage().setAttribute(WikiPage.CHANGENOTE, "Test change");
    engine.saveText(context, "test");
    for (int i = 0; i < 5; i++) {
        WikiPage p2 = (WikiPage) engine.getPage(NAME1).clone();
        p2.removeAttribute(WikiPage.CHANGENOTE);
        context.setPage(p2);
        engine.saveText(context, "test" + i);
    }
    WikiPage p3 = engine.getPage(NAME1, -1);
    Assert.assertEquals(null, p3.getAttribute(WikiPage.CHANGENOTE));
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 47 with WikiContext

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

the class CreoleRendererTest method render.

private String render(String s) throws IOException {
    WikiPage dummyPage = new WikiPage(m_testEngine, "TestPage");
    WikiContext ctx = new WikiContext(m_testEngine, dummyPage);
    StringReader in = new StringReader(s);
    JSPWikiMarkupParser p = new JSPWikiMarkupParser(ctx, in);
    WikiDocument d = p.parse();
    CreoleRenderer cr = new CreoleRenderer(ctx, d);
    return cr.getString();
}
Also used : WikiContext(org.apache.wiki.WikiContext) JSPWikiMarkupParser(org.apache.wiki.parser.JSPWikiMarkupParser) WikiPage(org.apache.wiki.WikiPage) StringReader(java.io.StringReader) WikiDocument(org.apache.wiki.parser.WikiDocument)

Example 48 with WikiContext

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

the class RenderingManagerTest method testCache.

/**
 * Tests the relative speed of the DOM cache with respect to
 * page being parsed every single time.
 * @throws Exception
 */
@Test
public void testCache() throws Exception {
    m_engine.saveText("TestPage", TEST_TEXT);
    StopWatch sw = new StopWatch();
    // System.out.println("DOM cache speed test:");
    sw.start();
    for (int i = 0; i < 300; i++) {
        WikiPage page = m_engine.getPage("TestPage");
        String pagedata = m_engine.getPureText(page);
        WikiContext context = new WikiContext(m_engine, page);
        MarkupParser p = m_manager.getParser(context, pagedata);
        WikiDocument d = p.parse();
        String html = m_manager.getHTML(context, d);
        Assert.assertNotNull("noncached got null response", html);
    }
    sw.stop();
    // System.out.println("  Nocache took "+sw);
    long nocachetime = sw.getTime();
    sw.reset();
    sw.start();
    for (int i = 0; i < 300; i++) {
        WikiPage page = m_engine.getPage("TestPage");
        String pagedata = m_engine.getPureText(page);
        WikiContext context = new WikiContext(m_engine, page);
        String html = m_manager.getHTML(context, pagedata);
        Assert.assertNotNull("cached got null response", html);
    }
    sw.stop();
    // System.out.println("  Cache took "+sw);
    long speedup = nocachetime / sw.getTime();
// System.out.println("  Approx speedup: "+speedup+"x");
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) WikiDocument(org.apache.wiki.parser.WikiDocument) StopWatch(org.apache.commons.lang.time.StopWatch) MarkupParser(org.apache.wiki.parser.MarkupParser) Test(org.junit.Test)

Example 49 with WikiContext

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

the class WysiwygEditingRendererTest method render.

private String render(String s) throws IOException {
    WikiPage dummyPage = new WikiPage(testEngine, "TestPage");
    WikiContext ctx = new WikiContext(testEngine, dummyPage);
    StringReader in = new StringReader(s);
    JSPWikiMarkupParser p = new JSPWikiMarkupParser(ctx, in);
    WikiDocument d = p.parse();
    WysiwygEditingRenderer wer = new WysiwygEditingRenderer(ctx, d);
    return wer.getString();
}
Also used : WikiContext(org.apache.wiki.WikiContext) JSPWikiMarkupParser(org.apache.wiki.parser.JSPWikiMarkupParser) WikiPage(org.apache.wiki.WikiPage) StringReader(java.io.StringReader) WikiDocument(org.apache.wiki.parser.WikiDocument)

Example 50 with WikiContext

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

the class RSSGeneratorTest method testBlogRSS2.

@Test
public void testBlogRSS2() 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 \"blah\".");
    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 RSS20Feed(context);
    String blog = gen.generateBlogRSS(context, entries, feed);
    Assert.assertTrue("has Foo", blog.indexOf("<description>Foo &amp;quot;blah&amp;quot;.</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)

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