Search in sources :

Example 36 with WikiContext

use of org.apache.wiki.WikiContext 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]");
    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]", 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 37 with WikiContext

use of org.apache.wiki.WikiContext 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());
    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/foo.txt] [linktext|FooTest/bar.jpg]", data.trim());
    Attachment att = m_engine.getAttachmentManager().getAttachmentInfo("FooTest/foo.txt");
    Assert.assertNotNull("footext", att);
    att = m_engine.getAttachmentManager().getAttachmentInfo("FooTest/bar.jpg");
    Assert.assertNotNull("barjpg", att);
    att = m_engine.getAttachmentManager().getAttachmentInfo("TestPage/bar.jpg");
    Assert.assertNull("testpage/bar.jpg exists", att);
    att = m_engine.getAttachmentManager().getAttachmentInfo("TestPage/foo.txt");
    Assert.assertNull("testpage/foo.txt exists", att);
    Collection<String> refs = m_engine.getReferenceManager().findReferrers("TestPage/bar.jpg");
    Assert.assertNull("oldpage", refs);
    refs = m_engine.getReferenceManager().findReferrers("FooTest/bar.jpg");
    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) Attachment(org.apache.wiki.attachment.Attachment) Test(org.junit.Test)

Example 38 with WikiContext

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

the class PageRenamerTest method testReferrerChangeCC.

@Test
public void testReferrerChangeCC() throws Exception {
    m_engine.saveText("TestPage", "foofoo");
    m_engine.saveText("TestPage2", "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", 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 39 with WikiContext

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

the class PageRenamerTest method rename.

private void rename(String src, String dst) throws WikiException {
    WikiPage p = m_engine.getPage(src);
    WikiContext context = new WikiContext(m_engine, p);
    m_engine.renamePage(context, src, dst, true);
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage)

Example 40 with WikiContext

use of org.apache.wiki.WikiContext 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)

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