Search in sources :

Example 36 with Context

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

the class PageRenamerTest method testAttachmentChange.

@Test
public void testAttachmentChange() throws Exception {
    m_engine.saveText("TestPage", "foofoo");
    m_engine.saveText("TestPage2", "[TestPage/foo.txt] [linktext|TestPage/bar.jpg]");
    m_engine.addAttachment("TestPage", "foo.txt", "testing".getBytes());
    m_engine.addAttachment("TestPage", "bar.jpg", "pr0n".getBytes());
    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/foo.txt] [linktext|FooTest/bar.jpg]", data.trim(), "no rename");
    Attachment att = m_engine.getManager(AttachmentManager.class).getAttachmentInfo("FooTest/foo.txt");
    Assertions.assertNotNull(att, "footext");
    att = m_engine.getManager(AttachmentManager.class).getAttachmentInfo("FooTest/bar.jpg");
    Assertions.assertNotNull(att, "barjpg");
    att = m_engine.getManager(AttachmentManager.class).getAttachmentInfo("TestPage/bar.jpg");
    Assertions.assertNull(att, "testpage/bar.jpg exists");
    att = m_engine.getManager(AttachmentManager.class).getAttachmentInfo("TestPage/foo.txt");
    Assertions.assertNull(att, "testpage/foo.txt exists");
    Collection<String> refs = m_engine.getManager(ReferenceManager.class).findReferrers("TestPage/bar.jpg");
    Assertions.assertNull(refs, "oldpage");
    refs = m_engine.getManager(ReferenceManager.class).findReferrers("FooTest/bar.jpg");
    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) Attachment(org.apache.wiki.api.core.Attachment) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) ReferenceManager(org.apache.wiki.references.ReferenceManager) Test(org.junit.jupiter.api.Test)

Example 37 with Context

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

the class PageRenamerTest method testReferrerChange.

@Test
public void testReferrerChange() throws Exception {
    m_engine.saveText("TestPage", "foofoo");
    m_engine.saveText("TestPage2", "[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);
    final String data = m_engine.getManager(PageManager.class).getPureText("TestPage2", WikiProvider.LATEST_VERSION);
    Assertions.assertEquals("[FooTest]", 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 38 with Context

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

the class PageRenamerTest method rename.

private void rename(final String src, final String dst) throws WikiException {
    final Page p = m_engine.getManager(PageManager.class).getPage(src);
    final Context context = Wiki.context().create(m_engine, p);
    m_engine.getManager(PageRenamer.class).renamePage(context, src, dst, true);
}
Also used : Context(org.apache.wiki.api.core.Context) PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page)

Example 39 with Context

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

the class PageRenamerTest method testReferrerChangeMultiRename.

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

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

the class ContextualDiffProviderTest method diffTest.

// FIXME: This test Assertions.fails; must be enabled again asap.
/*
    @Test
    public void testKnownProblemCases() throws NoRequiredPropertyException, IOException
    {
        //These all Assertions.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 Assertions.failures are all due to how we process the diff results, we need to collapse
        //adjacent edits into one...

    }
     */
private void diffTest(final String contextLimit, final String oldText, final String newText, final String expectedDiff) throws IOException, WikiException {
    final ContextualDiffProvider diff = new ContextualDiffProvider();
    specializedNotation(diff);
    final Properties props = TestEngine.getTestProperties();
    if (null != contextLimit) {
        props.put(ContextualDiffProvider.PROP_UNCHANGED_CONTEXT_LIMIT, contextLimit);
    }
    diff.initialize(null, props);
    final TestEngine engine = new TestEngine(props);
    final Context ctx = Wiki.context().create(engine, Wiki.contents().page(engine, "Dummy"));
    final String actualDiff = diff.makeDiffHtml(ctx, oldText, newText);
    Assertions.assertEquals(expectedDiff, actualDiff);
}
Also used : Context(org.apache.wiki.api.core.Context) TestEngine(org.apache.wiki.TestEngine) Properties(java.util.Properties)

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