Search in sources :

Example 56 with WikiContext

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

the class PageViewPluginTest method testShowCountsSorted.

@Test
public void testShowCountsSorted() throws Exception {
    WikiPage page1 = testEngine.getPage("TestPage01");
    WikiContext context1 = new WikiContext(testEngine, page1);
    WikiPage page2 = testEngine.getPage("TestPage02");
    WikiContext context2 = new WikiContext(testEngine, page2);
    // generate counts:
    testEngine.getHTML(context1, page1);
    testEngine.getHTML(context2, page2);
    testEngine.getHTML(context2, page2);
    // mind the double \n in the following string:
    String pageViewPageContent = "[{PageViewPlugin show='list' sort=count '\n\n* {1} ({2} views)\n}]";
    testEngine.saveText("PageViews", pageViewPageContent);
    WikiPage pageviews = testEngine.getPage("PageViews");
    WikiContext contextPV = new WikiContext(testEngine, pageviews);
    String result = testEngine.getHTML(contextPV, pageviews);
    // System.out.println( result );
    int start1 = result.indexOf("Test Page 01");
    int start2 = result.indexOf("Test Page 02");
    // page2 should be showed before page1
    Assert.assertTrue(start2 < start1);
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 57 with WikiContext

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

the class PageViewPluginTest method testShowCountsBasic.

@Test
public void testShowCountsBasic() throws Exception {
    WikiPage page1 = testEngine.getPage("TestPage01");
    WikiContext context1 = new WikiContext(testEngine, page1);
    WikiPage page2 = testEngine.getPage("TestPage02");
    WikiContext context2 = new WikiContext(testEngine, page2);
    // generate counts:
    testEngine.getHTML(context1, page1);
    testEngine.getHTML(context2, page2);
    testEngine.getHTML(context2, page2);
    // mind the double \n in the following string:
    String pageViewPageContent = "[{PageViewPlugin show='list''\n\n* {1} ({2} views)\n}]";
    testEngine.saveText("PageViews", pageViewPageContent);
    WikiPage pageviews = testEngine.getPage("PageViews");
    WikiContext contextPV = new WikiContext(testEngine, pageviews);
    String result = testEngine.getHTML(contextPV, pageviews);
    // System.out.println( result );
    Assert.assertTrue(result.contains("Test Page 01 (2 views)"));
    Assert.assertTrue(result.contains("Test Page 02 (3 views)"));
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 58 with WikiContext

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

the class RecentChangesPluginTest method testSimple.

/**
 * Plain test without parameters
 *
 * @throws Exception
 */
@Test
public void testSimple() throws Exception {
    context = new WikiContext(testEngine, new WikiPage(testEngine, "TestPage01"));
    String res = manager.execute(context, "{INSERT org.apache.wiki.plugin.RecentChangesPlugin}");
    // we don't want to compare the complete html returned, but check if
    // certain Strings are present and other Strings are not present
    Assert.assertTrue(res.contains("<table class=\"recentchanges\" cellpadding=\"4\">"));
    Assert.assertTrue(res.contains("<a href=\"/test/Wiki.jsp?page=TestPage01\">Test Page 01</a>"));
    Assert.assertTrue(res.contains("<a href=\"/test/Wiki.jsp?page=TestPage02\">Test Page 02</a>"));
    Assert.assertTrue(res.contains("<a href=\"/test/Wiki.jsp?page=TestPage03\">Test Page 03</a>"));
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 59 with WikiContext

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

the class RecentChangesPluginTest method testParmExClude.

/**
 * Test with the exclude parameter
 *
 * @throws Exception
 */
@Test
public void testParmExClude() throws Exception {
    context = new WikiContext(testEngine, new WikiPage(testEngine, "TestPage03"));
    String res = manager.execute(context, "{INSERT org.apache.wiki.plugin.RecentChangesPlugin exclude='TestPage03*'}");
    Assert.assertTrue(res.contains("<table class=\"recentchanges\" cellpadding=\"4\">"));
    Assert.assertTrue(res.contains("<a href=\"/test/Wiki.jsp?page=TestPage01\">Test Page 01</a>"));
    Assert.assertTrue(res.contains("<a href=\"/test/Wiki.jsp?page=TestPage02\">Test Page 02</a>"));
    Assert.assertFalse(res.contains("<a href=\"/test/Wiki.jsp?page=TestPage03\">Test Page 03</a>"));
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 60 with WikiContext

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

the class RecentChangesPluginTest method testParmInClude.

/**
 * Test with the include parameter
 *
 * @throws Exception
 */
@Test
public void testParmInClude() throws Exception {
    context = new WikiContext(testEngine, new WikiPage(testEngine, "TestPage02"));
    String res = manager.execute(context, "{INSERT org.apache.wiki.plugin.RecentChangesPlugin include='TestPage02*'}");
    Assert.assertTrue(res.contains("<table class=\"recentchanges\" cellpadding=\"4\">"));
    Assert.assertFalse(res.contains("<a href=\"/test/Wiki.jsp?page=TestPage01\">Test Page 01</a>"));
    Assert.assertTrue(res.contains("<a href=\"/test/Wiki.jsp?page=TestPage02\">Test Page 02</a>"));
    Assert.assertFalse(res.contains("<a href=\"/test/Wiki.jsp?page=TestPage03\">Test Page 03</a>"));
}
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