Search in sources :

Example 1 with Operation

use of org.kie.internal.task.api.model.Operation in project jbpm by kiegroup.

the class MVELLifeCycleManagerTest method testClaimIsAllowedExcludedOwner.

/**
 * Tests that a user who is in the ExcludedOwners list of the {@link Task task's) {@link PeopleAssignments peopleAssignment's) object is
 * not allowed to execute operations on the given task. We expect to get a {@link PermissionDeniedException}.
 */
@Test(expected = PermissionDeniedException.class)
public void testClaimIsAllowedExcludedOwner() {
    User testUser = new UserImpl("BB8");
    List<String> testGroupIds = new ArrayList<>();
    testGroupIds.add("testGroup1");
    // Create the task.
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { status = Status.Created } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { excludedOwners = [new User('BB8')], potentialOwners = [new Group('testGroup1')]}),";
    str += "name =  'This is my task name' })";
    InternalTask task = (InternalTask) TaskFactory.evalTask(new StringReader(str));
    // Test whether we can claim the task. This should not be possible.
    Operation operation = Operation.Claim;
    List<OperationCommand> operationCommands = new ArrayList<>();
    OperationCommand operationCommand = new OperationCommand();
    // Set the list of user-types (e.g. PotentialOwners, BusinessAdministrators, etc.) that are allowed to execute this operation.
    List<Allowed> allowed = new ArrayList<>();
    // We should only allow PotentialOwner in this test (we're claiming a task).
    allowed.add(Allowed.PotentialOwner);
    operationCommand.setAllowed(allowed);
    // Set the status that is required to be able to execute this operation.
    List<Status> status = new ArrayList<>();
    // Before we claim a task, the status is "Created".
    status.add(Status.Created);
    operationCommand.setStatus(status);
    operationCommands.add(operationCommand);
    // We don't need "targetEntity" and "entities" for this test.
    MVELLifeCycleManager taskLcManager = new MVELLifeCycleManager();
    taskLcManager.evalCommand(operation, operationCommands, task, testUser, null, testGroupIds, null);
}
Also used : Status(org.kie.api.task.model.Status) User(org.kie.api.task.model.User) InternalTask(org.kie.internal.task.api.model.InternalTask) ArrayList(java.util.ArrayList) Operation(org.kie.internal.task.api.model.Operation) UserImpl(org.jbpm.services.task.impl.model.UserImpl) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 2 with Operation

use of org.kie.internal.task.api.model.Operation in project jbpm by kiegroup.

the class MVELLifeCycleManagerTest method testDelegateIsAllowedExcludedOwnerBusinessAdministrator.

/**
 * Tests that a user who is in the ExcludedOwners list of the {@link Task task's) {@link PeopleAssignments peopleAssignment's) object IS
 * allowed to execute operations on the given task IF the person is also a Business Administrator.
 */
@Test
public void testDelegateIsAllowedExcludedOwnerBusinessAdministrator() {
    User testUser = new UserImpl("BB8");
    List<String> testGroupIds = new ArrayList<>();
    testGroupIds.add("testGroup1");
    // Create the task.
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { status = Status.Ready } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { excludedOwners = [new User('BB8')], potentialOwners = [new Group('testGroup1')], businessAdministrators = [new User('BB8')]}),";
    str += "name =  'This is my task name' })";
    InternalTask task = (InternalTask) TaskFactory.evalTask(new StringReader(str));
    /*
		 * Test whether we can delegate the task. Because the user is a BusinessAdministrator, this should be possible, even if the owner is
		 * in the ExcludedOwners list.
		 */
    Operation operation = Operation.Delegate;
    List<OperationCommand> operationCommands = new ArrayList<>();
    OperationCommand operationCommand = new OperationCommand();
    // Set the list of user-types (e.g. PotentialOwners, BusinessAdministrators, etc.) that are allowed to execute this operation.
    List<Allowed> allowed = new ArrayList<>();
    // We should only allow PotentialOwner in this test (we're claiming a task).
    allowed.add(Allowed.PotentialOwner);
    allowed.add(Allowed.BusinessAdministrator);
    operationCommand.setAllowed(allowed);
    // Set the status that is required to be able to execute this operation.
    List<Status> status = new ArrayList<>();
    // Before we claim a task, the status is "Created".
    status.add(Status.Ready);
    operationCommand.setStatus(status);
    operationCommands.add(operationCommand);
    // We don't need "targetEntity" and "entities" for this test.
    MVELLifeCycleManager taskLcManager = new MVELLifeCycleManager();
    taskLcManager.evalCommand(operation, operationCommands, task, testUser, null, testGroupIds, null);
}
Also used : Status(org.kie.api.task.model.Status) User(org.kie.api.task.model.User) InternalTask(org.kie.internal.task.api.model.InternalTask) ArrayList(java.util.ArrayList) Operation(org.kie.internal.task.api.model.Operation) UserImpl(org.jbpm.services.task.impl.model.UserImpl) StringReader(java.io.StringReader) Test(org.junit.Test)

Aggregations

StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 UserImpl (org.jbpm.services.task.impl.model.UserImpl)2 Test (org.junit.Test)2 Status (org.kie.api.task.model.Status)2 User (org.kie.api.task.model.User)2 InternalTask (org.kie.internal.task.api.model.InternalTask)2 Operation (org.kie.internal.task.api.model.Operation)2