Search in sources :

Example 86 with WikiPage

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

the class PageRenamerTest method testReferrerChangeMultilink.

@Test
public void testReferrerChangeMultilink() throws Exception {
    m_engine.saveText("TestPage", "foofoo");
    m_engine.saveText("TestPage2", "[TestPage] [TestPage] [linktext|TestPage] TestPage [linktext|TestPage] [TestPage#Anchor] [TestPage] TestPage [TestPage]");
    WikiPage p = m_engine.getPage("TestPage");
    WikiContext context = new WikiContext(m_engine, p);
    m_engine.renamePage(context, "TestPage", "FooTest", true);
    String data = m_engine.getPureText("TestPage2", WikiProvider.LATEST_VERSION);
    Assert.assertEquals("no rename", "[FooTest] [FooTest] [linktext|FooTest] FooTest [linktext|FooTest] [FooTest#Anchor] [FooTest] FooTest [FooTest]", data.trim());
    Collection<String> refs = m_engine.getReferenceManager().findReferrers("TestPage");
    Assert.assertNull("oldpage", refs);
    refs = m_engine.getReferenceManager().findReferrers("FooTest");
    Assert.assertEquals("new size", 1, refs.size());
    Assert.assertEquals("wrong ref", "TestPage2", (String) refs.iterator().next());
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 87 with WikiPage

use of org.apache.wiki.WikiPage 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 88 with WikiPage

use of org.apache.wiki.WikiPage 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 89 with WikiPage

use of org.apache.wiki.WikiPage 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 90 with WikiPage

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

the class CachingProviderTest method testSneakyAdd.

@Test
public void testSneakyAdd() throws Exception {
    Properties props = TestEngine.getTestProperties();
    props.setProperty("jspwiki.cachingProvider.cacheCheckInterval", "2");
    TestEngine engine = new TestEngine(props);
    String dir = props.getProperty(FileSystemProvider.PROP_PAGEDIR);
    File f = new File(dir, "Testi.txt");
    String content = "[fuufaa]";
    PrintWriter out = new PrintWriter(new FileWriter(f));
    FileUtil.copyContents(new StringReader(content), out);
    out.close();
    // Make sure we wait long enough
    Thread.sleep(4000L);
    WikiPage p = engine.getPage("Testi");
    Assert.assertNotNull("page did not exist?", p);
    String text = engine.getText("Testi");
    Assert.assertEquals("text", "[fuufaa]", text);
// TODO: ReferenceManager check as well
}
Also used : FileWriter(java.io.FileWriter) WikiPage(org.apache.wiki.WikiPage) StringReader(java.io.StringReader) TestEngine(org.apache.wiki.TestEngine) Properties(java.util.Properties) File(java.io.File) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

WikiPage (org.apache.wiki.WikiPage)186 Test (org.junit.Test)77 WikiContext (org.apache.wiki.WikiContext)63 WikiEngine (org.apache.wiki.WikiEngine)29 Attachment (org.apache.wiki.attachment.Attachment)26 ProviderException (org.apache.wiki.api.exceptions.ProviderException)22 Date (java.util.Date)17 File (java.io.File)16 Collection (java.util.Collection)16 TestEngine (org.apache.wiki.TestEngine)15 Iterator (java.util.Iterator)13 StringReader (java.io.StringReader)9 Hashtable (java.util.Hashtable)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 Calendar (java.util.Calendar)8 Vector (java.util.Vector)8 StringWriter (java.io.StringWriter)7 InternalWikiException (org.apache.wiki.InternalWikiException)7 PagePermission (org.apache.wiki.auth.permissions.PagePermission)7