@Test void renameLinksFromLinksAndMacros() throws Exception { DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page"); XWikiDocument document = mock(XWikiDocument.class); when(this.xcontext.getWiki().getDocument(documentReference, this.xcontext)).thenReturn(document); when(document.getDocumentReference()).thenReturn(documentReference); when(document.getSyntax()).thenReturn(Syntax.XWIKI_2_1); DocumentReference oldLinkTarget = new DocumentReference("wiki", "A", "B"); DocumentReference newLinkTarget = new DocumentReference("wiki", "X", "Y"); XDOM xdom = mock(XDOM.class); when(document.getXDOM()).thenReturn(xdom); Map<String, String> includeParameters = new HashMap<String, String>(); includeParameters.put("reference", "A.B"); MacroBlock includeMacroBlock = new MacroBlock("include", includeParameters, false); ResourceReference resourceReference = new ResourceReference("A.B", ResourceType.DOCUMENT); LinkBlock documentLinkBlock = new LinkBlock(Collections.emptyList(), resourceReference, false); when(xdom.getBlocks(any(), eq(Block.Axes.DESCENDANT))) .thenReturn(Arrays.asList(includeMacroBlock, documentLinkBlock)); when(this.resourceReferenceResolver.resolve(resourceReference, null, documentReference)) .thenReturn(oldLinkTarget); when(this.defaultReferenceDocumentReferenceResolver.resolve(oldLinkTarget)).thenReturn(oldLinkTarget); when(this.compactEntityReferenceSerializer.serialize(newLinkTarget, documentReference)).thenReturn("X.Y"); this.refactoring.renameLinks(documentReference, oldLinkTarget, newLinkTarget); assertEquals("X.Y", includeMacroBlock.getParameter("reference")); assertEquals("X.Y", documentLinkBlock.getReference().getReference()); assertEquals(ResourceType.DOCUMENT, documentLinkBlock.getReference().getType()); verifyDocumentSave(document, "Renamed back-links.", false, false); }
@Override public void renameLinks(DocumentReference documentReference, DocumentReference oldLinkTarget, DocumentReference newLinkTarget) { boolean popLevelProgress = false; XWikiContext xcontext = this.xcontextProvider.get(); String previousWikiId = xcontext.getWikiId(); try { xcontext.setWikiId(documentReference.getWikiReference().getName()); XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext); List<Locale> locales = document.getTranslationLocales(xcontext); this.progressManager.pushLevelProgress(1 + locales.size(), this); popLevelProgress = true; this.progressManager.startStep(this); renameLinks(document, oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); for (Locale locale : locales) { this.progressManager.startStep(this); renameLinks(document.getTranslatedDocument(locale, xcontext), oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); } } catch (XWikiException e) { this.logger.error("Failed to rename the links that target [{}] from [{}].", oldLinkTarget, documentReference, e); } finally { if (popLevelProgress) { this.progressManager.popLevelProgress(this); } xcontext.setWikiId(previousWikiId); } }
DefaultLinkRefactoring implements LinkRefactoring { @Override public void renameLinks(DocumentReference documentReference, DocumentReference oldLinkTarget, DocumentReference newLinkTarget) { boolean popLevelProgress = false; XWikiContext xcontext = this.xcontextProvider.get(); String previousWikiId = xcontext.getWikiId(); try { xcontext.setWikiId(documentReference.getWikiReference().getName()); XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext); List<Locale> locales = document.getTranslationLocales(xcontext); this.progressManager.pushLevelProgress(1 + locales.size(), this); popLevelProgress = true; this.progressManager.startStep(this); renameLinks(document, oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); for (Locale locale : locales) { this.progressManager.startStep(this); renameLinks(document.getTranslatedDocument(locale, xcontext), oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); } } catch (XWikiException e) { this.logger.error("Failed to rename the links that target [{}] from [{}].", oldLinkTarget, documentReference, e); } finally { if (popLevelProgress) { this.progressManager.popLevelProgress(this); } xcontext.setWikiId(previousWikiId); } } }
DefaultLinkRefactoring implements LinkRefactoring { @Override public void renameLinks(DocumentReference documentReference, DocumentReference oldLinkTarget, DocumentReference newLinkTarget) { boolean popLevelProgress = false; XWikiContext xcontext = this.xcontextProvider.get(); String previousWikiId = xcontext.getWikiId(); try { xcontext.setWikiId(documentReference.getWikiReference().getName()); XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext); List<Locale> locales = document.getTranslationLocales(xcontext); this.progressManager.pushLevelProgress(1 + locales.size(), this); popLevelProgress = true; this.progressManager.startStep(this); renameLinks(document, oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); for (Locale locale : locales) { this.progressManager.startStep(this); renameLinks(document.getTranslatedDocument(locale, xcontext), oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); } } catch (XWikiException e) { this.logger.error("Failed to rename the links that target [{}] from [{}].", oldLinkTarget, documentReference, e); } finally { if (popLevelProgress) { this.progressManager.popLevelProgress(this); } xcontext.setWikiId(previousWikiId); } }  }
DefaultLinkRefactoring implements LinkRefactoring { @Override public void renameLinks(DocumentReference documentReference, DocumentReference oldLinkTarget, DocumentReference newLinkTarget) { boolean popLevelProgress = false; XWikiContext xcontext = this.xcontextProvider.get(); String previousWikiId = xcontext.getWikiId(); try { xcontext.setWikiId(documentReference.getWikiReference().getName()); XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext); List<Locale> locales = document.getTranslationLocales(xcontext); this.progressManager.pushLevelProgress(1 + locales.size(), this); popLevelProgress = true; this.progressManager.startStep(this); renameLinks(document, oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); for (Locale locale : locales) { this.progressManager.startStep(this); renameLinks(document.getTranslatedDocument(locale, xcontext), oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); } } catch (XWikiException e) { this.logger.error("Failed to rename the links that target [{}] from [{}].", oldLinkTarget, documentReference, e); } finally { if (popLevelProgress) { this.progressManager.popLevelProgress(this); } xcontext.setWikiId(previousWikiId); } }  @Override void renameLinks(DocumentReference documentReference, DocumentReference oldLinkTarget,
        DocumentReference newLinkTarget); @Override void updateRelativeLinks(DocumentReference oldReference, DocumentReference newReference); }
DefaultLinkRefactoring implements LinkRefactoring { @Override public void renameLinks(DocumentReference documentReference, DocumentReference oldLinkTarget, DocumentReference newLinkTarget) { boolean popLevelProgress = false; XWikiContext xcontext = this.xcontextProvider.get(); String previousWikiId = xcontext.getWikiId(); try { xcontext.setWikiId(documentReference.getWikiReference().getName()); XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext); List<Locale> locales = document.getTranslationLocales(xcontext); this.progressManager.pushLevelProgress(1 + locales.size(), this); popLevelProgress = true; this.progressManager.startStep(this); renameLinks(document, oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); for (Locale locale : locales) { this.progressManager.startStep(this); renameLinks(document.getTranslatedDocument(locale, xcontext), oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); } } catch (XWikiException e) { this.logger.error("Failed to rename the links that target [{}] from [{}].", oldLinkTarget, documentReference, e); } finally { if (popLevelProgress) { this.progressManager.popLevelProgress(this); } xcontext.setWikiId(previousWikiId); } }  @Override void renameLinks(DocumentReference documentReference, DocumentReference oldLinkTarget,
        DocumentReference newLinkTarget); @Override void updateRelativeLinks(DocumentReference oldReference, DocumentReference newReference);  }