@Test
  public void testRenameRenamedPage() throws Exception {
    WikiTestUtil.addPage(
        TestPropsValues.getUserId(), _group.getGroupId(), _node.getNodeId(), "A", true);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    WikiPageLocalServiceUtil.renamePage(
        TestPropsValues.getUserId(), _node.getNodeId(), "A", "B", true, serviceContext);

    WikiPageLocalServiceUtil.renamePage(
        TestPropsValues.getUserId(), _node.getNodeId(), "A", "C", true, serviceContext);

    WikiPage pageA = WikiPageLocalServiceUtil.getPage(_node.getNodeId(), "A");
    WikiPage pageB = WikiPageLocalServiceUtil.getPage(_node.getNodeId(), "B");
    WikiPage pageC = WikiPageLocalServiceUtil.getPage(_node.getNodeId(), "C");

    Assert.assertEquals("C", pageA.getRedirectTitle());
    Assert.assertEquals(StringPool.BLANK, pageB.getRedirectTitle());
    Assert.assertEquals(StringPool.BLANK, pageC.getRedirectTitle());
    Assert.assertEquals("Renamed as C", pageA.getSummary());
    Assert.assertEquals("Summary", pageB.getSummary());
    Assert.assertEquals(StringPool.BLANK, pageC.getSummary());
    Assert.assertEquals("[[C]]", pageA.getContent());
    Assert.assertEquals("[[B]]", pageC.getContent());
  }
  @Test
  public void testChangeRedirectPageNode() throws Exception {
    WikiNode destinationNode = WikiTestUtil.addNode(_group.getGroupId());

    WikiTestUtil.addPage(
        TestPropsValues.getUserId(),
        _group.getGroupId(),
        _node.getNodeId(),
        "InitialTitlePage",
        true);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    WikiPageLocalServiceUtil.renamePage(
        TestPropsValues.getUserId(),
        _node.getNodeId(),
        "InitialTitlePage",
        "RenamedPage",
        serviceContext);

    try {
      WikiPageLocalServiceUtil.changeNode(
          TestPropsValues.getUserId(),
          _node.getNodeId(),
          "InitialTitlePage",
          destinationNode.getNodeId(),
          serviceContext);

      Assert.fail();
    } catch (NodeChangeException nce) {
      Assert.assertEquals("InitialTitlePage", nce.getPageTitle());
      Assert.assertEquals(_node.getName(), nce.getNodeName());
      Assert.assertEquals(NodeChangeException.REDIRECT_PAGE, nce.getType());
    }
  }
  @Test
  public void testChangePageNodeWithRedirectPage() throws Exception {
    WikiNode destinationNode = WikiTestUtil.addNode(_group.getGroupId());

    WikiTestUtil.addPage(
        TestPropsValues.getUserId(),
        _group.getGroupId(),
        _node.getNodeId(),
        "InitialTitlePage",
        true);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    WikiPageLocalServiceUtil.renamePage(
        TestPropsValues.getUserId(),
        _node.getNodeId(),
        "InitialTitlePage",
        "RenamedPage",
        serviceContext);

    WikiPageLocalServiceUtil.changeNode(
        TestPropsValues.getUserId(),
        _node.getNodeId(),
        "RenamedPage",
        destinationNode.getNodeId(),
        serviceContext);

    WikiPage page = WikiPageLocalServiceUtil.getPage(destinationNode.getNodeId(), "RenamedPage");
    WikiPage redirectPage =
        WikiPageLocalServiceUtil.getPage(destinationNode.getNodeId(), "InitialTitlePage");

    Assert.assertEquals(destinationNode.getNodeId(), page.getNodeId());
    Assert.assertEquals(destinationNode.getNodeId(), redirectPage.getNodeId());
    Assert.assertEquals("RenamedPage", redirectPage.getRedirectTitle());
  }
  @Test(expected = DuplicatePageException.class)
  public void testRenamePageSameName() throws Exception {
    WikiPage page = WikiTestUtil.addPage(_group.getGroupId(), _node.getNodeId(), true);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    WikiPageLocalServiceUtil.renamePage(
        TestPropsValues.getUserId(),
        _node.getNodeId(),
        page.getTitle(),
        page.getTitle(),
        true,
        serviceContext);
  }
  protected void testRenamePage(boolean hasExpandoValues) throws Exception {
    WikiPage page = WikiTestUtil.addPage(_group.getGroupId(), _node.getNodeId(), true);

    if (hasExpandoValues) {
      addExpandoValueToPage(page);
    }

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    WikiPageLocalServiceUtil.renamePage(
        TestPropsValues.getUserId(),
        _node.getNodeId(),
        page.getTitle(),
        "New Title",
        true,
        serviceContext);

    WikiPage renamedPage = WikiPageLocalServiceUtil.getPage(_node.getNodeId(), "New Title");

    Assert.assertNotNull(renamedPage);

    checkPopulatedServiceContext(serviceContext, renamedPage, hasExpandoValues);
  }