Search in sources :

Example 16 with MoveRequest

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

the class RenameJobTest method renameDocument.

@Test
public void renameDocument() throws Throwable {
    DocumentReference oldReference = new DocumentReference("wiki", "Space", "Old");
    when(this.modelBridge.exists(oldReference)).thenReturn(true);
    DocumentReference newReference = new DocumentReference("wiki", "Space", "New");
    DocumentReference userReference = new DocumentReference("wiki", "Users", "Alice");
    when(this.modelBridge.copy(oldReference, newReference)).thenReturn(true);
    MoveRequest request = createRequest(oldReference, newReference);
    request.setCheckRights(false);
    request.setInteractive(false);
    request.setUserReference(userReference);
    run(request);
    verify(this.modelBridge).setContextUserReference(userReference);
    verify(this.modelBridge).delete(oldReference);
    verify(this.modelBridge).createRedirect(oldReference, newReference);
}
Also used : MoveRequest(org.xwiki.refactoring.job.MoveRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 17 with MoveRequest

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

the class RenameJobTest method renameMultipleEntities.

@Test
public void renameMultipleEntities() throws Throwable {
    DocumentReference blackReference = new DocumentReference("wiki", "Color", "Black");
    DocumentReference whiteReference = new DocumentReference("wiki", "Color", "White");
    DocumentReference orangeReference = new DocumentReference("wiki", "Color", "Orange");
    MoveRequest request = new MoveRequest();
    request.setEntityReferences(Arrays.<EntityReference>asList(blackReference, whiteReference));
    request.setDestination(orangeReference);
    run(request);
    verifyNoMove();
}
Also used : MoveRequest(org.xwiki.refactoring.job.MoveRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 18 with MoveRequest

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

the class RefactoringScriptServiceTest method convertToTerminalDocument.

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

Example 19 with MoveRequest

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

the class RefactoringScriptServiceTest method move.

@Test
public void move() throws Exception {
    SpaceReference source = new SpaceReference("Space", new WikiReference("math"));
    WikiReference destination = new WikiReference("code");
    Job job = mock(Job.class);
    ArgumentCaptor<MoveRequest> request = ArgumentCaptor.forClass(MoveRequest.class);
    when(this.jobExecutor.execute(eq(RefactoringJobs.MOVE), request.capture())).thenReturn(job);
    assertSame(job, getService().move(source, destination));
    assertEquals(Arrays.asList(source), request.getValue().getEntityReferences());
    assertEquals(destination, request.getValue().getDestination());
    assertEquals(Arrays.asList(RefactoringJobs.GROUP, "move"), request.getValue().getId().subList(0, 2));
    assertEquals(RefactoringJobs.MOVE, request.getValue().getJobType());
    assertEquals(this.userReference, request.getValue().getUserReference());
    assertEquals(false, request.getValue().isDeep());
    assertEquals(true, request.getValue().isDeleteSource());
    assertEquals(true, request.getValue().isUpdateLinks());
    assertEquals(true, request.getValue().isAutoRedirect());
    assertEquals(false, request.getValue().isInteractive());
    assertEquals(true, request.getValue().isCheckRights());
}
Also used : MoveRequest(org.xwiki.refactoring.job.MoveRequest) SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) Job(org.xwiki.job.Job) Test(org.junit.Test)

Example 20 with MoveRequest

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

the class RefactoringScriptServiceTest method copy.

@Test
public void copy() throws Exception {
    SpaceReference source = new SpaceReference("Space", new WikiReference("math"));
    WikiReference destination = new WikiReference("code");
    getService().copy(source, destination);
    ArgumentCaptor<MoveRequest> request = ArgumentCaptor.forClass(MoveRequest.class);
    // The MOVE job can perform a COPY too.
    verify(this.jobExecutor).execute(eq(RefactoringJobs.MOVE), request.capture());
    assertEquals(RefactoringJobs.COPY, request.getValue().getJobType());
    assertFalse(request.getValue().isDeleteSource());
}
Also used : MoveRequest(org.xwiki.refactoring.job.MoveRequest) SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) 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