Search in sources :

Example 41 with WikiContext

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

the class ContextualDiffProviderTest method diffTest.

// FIXME: This test Assert.fails; must be enabled again asap.
/*
    @Test
    public void testKnownProblemCases() throws NoRequiredPropertyException, IOException
    {
        //These all Assert.fail...

        //make two consequtive changes
        diffTest(null, "A B C D", "A b c D", "A |^b c^-B C-| D");
        //acually returns ->                 "A |^b^-B-| |^c^-C-| D"

        //collapse adjacent elements...
        diffTest(null, "A B C D", "A BC D", "A |^BC^-B C-| D");
        //acually returns ->                "A |^BC^-B-| |-C -|D"


        //These Assert.failures are all due to how we process the diff results, we need to collapse
        //adjacent edits into one...

    }
     */
private void diffTest(String contextLimit, String oldText, String newText, String expectedDiff) throws IOException, WikiException {
    ContextualDiffProvider diff = new ContextualDiffProvider();
    specializedNotation(diff);
    Properties props = TestEngine.getTestProperties();
    if (null != contextLimit)
        props.put(ContextualDiffProvider.PROP_UNCHANGED_CONTEXT_LIMIT, contextLimit);
    diff.initialize(null, props);
    PropertyConfigurator.configure(props);
    TestEngine engine = new TestEngine(props);
    WikiContext ctx = new WikiContext(engine, new WikiPage(engine, "Dummy"));
    String actualDiff = diff.makeDiffHtml(ctx, oldText, newText);
    Assert.assertEquals(expectedDiff, actualDiff);
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) TestEngine(org.apache.wiki.TestEngine) Properties(java.util.Properties)

Example 42 with WikiContext

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

the class TableOfContentsTest method getI18nHTML.

/**
 * TableOfContents plugin produces some i18n text, so we enforce english locale in order to
 * be able to compare properly to assertion texts.
 *
 * @param pagename name of the page.
 * @return (english) contents corresponding to the given page name.
 */
String getI18nHTML(String pagename) {
    WikiPage page = testEngine.getPage(pagename, WikiPageProvider.LATEST_VERSION);
    WikiContext context = new WikiContext(testEngine, testEngine.newHttpRequest(), page);
    context.setRequestContext(WikiContext.NONE);
    return testEngine.getHTML(context, page);
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage)

Example 43 with WikiContext

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

the class UndefinedPagesPluginTest method setUp.

@Before
public void setUp() throws Exception {
    CacheManager.getInstance().removeAllCaches();
    testEngine = new TestEngine(props);
    testEngine.saveText("TestPage", "Reference to [Foobar].");
    testEngine.saveText("Foobar", "Reference to [Foobar 2], [Foobars]");
    context = new WikiContext(testEngine, new WikiPage(testEngine, "TestPage"));
    manager = new DefaultPluginManager(testEngine, props);
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) TestEngine(org.apache.wiki.TestEngine) Before(org.junit.Before)

Example 44 with WikiContext

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

the class VersioningFileProviderTest method testChangeNote.

@Test
public void testChangeNote() throws Exception {
    WikiPage p = new WikiPage(engine, NAME1);
    p.setAttribute(WikiPage.CHANGENOTE, "Test change");
    WikiContext context = new WikiContext(engine, p);
    engine.saveText(context, "test");
    WikiPage p2 = engine.getPage(NAME1);
    Assert.assertEquals("Test change", p2.getAttribute(WikiPage.CHANGENOTE));
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 45 with WikiContext

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

the class VersioningFileProviderTest method testChangeNoteOldVersion.

@Test
public void testChangeNoteOldVersion() 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");
    context.getPage().setAttribute(WikiPage.CHANGENOTE, "Change 2");
    engine.saveText(context, "test2");
    WikiPage p2 = engine.getPage(NAME1, 1);
    Assert.assertEquals("Test change", p2.getAttribute(WikiPage.CHANGENOTE));
    WikiPage p3 = engine.getPage(NAME1, 2);
    Assert.assertEquals("Change 2", p3.getAttribute(WikiPage.CHANGENOTE));
}
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