Search in sources :

Example 11 with MoveRequest

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

the class MoveJobTest method moveDocumentWithoutDeleteRight.

@Test
public void moveDocumentWithoutDeleteRight() throws Throwable {
    DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
    when(this.modelBridge.exists(documentReference)).thenReturn(true);
    DocumentReference userReference = new DocumentReference("wiki", "Users", "Alice");
    when(this.authorization.hasAccess(Right.DELETE, userReference, documentReference)).thenReturn(false);
    MoveRequest request = createRequest(documentReference, new SpaceReference("Foo", new WikiReference("bar")));
    request.setCheckRights(true);
    request.setUserReference(userReference);
    run(request);
    verify(this.mocker.getMockedLogger()).error("You are not allowed to delete [{}].", documentReference);
    verifyNoMove();
}
Also used : MoveRequest(org.xwiki.refactoring.job.MoveRequest) SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 12 with MoveRequest

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

Example 13 with MoveRequest

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

the class MoveJobTest method moveSpaceHomeDeep.

@Test
public void moveSpaceHomeDeep() throws Throwable {
    DocumentReference spaceHome = new DocumentReference("chess", Arrays.asList("A", "B", "C"), "WebHome");
    DocumentReference docFromSpace = new DocumentReference("X", spaceHome.getLastSpaceReference());
    when(this.modelBridge.getDocumentReferences(spaceHome.getLastSpaceReference())).thenReturn(Arrays.asList(docFromSpace));
    when(this.modelBridge.exists(docFromSpace)).thenReturn(true);
    WikiReference newWiki = new WikiReference("tennis");
    MoveRequest request = createRequest(spaceHome, newWiki);
    request.setCheckRights(false);
    request.setDeep(true);
    run(request);
    verify(this.modelBridge).copy(docFromSpace, new DocumentReference("tennis", "C", "X"));
}
Also used : MoveRequest(org.xwiki.refactoring.job.MoveRequest) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 14 with MoveRequest

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

the class MoveJobTest method moveDocumentToRestrictedDestination.

@Test
public void moveDocumentToRestrictedDestination() throws Throwable {
    DocumentReference oldReference = new DocumentReference("wiki", "One", "Page");
    DocumentReference newReference = new DocumentReference("wiki", "Two", "Page");
    when(this.modelBridge.exists(oldReference)).thenReturn(true);
    DocumentReference userReference = new DocumentReference("wiki", "Users", "Alice");
    when(this.authorization.hasAccess(Right.DELETE, userReference, oldReference)).thenReturn(true);
    when(this.authorization.hasAccess(Right.VIEW, userReference, newReference)).thenReturn(false);
    MoveRequest request = createRequest(oldReference, newReference.getParent());
    request.setCheckRights(true);
    request.setUserReference(userReference);
    run(request);
    verify(this.mocker.getMockedLogger()).error("You don't have sufficient permissions over the destination document [{}].", newReference);
    verifyNoMove();
}
Also used : MoveRequest(org.xwiki.refactoring.job.MoveRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 15 with MoveRequest

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

the class RenameJobTest method renameSpaceHomeDeep.

@Test
public void renameSpaceHomeDeep() throws Throwable {
    DocumentReference aliceReference = new DocumentReference("wiki", "Alice", "WebHome");
    DocumentReference bobReference = new DocumentReference("wiki", "Bob", "WebHome");
    MoveRequest request = createRequest(aliceReference, bobReference);
    request.setDeep(true);
    run(request);
    // We verify that job fetches the space children.
    verify(this.modelBridge, atLeastOnce()).getDocumentReferences(aliceReference.getLastSpaceReference());
}
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