Search in sources :

Example 56 with Context

use of org.apache.wiki.api.core.Context 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.
 */
@Test
public void testCache() throws Exception {
    m_engine.saveText("TestPage", TEST_TEXT);
    final StopWatch sw = new StopWatch();
    // System.out.println("DOM cache speed test:");
    sw.start();
    for (int i = 0; i < 300; i++) {
        final Page page = m_engine.getManager(PageManager.class).getPage("TestPage");
        final String pagedata = m_engine.getManager(PageManager.class).getPureText(page);
        final Context context = Wiki.context().create(m_engine, page);
        final MarkupParser p = m_manager.getParser(context, pagedata);
        final WikiDocument d = p.parse();
        final String html = m_manager.getHTML(context, d);
        Assertions.assertNotNull(html, "noncached got null response");
    }
    sw.stop();
    sw.reset();
    sw.start();
    for (int i = 0; i < 300; i++) {
        final Page page = m_engine.getManager(PageManager.class).getPage("TestPage");
        final String pagedata = m_engine.getManager(PageManager.class).getPureText(page);
        final Context context = Wiki.context().create(m_engine, page);
        final String html = m_manager.getHTML(context, pagedata);
        Assertions.assertNotNull(html, "cached got null response");
    }
    sw.stop();
}
Also used : Context(org.apache.wiki.api.core.Context) PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page) WikiDocument(org.apache.wiki.parser.WikiDocument) StopWatch(org.apache.commons.lang3.time.StopWatch) MarkupParser(org.apache.wiki.parser.MarkupParser) Test(org.junit.jupiter.api.Test)

Example 57 with Context

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

the class RSSGeneratorTest method testBlogRSS2.

@Test
public void testBlogRSS2() throws Exception {
    final 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__");
    final RSSGenerator gen = m_testEngine.getManager(RSSGenerator.class);
    final Context context = Wiki.context().create(m_testEngine, m_testEngine.getManager(PageManager.class).getPage("TestBlog"));
    final WeblogPlugin blogplugin = new WeblogPlugin();
    final List<Page> entries = blogplugin.findBlogEntries(m_testEngine, "TestBlog", new Date(0), new Date(Long.MAX_VALUE));
    final Feed feed = new RSS20Feed(context);
    final String blog = gen.generateBlogRSS(context, entries, feed);
    Assertions.assertTrue(blog.contains("<description>Foo &amp;quot;blah&amp;quot;.</description>"), "has Foo");
    Assertions.assertTrue(blog.contains("&lt;b&gt;Bar&lt;/b&gt;"), "has proper Bar");
}
Also used : Context(org.apache.wiki.api.core.Context) WeblogPlugin(org.apache.wiki.plugin.WeblogPlugin) Page(org.apache.wiki.api.core.Page) WeblogEntryPlugin(org.apache.wiki.plugin.WeblogEntryPlugin) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 58 with Context

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

the class PageRenamerTest method testReferrerChangeMultiRename2.

@Test
public void testReferrerChangeMultiRename2() throws Exception {
    m_engine.saveText("TestPage", "foofoo");
    m_engine.saveText("TestPage2", "[Test|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);
    m_engine.getManager(PageRenamer.class).renamePage(context, "FooTest", "BarTest", true);
    final String data = m_engine.getManager(PageManager.class).getPureText("TestPage2", WikiProvider.LATEST_VERSION);
    Assertions.assertEquals("[Test|BarTest]", 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("FooPage");
    Assertions.assertNull(refs, "oldpage");
    refs = m_engine.getManager(ReferenceManager.class).findReferrers("BarTest");
    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 59 with Context

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

the class PageRenamerTest method testReferrerChangeAnchor.

@Test
public void testReferrerChangeAnchor() throws Exception {
    m_engine.saveText("TestPage", "foofoo");
    m_engine.saveText("TestPage2", "[TestPage#heading1]");
    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#heading1]", 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 60 with Context

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

the class PageRenamerTest method testReferrerNoWikiName.

@Test
public void testReferrerNoWikiName() throws Exception {
    m_engine.saveText("Test", "foo");
    m_engine.saveText("TestPage2", "[Test] [Test#anchor] test Test [test] [link|test] [link|test]");
    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, "Test", "TestPage", true);
    final String data = m_engine.getManager(PageManager.class).getPureText("TestPage2", WikiProvider.LATEST_VERSION);
    Assertions.assertEquals("[TestPage] [TestPage#anchor] test Test [TestPage] [link|TestPage] [link|TestPage]", data.trim(), "wrong data");
}
Also used : Context(org.apache.wiki.api.core.Context) PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page) 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