@Test void updateRelativeLinksAcrossWikis() throws Exception { DocumentReference oldReference = new DocumentReference("wiki1", "A", "B"); DocumentReference newReference = new DocumentReference("wiki2", "X", "Y"); XWikiDocument newDocument = mock(XWikiDocument.class); when(this.xcontext.getWiki().getDocument(newReference, this.xcontext)).thenReturn(newDocument); when(newDocument.getDocumentReference()).thenReturn(newReference); when(newDocument.getSyntax()).thenReturn(Syntax.XWIKI_2_1); XDOM xdom = mock(XDOM.class); when(newDocument.getXDOM()).thenReturn(xdom); ResourceReference docLinkReference = new ResourceReference("C", ResourceType.DOCUMENT); LinkBlock docLinkBlock = new LinkBlock(Collections.emptyList(), docLinkReference, false); ResourceReference spaceLinkReference = new ResourceReference("Z", ResourceType.SPACE); LinkBlock spaceLinkBlock = new LinkBlock(Collections.emptyList(), spaceLinkReference, false); when(xdom.getBlocks(any(), eq(Block.Axes.DESCENDANT))) .thenReturn(Arrays.asList(docLinkBlock, spaceLinkBlock)); DocumentReference originalDocLinkReference = new DocumentReference("C", oldReference.getLastSpaceReference()); when(this.resourceReferenceResolver.resolve(docLinkReference, null, oldReference)) .thenReturn(originalDocLinkReference); DocumentReference newDocLinkReference = new DocumentReference("C", newReference.getLastSpaceReference()); when(this.resourceReferenceResolver.resolve(docLinkReference, null, newReference)) .thenReturn(newDocLinkReference); SpaceReference originalSpaceReference = new SpaceReference("wiki1", "Z"); when(this.resourceReferenceResolver.resolve(spaceLinkReference, null, oldReference)) .thenReturn(originalSpaceReference); SpaceReference newSpaceReference = new SpaceReference("wiki2", "Z"); when(this.resourceReferenceResolver.resolve(spaceLinkReference, null, newReference)) .thenReturn(newSpaceReference); when(this.compactEntityReferenceSerializer.serialize(originalDocLinkReference, newReference)) .thenReturn("wiki1:A.C"); when(this.compactEntityReferenceSerializer.serialize(originalSpaceReference, newReference)) .thenReturn("wiki1:Z"); this.refactoring.updateRelativeLinks(oldReference, newReference); assertEquals("wiki1:A.C", docLinkBlock.getReference().getReference()); assertEquals(ResourceType.DOCUMENT, docLinkBlock.getReference().getType()); assertEquals("wiki1:Z", spaceLinkBlock.getReference().getReference()); assertEquals(ResourceType.SPACE, spaceLinkBlock.getReference().getType()); verifyDocumentSave(newDocument, "Updated the relative links.", true, true); }
@Override public void updateRelativeLinks(DocumentReference oldReference, DocumentReference newReference) { XWikiContext xcontext = this.xcontextProvider.get(); try { XWikiDocument document = xcontext.getWiki().getDocument(newReference, xcontext); renameLinks(document, oldReference, document.getDocumentReference(), xcontext, true); } catch (XWikiException e) { this.logger.error("Failed to update the relative links from [{}].", newReference, e); } }
DefaultLinkRefactoring implements LinkRefactoring { @Override public void updateRelativeLinks(DocumentReference oldReference, DocumentReference newReference) { XWikiContext xcontext = this.xcontextProvider.get(); try { XWikiDocument document = xcontext.getWiki().getDocument(newReference, xcontext); renameLinks(document, oldReference, document.getDocumentReference(), xcontext, true); } catch (XWikiException e) { this.logger.error("Failed to update the relative links from [{}].", newReference, e); } } }
DefaultLinkRefactoring implements LinkRefactoring { @Override public void updateRelativeLinks(DocumentReference oldReference, DocumentReference newReference) { XWikiContext xcontext = this.xcontextProvider.get(); try { XWikiDocument document = xcontext.getWiki().getDocument(newReference, xcontext); renameLinks(document, oldReference, document.getDocumentReference(), xcontext, true); } catch (XWikiException e) { this.logger.error("Failed to update the relative links from [{}].", newReference, e); } }  }
DefaultLinkRefactoring implements LinkRefactoring { @Override public void updateRelativeLinks(DocumentReference oldReference, DocumentReference newReference) { XWikiContext xcontext = this.xcontextProvider.get(); try { XWikiDocument document = xcontext.getWiki().getDocument(newReference, xcontext); renameLinks(document, oldReference, document.getDocumentReference(), xcontext, true); } catch (XWikiException e) { this.logger.error("Failed to update the relative links from [{}].", newReference, e); } }  @Override void renameLinks(DocumentReference documentReference, DocumentReference oldLinkTarget,
        DocumentReference newLinkTarget); @Override void updateRelativeLinks(DocumentReference oldReference, DocumentReference newReference); }
DefaultLinkRefactoring implements LinkRefactoring { @Override public void updateRelativeLinks(DocumentReference oldReference, DocumentReference newReference) { XWikiContext xcontext = this.xcontextProvider.get(); try { XWikiDocument document = xcontext.getWiki().getDocument(newReference, xcontext); renameLinks(document, oldReference, document.getDocumentReference(), xcontext, true); } catch (XWikiException e) { this.logger.error("Failed to update the relative links from [{}].", newReference, e); } }  @Override void renameLinks(DocumentReference documentReference, DocumentReference oldLinkTarget,
        DocumentReference newLinkTarget); @Override void updateRelativeLinks(DocumentReference oldReference, DocumentReference newReference);  }