Search in sources :

Example 1 with MoveRequest

use of org.xwiki.refactoring.job.MoveRequest in project xwiki-platform by xwiki.

the class MoveJobTest method moveDocumentToSpaceHome.

@Test
public void moveDocumentToSpaceHome() throws Throwable {
    DocumentReference source = new DocumentReference("wiki", "A", "B");
    when(this.modelBridge.exists(source)).thenReturn(true);
    DocumentReference destination = new DocumentReference("wiki", "C", "WebHome");
    MoveRequest request = createRequest(source, destination);
    request.setCheckRights(false);
    run(request);
    verify(this.modelBridge).copy(source, new DocumentReference("wiki", "C", "B"));
}
Also used : MoveRequest(org.xwiki.refactoring.job.MoveRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 2 with MoveRequest

use of org.xwiki.refactoring.job.MoveRequest 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 3 with MoveRequest

use of org.xwiki.refactoring.job.MoveRequest 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 4 with MoveRequest

use of org.xwiki.refactoring.job.MoveRequest in project xwiki-platform by xwiki.

the class MoveJobTest method moveSpaceToSpaceHome.

@Test
public void moveSpaceToSpaceHome() throws Throwable {
    SpaceReference sourceSpace = new SpaceReference("wiki", "A", "B");
    DocumentReference sourceDoc = new DocumentReference("X", sourceSpace);
    when(this.modelBridge.getDocumentReferences(sourceSpace)).thenReturn(Arrays.asList(sourceDoc));
    when(this.modelBridge.exists(sourceDoc)).thenReturn(true);
    DocumentReference destination = new DocumentReference("wiki", "C", "WebHome");
    MoveRequest request = createRequest(sourceSpace, destination);
    request.setCheckRights(false);
    run(request);
    verify(this.modelBridge).copy(sourceDoc, new DocumentReference("wiki", Arrays.asList("C", "B"), "X"));
}
Also used : MoveRequest(org.xwiki.refactoring.job.MoveRequest) SpaceReference(org.xwiki.model.reference.SpaceReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 5 with MoveRequest

use of org.xwiki.refactoring.job.MoveRequest in project xwiki-platform by xwiki.

the class RenameJobTest method convertNotTerminalDocumentToTerminalDocumentPreservingChildren.

@Test
public void convertNotTerminalDocumentToTerminalDocumentPreservingChildren() throws Throwable {
    DocumentReference nonTerminalReference = new DocumentReference("wiki", "One", "WebHome");
    DocumentReference terminalReference = new DocumentReference("wiki", "Zero", "One");
    MoveRequest request = createRequest(nonTerminalReference, terminalReference);
    request.setDeep(true);
    run(request);
    verifyNoMove();
    verify(this.mocker.getMockedLogger()).error("You cannot transform a non-terminal document [{}] into a terminal document [{}]" + " and preserve its child documents at the same time.", nonTerminalReference, terminalReference);
}
Also used : MoveRequest(org.xwiki.refactoring.job.MoveRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

MoveRequest (org.xwiki.refactoring.job.MoveRequest)25 Test (org.junit.Test)21 DocumentReference (org.xwiki.model.reference.DocumentReference)16 SpaceReference (org.xwiki.model.reference.SpaceReference)6 WikiReference (org.xwiki.model.reference.WikiReference)6 LinkRefactoring (org.xwiki.refactoring.internal.LinkRefactoring)3 GroupedJob (org.xwiki.job.GroupedJob)1 Job (org.xwiki.job.Job)1 JobException (org.xwiki.job.JobException)1 ContextualAuthorizationManager (org.xwiki.security.authorization.ContextualAuthorizationManager)1 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)1