Search in sources :

Example 6 with EntityRequest

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

the class RefactoringScriptService method createDeleteRequest.

/**
 * Creates a request to delete the specified entities.
 *
 * @param entityReferences the entities to delete
 * @return the delete request
 */
public EntityRequest createDeleteRequest(Collection<EntityReference> entityReferences) {
    EntityRequest request = new EntityRequest();
    initEntityRequest(request, RefactoringJobs.DELETE, entityReferences);
    return request;
}
Also used : EntityRequest(org.xwiki.refactoring.job.EntityRequest)

Example 7 with EntityRequest

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

the class DeleteJobTest method createRequest.

private EntityRequest createRequest(EntityReference... entityReference) {
    EntityRequest request = new EntityRequest();
    request.setEntityReferences(Arrays.asList(entityReference));
    return request;
}
Also used : EntityRequest(org.xwiki.refactoring.job.EntityRequest)

Example 8 with EntityRequest

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

the class DeleteJobTest method deleteDocumentWithoutDeleteRight.

@Test
public void deleteDocumentWithoutDeleteRight() 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);
    EntityRequest request = createRequest(documentReference);
    request.setCheckRights(true);
    request.setUserReference(userReference);
    run(request);
    verify(this.mocker.getMockedLogger()).error("You are not allowed to delete [{}].", documentReference);
    verify(this.modelBridge, never()).delete(any(DocumentReference.class));
}
Also used : EntityRequest(org.xwiki.refactoring.job.EntityRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 9 with EntityRequest

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

the class DeleteJobTest method deleteSpaceHomeDeep.

@Test
public void deleteSpaceHomeDeep() throws Throwable {
    DocumentReference documentReference = new DocumentReference("wiki", "Space", "WebHome");
    EntityRequest request = createRequest(documentReference);
    request.setDeep(true);
    run(request);
    // We only verify if the job fetches the documents from the space. The rest of the test is in #deleteSpace()
    verify(this.modelBridge, atLeastOnce()).getDocumentReferences(documentReference.getLastSpaceReference());
}
Also used : EntityRequest(org.xwiki.refactoring.job.EntityRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 10 with EntityRequest

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

the class EntityJobTest method getGroupPath.

@Test
public void getGroupPath() {
    NoopEntityJob job = new NoopEntityJob();
    EntityRequest request = new EntityRequest();
    DocumentReference aliceReference = new DocumentReference("chess", Arrays.asList("Path", "To"), "Alice");
    request.setEntityReferences(aliceReference.getReversedReferenceChain());
    initialize(job, request);
    assertEquals(new JobGroupPath(Arrays.asList("refactoring", "chess")), job.getGroupPath());
    DocumentReference bobReference = new DocumentReference("dev", Arrays.asList("Path", "To"), "Bob");
    request.setEntityReferences(Arrays.<EntityReference>asList(aliceReference, bobReference));
    initialize(job, request);
    assertEquals(new JobGroupPath(Arrays.asList("refactoring")), job.getGroupPath());
    DocumentReference carolReference = new DocumentReference("chess", Arrays.asList("Path", "To"), "Carol");
    request.setEntityReferences(Arrays.<EntityReference>asList(aliceReference, carolReference));
    initialize(job, request);
    assertEquals(new JobGroupPath(Arrays.asList("refactoring", "chess", "Path", "To")), job.getGroupPath());
    DocumentReference daveReference = new DocumentReference("chess", Arrays.asList("Path", "To2"), "Dave");
    request.setEntityReferences(Arrays.<EntityReference>asList(aliceReference, carolReference, daveReference));
    initialize(job, request);
    assertEquals(new JobGroupPath(Arrays.asList("refactoring", "chess", "Path")), job.getGroupPath());
}
Also used : EntityRequest(org.xwiki.refactoring.job.EntityRequest) JobGroupPath(org.xwiki.job.JobGroupPath) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

EntityRequest (org.xwiki.refactoring.job.EntityRequest)11 Test (org.junit.Test)8 DocumentReference (org.xwiki.model.reference.DocumentReference)7 ArrayList (java.util.ArrayList)2 XWikiException (com.xpn.xwiki.XWikiException)1 JobException (org.xwiki.job.JobException)1 JobExecutor (org.xwiki.job.JobExecutor)1 JobGroupPath (org.xwiki.job.JobGroupPath)1 EntityReference (org.xwiki.model.reference.EntityReference)1 SpaceReference (org.xwiki.model.reference.SpaceReference)1 WikiReference (org.xwiki.model.reference.WikiReference)1 RefactoringScriptService (org.xwiki.refactoring.script.RefactoringScriptService)1 ScriptService (org.xwiki.script.service.ScriptService)1