use of org.activiti.api.task.model.payloads.GetTasksPayload 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.payloads.GetTasksPayload in project Activiti by Activiti.
the class ProcessRuntimeBPMNErrorReceivedIT method checkTask.
private void checkTask(String processInstanceId, String taskName) {
GetTasksPayload getTasksPayload = new GetTasksPayloadBuilder().withProcessInstanceId(processInstanceId).build();
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50), getTasksPayload);
assertThat(tasks.getContent()).hasSize(1);
assertThat(tasks.getContent().get(0).getName()).isEqualTo(taskName);
}
use of org.activiti.api.task.model.payloads.GetTasksPayload in project workflow-service by open-hand.
the class ProcessInstanceServiceImpl method approveUserTask.
@Override
public Boolean approveUserTask(String businessKey) {
GetProcessInstancesPayload getProcessInstancesPayload = new GetProcessInstancesPayload();
getProcessInstancesPayload.setBusinessKey(businessKey);
Page<ProcessInstance> processInstances = processRuntime.processInstances(Pageable.of(0, 10), getProcessInstancesPayload);
if (processInstances.getContent().size() > 0) {
GetTasksPayload getTasksPayload = new GetTasksPayload();
getTasksPayload.setProcessInstanceId(processInstances.getContent().get(0).getId());
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 10), getTasksPayload);
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(tasks.getContent().get(0).getId()).build());
return true;
}
return false;
}
use of org.activiti.api.task.model.payloads.GetTasksPayload in project Activiti by Activiti.
the class BasicInclusiveGatewayTest method testProcessExecutionWithInclusiveGateway.
@Test
public void testProcessExecutionWithInclusiveGateway() {
// given
securityUtil.logInAs("user1");
// given
ProcessInstance processInstance = processOperations.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(PROCESS_KEY).withBusinessKey("my-business-key").withName("my-process-instance-name").withVariable("input", 1).build()).expectFields(processInstance().status(ProcessInstance.ProcessInstanceStatus.RUNNING), processInstance().name("my-process-instance-name"), processInstance().businessKey("my-business-key")).expect(processInstance().hasTask("Start Process", Task.TaskStatus.ASSIGNED, withAssignee("user1"))).expectEvents(processInstance().hasBeenStarted(), startEvent("theStart").hasBeenStarted(), startEvent("theStart").hasBeenCompleted(), sequenceFlow("flow1").hasBeenTaken(), taskWithName("Start Process").hasBeenCreated(), taskWithName("Start Process").hasBeenAssigned()).andReturn();
// I should be able to get the process instance from the Runtime
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("flow2").hasBeenTaken(), inclusiveGateway("inclusiveGateway").hasBeenStarted(), inclusiveGateway("inclusiveGateway").hasBeenCompleted(), sequenceFlow("flow3").hasBeenTaken(), taskWithName("Send e-mail").hasBeenCreated(), sequenceFlow("flow4").hasBeenTaken(), taskWithName("Check account").hasBeenCreated()).expect(processInstance().hasTask("Send e-mail", Task.TaskStatus.ASSIGNED), processInstance().hasTask("Check account", Task.TaskStatus.ASSIGNED));
// then - two tasks should be available
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(2);
Task task1 = tasks.getContent().get(0);
Task task2 = tasks.getContent().get(1);
// given
taskOperations.complete(TaskPayloadBuilder.complete().withTaskId(task1.getId()).build()).expectEvents(task().hasBeenCompleted(), inclusiveGateway("inclusiveGatewayEnd").hasBeenStarted()).expect(processInstance().hasTask(task2.getName(), task2.getStatus()));
// then - only second task should be available
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(1);
assertThat(tasks.getContent()).extracting(Task::getStatus, Task::getName).contains(tuple(task2.getStatus(), task2.getName()));
// complete second task
taskOperations.complete(TaskPayloadBuilder.complete().withTaskId(task2.getId()).build()).expectEvents(task().hasBeenCompleted(), inclusiveGateway("inclusiveGatewayEnd").hasBeenCompleted(), endEvent("theEnd").hasBeenStarted(), endEvent("theEnd").hasBeenCompleted());
// No tasks should be available
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(0);
}
Aggregations