Search in sources :

Example 1 with LinkRefactoring

use of org.xwiki.refactoring.internal.LinkRefactoring in project xwiki-platform by xwiki.

the class MoveJobTest method updateLinksOnFarm.

@Test
public void updateLinksOnFarm() throws Throwable {
    DocumentReference oldReference = new DocumentReference("foo", "One", "Page");
    when(this.modelBridge.exists(oldReference)).thenReturn(true);
    DocumentReference newReference = new DocumentReference("foo", "Two", "Page");
    when(this.modelBridge.exists(newReference)).thenReturn(false);
    when(this.modelBridge.copy(oldReference, newReference)).thenReturn(true);
    WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getAllIds()).thenReturn(Arrays.asList("foo", "bar"));
    DocumentReference aliceReference = new DocumentReference("foo", "Alice", "BackLink");
    when(this.modelBridge.getBackLinkedReferences(oldReference, "foo")).thenReturn(Arrays.asList(aliceReference));
    DocumentReference bobReference = new DocumentReference("bar", "Bob", "BackLink");
    when(this.modelBridge.getBackLinkedReferences(oldReference, "bar")).thenReturn(Arrays.asList(bobReference));
    MoveRequest request = createRequest(oldReference, newReference.getParent());
    request.setCheckRights(false);
    request.setInteractive(false);
    request.setUpdateLinksOnFarm(true);
    GroupedJob job = (GroupedJob) run(request);
    assertEquals(RefactoringJobs.GROUP, job.getGroupPath().toString());
    LinkRefactoring linkRefactoring = getMocker().getInstance(LinkRefactoring.class);
    verify(linkRefactoring).renameLinks(aliceReference, oldReference, newReference);
    verify(linkRefactoring).renameLinks(bobReference, oldReference, newReference);
}
Also used : GroupedJob(org.xwiki.job.GroupedJob) LinkRefactoring(org.xwiki.refactoring.internal.LinkRefactoring) MoveRequest(org.xwiki.refactoring.job.MoveRequest) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 2 with LinkRefactoring

use of org.xwiki.refactoring.internal.LinkRefactoring in project xwiki-platform by xwiki.

the class MoveJobTest method copyDocument.

@Test
public void copyDocument() throws Throwable {
    DocumentReference sourceReference = new DocumentReference("wiki", "Space", "Page");
    when(this.modelBridge.exists(sourceReference)).thenReturn(true);
    DocumentReference copyReference = new DocumentReference("wiki", "Copy", "Page");
    when(this.modelBridge.copy(sourceReference, copyReference)).thenReturn(true);
    MoveRequest request = createRequest(sourceReference, copyReference.getParent());
    request.setCheckRights(false);
    request.setInteractive(false);
    request.setDeleteSource(false);
    Map<String, String> parameters = Collections.singletonMap("foo", "bar");
    request.setEntityParameters(sourceReference, parameters);
    run(request);
    verify(this.modelBridge).update(copyReference, parameters);
    LinkRefactoring linkRefactoring = getMocker().getInstance(LinkRefactoring.class);
    verify(linkRefactoring, never()).renameLinks(any(DocumentReference.class), any(DocumentReference.class), any(DocumentReference.class));
    verify(linkRefactoring).updateRelativeLinks(sourceReference, copyReference);
    verify(this.modelBridge, never()).delete(any(DocumentReference.class));
    verify(this.modelBridge, never()).createRedirect(any(DocumentReference.class), any(DocumentReference.class));
}
Also used : LinkRefactoring(org.xwiki.refactoring.internal.LinkRefactoring) MoveRequest(org.xwiki.refactoring.job.MoveRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 3 with LinkRefactoring

use of org.xwiki.refactoring.internal.LinkRefactoring in project xwiki-platform by xwiki.

the class MoveJobTest method moveDocumentToSpace.

@Test
public void moveDocumentToSpace() throws Throwable {
    DocumentReference oldReference = new DocumentReference("wiki", "One", "Page");
    when(this.modelBridge.exists(oldReference)).thenReturn(true);
    DocumentReference backLinkReference = new DocumentReference("wiki", "Three", "BackLink");
    when(this.modelBridge.getBackLinkedReferences(oldReference, "wiki")).thenReturn(Arrays.asList(backLinkReference));
    DocumentReference newReference = new DocumentReference("wiki", "Two", "Page");
    when(this.modelBridge.exists(newReference)).thenReturn(true);
    DocumentReference userReference = new DocumentReference("wiki", "Users", "Alice");
    when(this.modelBridge.delete(newReference)).thenReturn(true);
    when(this.modelBridge.copy(oldReference, newReference)).thenReturn(true);
    MoveRequest request = createRequest(oldReference, newReference.getParent());
    request.setCheckRights(false);
    request.setInteractive(false);
    request.setUserReference(userReference);
    run(request);
    LinkRefactoring linkRefactoring = getMocker().getInstance(LinkRefactoring.class);
    verify(linkRefactoring).renameLinks(backLinkReference, oldReference, newReference);
    verify(linkRefactoring).updateRelativeLinks(oldReference, newReference);
    verify(this.modelBridge).setContextUserReference(userReference);
    verify(this.modelBridge).delete(oldReference);
    verify(this.modelBridge).createRedirect(oldReference, newReference);
}
Also used : LinkRefactoring(org.xwiki.refactoring.internal.LinkRefactoring) MoveRequest(org.xwiki.refactoring.job.MoveRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 LinkRefactoring (org.xwiki.refactoring.internal.LinkRefactoring)3 MoveRequest (org.xwiki.refactoring.job.MoveRequest)3 GroupedJob (org.xwiki.job.GroupedJob)1 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)1