public void testRenamePage() throws Exception
{
String pageName = String.format("%s-%d", TestConstants.TEST_PREFIX, Math.abs(this.random.nextInt()));
String pageId = String.format("%s.%s", TestConstants.TEST_SPACE, pageName);
String content = String.format("Modified by org.xwiki.xmlrpc @ %s (inital version)\n", new Date());
XWikiPage page = null;
TestUtils.banner("TEST: renamePage()");
page = new XWikiPage();
page.setId(pageId);
page.setContent(content);
page = this.rpc.storePage(page);
page.setSpace("Foo");
page.setTitle("Bar");
XWikiPage renamedPage = this.rpc.storePage(page);
try {
this.rpc.getPage(pageId);
fail("This page should no longer exist");
} catch (Exception e) {
// Ignore
}
assertTrue(renamedPage.getId().equals("Foo.Bar"));
assertTrue(renamedPage.getContent().equals(content));
/* Test other cases as well */
page = new XWikiPage();
page.setId(pageId);
page.setContent(content);
page = this.rpc.storePage(page);
page.setSpace("TargetSpace");
renamedPage = this.rpc.storePage(page);
try {
this.rpc.getPage(pageId);
fail("This page should no longer exist");
} catch (Exception e) {
// Ignore
}
assertTrue(renamedPage.getId().equals(String.format("TargetSpace.%s", pageName)));
assertTrue(renamedPage.getContent().equals(content));
/*-*/
page = new XWikiPage();
page.setId(pageId);
page.setContent(content);
page = this.rpc.storePage(page);
page.setTitle("Foo");
renamedPage = this.rpc.storePage(page);
try {
this.rpc.getPage(pageId);
fail("This page should no longer exist");
} catch (Exception e) {
// Ignore
}
assertTrue(renamedPage.getId().equals(String.format("%s.Foo", TestConstants.TEST_SPACE)));
assertTrue(renamedPage.getContent().equals(content));
}