Search in sources :

Example 6 with MoveRequest

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

the class RefactoringScriptServiceTest method moveWithoutPR.

@Test
public void moveWithoutPR() throws Exception {
    MoveRequest request = new MoveRequest();
    request.setCheckRights(false);
    request.setUserReference(new DocumentReference("wiki", "Users", "Bob"));
    getService().move(request);
    assertTrue(request.isCheckRights());
    assertEquals(this.userReference, request.getUserReference());
}
Also used : MoveRequest(org.xwiki.refactoring.job.MoveRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 7 with MoveRequest

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

the class RefactoringScriptServiceTest method convertToNestedDocument.

@Test
public void convertToNestedDocument() throws Exception {
    DocumentReference terminalDocumentReference = new DocumentReference("code", "Model", "Entity");
    DocumentReference nestedDocumentReference = new DocumentReference("code", Arrays.asList("Model", "Entity"), "WebHome");
    getService().convertToNestedDocument(terminalDocumentReference);
    ArgumentCaptor<MoveRequest> request = ArgumentCaptor.forClass(MoveRequest.class);
    verify(this.jobExecutor).execute(eq(RefactoringJobs.RENAME), request.capture());
    assertEquals(Arrays.asList(terminalDocumentReference), request.getValue().getEntityReferences());
    assertEquals(nestedDocumentReference, request.getValue().getDestination());
    assertNull(getService().convertToNestedDocument(nestedDocumentReference));
}
Also used : MoveRequest(org.xwiki.refactoring.job.MoveRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 8 with MoveRequest

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

the class RefactoringScriptServiceTest method moveWithPR.

@Test
public void moveWithPR() throws Exception {
    MoveRequest request = new MoveRequest();
    request.setCheckRights(false);
    DocumentReference bobReference = new DocumentReference("wiki", "Users", "Bob");
    request.setUserReference(bobReference);
    ContextualAuthorizationManager authorization = this.mocker.getInstance(ContextualAuthorizationManager.class);
    when(authorization.hasAccess(Right.PROGRAM)).thenReturn(true);
    getService().move(request);
    assertFalse(request.isCheckRights());
    assertEquals(bobReference, request.getUserReference());
}
Also used : ContextualAuthorizationManager(org.xwiki.security.authorization.ContextualAuthorizationManager) MoveRequest(org.xwiki.refactoring.job.MoveRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 9 with MoveRequest

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

the class RefactoringScriptServiceTest method rename.

@Test
public void rename() throws Exception {
    SpaceReference spaceReference = new SpaceReference("Alice", new SpaceReference("Users", new WikiReference("dev")));
    getService().rename(spaceReference, "Bob");
    ArgumentCaptor<MoveRequest> request = ArgumentCaptor.forClass(MoveRequest.class);
    verify(this.jobExecutor).execute(eq(RefactoringJobs.RENAME), request.capture());
    assertEquals(RefactoringJobs.RENAME, request.getValue().getJobType());
    assertEquals(Arrays.asList(spaceReference), request.getValue().getEntityReferences());
    assertEquals(new SpaceReference("Bob", spaceReference.getParent()), request.getValue().getDestination());
}
Also used : MoveRequest(org.xwiki.refactoring.job.MoveRequest) SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 10 with MoveRequest

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

the class RefactoringScriptServiceTest method moveWithException.

@Test
public void moveWithException() throws Exception {
    MoveRequest request = new MoveRequest();
    JobException exception = new JobException("Some error message");
    when(this.jobExecutor.execute(RefactoringJobs.MOVE, request)).thenThrow(exception);
    assertNull(getService().move(request));
    assertSame(exception, getService().getLastError());
}
Also used : JobException(org.xwiki.job.JobException) MoveRequest(org.xwiki.refactoring.job.MoveRequest) 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