use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class UserTaskCandidateUserRuntimeTest method shouldCreateClaimAndCompleteTask.
@Test
public void shouldCreateClaimAndCompleteTask() {
securityUtil.logInAs("user1");
ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(processKey).withBusinessKey("my-business-key").withName("my-process-instance-name").build());
// then
assertThat(processInstance).isNotNull();
assertThat(processInstance.getStatus()).isEqualTo(ProcessInstance.ProcessInstanceStatus.RUNNING);
assertThat(processInstance.getBusinessKey()).isEqualTo("my-business-key");
assertThat(processInstance.getName()).isEqualTo("my-process-instance-name");
// I should be able to get the process instance from the Runtime because it is still running
ProcessInstance processInstanceById = processRuntime.processInstance(processInstance.getId());
assertThat(processInstanceById).isEqualTo(processInstance);
// I should get a task for User1
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(1);
Task task = tasks.getContent().get(0);
Task taskById = taskRuntime.task(task.getId());
assertThat(taskById.getStatus()).isEqualTo(Task.TaskStatus.CREATED);
assertThat(task).isEqualTo(taskById);
assertThat(task.getAssignee()).isNull();
assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, TaskRuntimeEvent.TaskEvents.TASK_CREATED);
clearEvents();
// Check with user2
securityUtil.logInAs("user2");
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(0);
Throwable throwable = catchThrowable(() -> taskRuntime.task(task.getId()));
assertThat(throwable).isInstanceOf(NotFoundException.class);
// Try to complete without claim should error
securityUtil.logInAs("user1");
throwable = catchThrowable(() -> taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build()));
assertThat(throwable).isInstanceOf(IllegalStateException.class);
// Claim should be allowed
Task claimedTask = taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
assertThat(claimedTask.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
assertThat(claimedTask.getAssignee()).isEqualTo("user1");
assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, TaskRuntimeEvent.TaskEvents.TASK_UPDATED);
clearEvents();
// complete task now should work
Task completedTask = taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(claimedTask.getId()).build());
assertThat(completedTask.getStatus()).isEqualTo(Task.TaskStatus.COMPLETED);
assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED);
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class UserTaskCandidateGroupAndAssigneeTest method shouldCreateAndCompleteATaskAndDontSeeNext.
@Test
public void shouldCreateAndCompleteATaskAndDontSeeNext() {
securityUtil.logInAs("user1");
// given
ProcessInstance processInstance = processOperations.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(processKey).withBusinessKey("my-business-key").withName("my-process-instance-name").build()).expectFields(processInstance().status(ProcessInstance.ProcessInstanceStatus.RUNNING), processInstance().name("my-process-instance-name"), processInstance().businessKey("my-business-key")).expect(processInstance().hasTask("Task User1", Task.TaskStatus.ASSIGNED, withAssignee("user1"))).expectEvents(processInstance().hasBeenStarted(), startEvent("StartEvent_1").hasBeenStarted(), startEvent("StartEvent_1").hasBeenCompleted(), sequenceFlow("SequenceFlow_1uccvwa").hasBeenTaken(), taskWithName("Task User1").hasBeenCreated(), taskWithName("Task User1").hasBeenAssigned()).andReturn();
// I should be able to get the process instance from the Runtime because it is still running
ProcessInstance processInstanceById = processRuntime.processInstance(processInstance.getId());
assertThat(processInstanceById).isEqualTo(processInstance);
// I should get a task for User1
GetTasksPayload processInstanceTasksPayload = TaskPayloadBuilder.tasks().withProcessInstanceId(processInstance.getId()).build();
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50), processInstanceTasksPayload);
assertThat(tasks.getTotalItems()).isEqualTo(1);
Task task = tasks.getContent().get(0);
// given
taskOperations.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build()).expectEvents(task().hasBeenCompleted(), sequenceFlow("SequenceFlow_151v2cg").hasBeenTaken(), taskWithName("Task Group1").hasBeenCreated()).expect(processInstance().hasTask("Task Group1", Task.TaskStatus.CREATED, createdTask -> {
assertThat(taskRuntime.userCandidates(createdTask.getId())).isEmpty();
assertThat(taskRuntime.groupCandidates(createdTask.getId())).contains("group1");
}));
// Check with user1 as he is a candidate
tasks = taskRuntime.tasks(Pageable.of(0, 50), processInstanceTasksPayload);
assertThat(tasks.getTotalItems()).isEqualTo(1);
// Check with user2 candidates which is not a candidate
securityUtil.logInAs("user2");
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(0);
// Check with user3 candidates which is a candidate
securityUtil.logInAs("user3");
tasks = taskRuntime.tasks(Pageable.of(0, 50), processInstanceTasksPayload);
assertThat(tasks.getTotalItems()).isEqualTo(1);
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class UserTaskCandidateVisibilityTest method shouldCreateATaskAndAddNewCandidateUser.
@Test
public void shouldCreateATaskAndAddNewCandidateUser() {
securityUtil.logInAs("user1");
ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(processKey).withBusinessKey("my-business-key").withName("my-process-instance-name").build());
// then
assertThat(processInstance).isNotNull();
assertThat(processInstance.getStatus()).isEqualTo(ProcessInstance.ProcessInstanceStatus.RUNNING);
assertThat(processInstance.getBusinessKey()).isEqualTo("my-business-key");
assertThat(processInstance.getName()).isEqualTo("my-process-instance-name");
// I should be able to get the process instance from the Runtime because it is still running
ProcessInstance processInstanceById = processRuntime.processInstance(processInstance.getId());
assertThat(processInstanceById).isEqualTo(processInstance);
// I should get a task for User1
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(1);
final Task task = tasks.getContent().get(0);
Task taskById = taskRuntime.task(task.getId());
assertThat(taskById.getStatus()).isEqualTo(Task.TaskStatus.CREATED);
assertThat(task).isEqualTo(taskById);
assertThat(task.getAssignee()).isNull();
assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, TaskRuntimeEvent.TaskEvents.TASK_CREATED);
clearEvents();
// Check with user2
securityUtil.logInAs("user2");
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(0);
Throwable throwable = catchThrowable(() -> taskRuntime.task(task.getId()));
assertThat(throwable).isInstanceOf(NotFoundException.class);
// Check with user1 candidates
securityUtil.logInAs("user1");
taskById = taskRuntime.task(task.getId());
List<String> candidateUsers = taskRuntime.userCandidates(task.getId());
assertThat(candidateUsers).isEmpty();
List<String> candidateGroups = taskRuntime.groupCandidates(task.getId());
assertThat(candidateGroups).contains("group1");
// This should fail because user1 is not the assignee
throwable = catchThrowable(() -> taskRuntime.addCandidateUsers(TaskPayloadBuilder.addCandidateUsers().withTaskId(task.getId()).withCandidateUser("user2").build()));
assertThat(throwable).isInstanceOf(IllegalStateException.class);
taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
// Now it should work
taskRuntime.addCandidateUsers(TaskPayloadBuilder.addCandidateUsers().withTaskId(task.getId()).withCandidateUser("user2").build());
candidateUsers = taskRuntime.userCandidates(task.getId());
assertThat(candidateUsers).contains("user2");
// User 1 needs to release the task in order for User 2 see it as candidate
taskRuntime.release(TaskPayloadBuilder.release().withTaskId(task.getId()).build());
// Check with user2
securityUtil.logInAs("user2");
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(1);
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class UserTaskCandidateGroupsTest method shouldCreateAndCompleteATaskAndDontSeeNext.
@Test
public void shouldCreateAndCompleteATaskAndDontSeeNext() {
securityUtil.logInAs("user1");
ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(processKey).withBusinessKey("my-business-key").withName("my-process-instance-name").build());
// then
assertThat(processInstance).isNotNull();
assertThat(processInstance.getStatus()).isEqualTo(ProcessInstance.ProcessInstanceStatus.RUNNING);
assertThat(processInstance.getBusinessKey()).isEqualTo("my-business-key");
assertThat(processInstance.getName()).isEqualTo("my-process-instance-name");
// I should be able to get the process instance from the Runtime because it is still running
ProcessInstance processInstanceById = processRuntime.processInstance(processInstance.getId());
assertThat(processInstanceById).isEqualTo(processInstance);
// I should get a task for User1
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(1);
Task task = tasks.getContent().get(0);
Task taskById = taskRuntime.task(task.getId());
assertThat(taskById.getStatus()).isEqualTo(Task.TaskStatus.CREATED);
assertThat(task).isEqualTo(taskById);
assertThat(task.getAssignee()).isNull();
assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, TaskRuntimeEvent.TaskEvents.TASK_CREATED);
clearEvents();
taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, TaskRuntimeEvent.TaskEvents.TASK_UPDATED);
clearEvents();
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build());
assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, TaskRuntimeEvent.TaskEvents.TASK_CREATED);
// Check with user2 as he is a candidate
securityUtil.logInAs("user2");
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(1);
task = tasks.getContent().get(0);
taskById = taskRuntime.task(task.getId());
assertThat(taskById.getStatus()).isEqualTo(Task.TaskStatus.CREATED);
List<String> candidateUsers = taskRuntime.userCandidates(task.getId());
assertThat(candidateUsers).hasSize(0);
List<String> candidateGroups = taskRuntime.groupCandidates(task.getId());
assertThat(candidateGroups).contains("group2");
// Check with user1 candidates which is not a candidate
securityUtil.logInAs("user1");
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(0);
// Check with user3 candidates which is a candidate
securityUtil.logInAs("user3");
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(1);
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskVariablesLocalCopiesTest method testAdminTaskVariables.
@Test
public void testAdminTaskVariables() {
securityUtil.logInAs("user");
Map<String, Object> startVariables = new HashMap<>();
startVariables.put("start1", "start1");
startVariables.put("start2", "start2");
// when
ProcessInstance twoTaskInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(TWOTASK_PROCESS).withVariables(startVariables).build());
assertThat(processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstance(twoTaskInstance).build())).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("start1", "start1"), tuple("start2", "start2"));
// both tasks should have the process variables
Task task1 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
// check that admin can get task variables
securityUtil.logInAs("admin");
assertThat(taskAdminRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task1.getId()).build())).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("start1", "start1"), tuple("start2", "start2"));
// check that admin can modify task variables
taskAdminRuntime.updateVariable(TaskPayloadBuilder.updateVariable().withTaskId(task1.getId()).withVariable("start1", "modifiedstart1").build());
// the task where it was modified should reflect the modification
assertThat(taskAdminRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task1.getId()).build())).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("start1", "modifiedstart1"), tuple("start2", "start2"));
securityUtil.logInAs("user");
// complete and change var again
taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task1.getId()).build());
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task1.getId()).withVariable("start1", "modagainstart1").build());
// after completion the process variable should be updated but only the one that was modified
assertThat(processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstance(twoTaskInstance).build())).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("start1", "modagainstart1"), tuple("start2", "start2"));
}
Aggregations