Search in sources :

Example 1 with GetTasksPayload

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);
}
Also used : ProcessInstanceMatchers.processInstance(org.activiti.test.matchers.ProcessInstanceMatchers.processInstance) Pageable(org.activiti.api.runtime.shared.query.Pageable) BPMNStartEventMatchers.startEvent(org.activiti.test.matchers.BPMNStartEventMatchers.startEvent) Task(org.activiti.api.task.model.Task) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) RuntimeTestConfiguration(org.activiti.spring.conformance.util.RuntimeTestConfiguration) ProcessPayloadBuilder(org.activiti.api.process.model.builders.ProcessPayloadBuilder) GetTasksPayload(org.activiti.api.task.model.payloads.GetTasksPayload) ProcessRuntime(org.activiti.api.process.runtime.ProcessRuntime) TaskOperations(org.activiti.test.operations.TaskOperations) SequenceFlowMatchers.sequenceFlow(org.activiti.test.matchers.SequenceFlowMatchers.sequenceFlow) SecurityUtil(org.activiti.spring.conformance.util.security.SecurityUtil) TaskMatchers.task(org.activiti.test.matchers.TaskMatchers.task) TaskRuntime(org.activiti.api.task.runtime.TaskRuntime) ProcessOperations(org.activiti.test.operations.ProcessOperations) ProcessInstance(org.activiti.api.process.model.ProcessInstance) TaskPayloadBuilder(org.activiti.api.task.model.builders.TaskPayloadBuilder) ProcessTaskMatchers.taskWithName(org.activiti.test.matchers.ProcessTaskMatchers.taskWithName) Page(org.activiti.api.runtime.shared.query.Page) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProcessAdminRuntime(org.activiti.api.process.runtime.ProcessAdminRuntime) TaskMatchers.withAssignee(org.activiti.test.matchers.TaskMatchers.withAssignee) Task(org.activiti.api.task.model.Task) GetTasksPayload(org.activiti.api.task.model.payloads.GetTasksPayload) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with GetTasksPayload

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);
}
Also used : Task(org.activiti.api.task.model.Task) GetTasksPayload(org.activiti.api.task.model.payloads.GetTasksPayload) GetTasksPayloadBuilder(org.activiti.api.task.model.builders.GetTasksPayloadBuilder)

Example 3 with GetTasksPayload

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;
}
Also used : Task(org.activiti.api.task.model.Task) GetTasksPayload(org.activiti.api.task.model.payloads.GetTasksPayload) ProcessInstance(org.activiti.api.process.model.ProcessInstance) GetProcessInstancesPayload(org.activiti.api.process.model.payloads.GetProcessInstancesPayload)

Example 4 with GetTasksPayload

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);
}
Also used : Task(org.activiti.api.task.model.Task) GetTasksPayload(org.activiti.api.task.model.payloads.GetTasksPayload) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Task (org.activiti.api.task.model.Task)4 GetTasksPayload (org.activiti.api.task.model.payloads.GetTasksPayload)4 ProcessInstance (org.activiti.api.process.model.ProcessInstance)3 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 ProcessPayloadBuilder (org.activiti.api.process.model.builders.ProcessPayloadBuilder)1 GetProcessInstancesPayload (org.activiti.api.process.model.payloads.GetProcessInstancesPayload)1 ProcessAdminRuntime (org.activiti.api.process.runtime.ProcessAdminRuntime)1 ProcessRuntime (org.activiti.api.process.runtime.ProcessRuntime)1 Page (org.activiti.api.runtime.shared.query.Page)1 Pageable (org.activiti.api.runtime.shared.query.Pageable)1 GetTasksPayloadBuilder (org.activiti.api.task.model.builders.GetTasksPayloadBuilder)1 TaskPayloadBuilder (org.activiti.api.task.model.builders.TaskPayloadBuilder)1 TaskRuntime (org.activiti.api.task.runtime.TaskRuntime)1 RuntimeTestConfiguration (org.activiti.spring.conformance.util.RuntimeTestConfiguration)1 SecurityUtil (org.activiti.spring.conformance.util.security.SecurityUtil)1 BPMNStartEventMatchers.startEvent (org.activiti.test.matchers.BPMNStartEventMatchers.startEvent)1 ProcessInstanceMatchers.processInstance (org.activiti.test.matchers.ProcessInstanceMatchers.processInstance)1 ProcessTaskMatchers.taskWithName (org.activiti.test.matchers.ProcessTaskMatchers.taskWithName)1 SequenceFlowMatchers.sequenceFlow (org.activiti.test.matchers.SequenceFlowMatchers.sequenceFlow)1