Search in sources :

Example 11 with EntityRequest

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

the class EntityJobTest method hasAccess.

@Test
public void hasAccess() {
    EntityRequest request = mock(EntityRequest.class);
    when(request.isCheckRights()).thenReturn(true, true, false);
    DocumentReference userReference = new DocumentReference("foo", "Users", "Alice");
    when(request.getUserReference()).thenReturn(userReference);
    DocumentReference documentReference = new DocumentReference("math", "Space", "Page");
    when(this.authorization.hasAccess(Right.EDIT, userReference, documentReference.getLastSpaceReference())).thenReturn(true);
    when(this.authorization.hasAccess(Right.DELETE, userReference, documentReference)).thenReturn(false);
    NoopEntityJob job = new NoopEntityJob();
    initialize(job, request);
    // checkRights = true
    assertTrue(job.hasAccess(Right.EDIT, documentReference.getLastSpaceReference()));
    assertFalse(job.hasAccess(Right.DELETE, documentReference));
    // checkRights = false
    assertTrue(job.hasAccess(Right.DELETE, documentReference));
}
Also used : EntityRequest(org.xwiki.refactoring.job.EntityRequest) 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