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();
}
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);
}
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"));
}
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();
}
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());
}
Aggregations