Search in sources :

Example 21 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class ProcessRuntimeBPMNMessageIT method should_not_cancelTask_when_nonInterruptedMessageReceived.

@Test
public void should_not_cancelTask_when_nonInterruptedMessageReceived() {
    ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withBusinessKey("businessKey").withVariable("correlationKey", "correlationKey").withProcessDefinitionKey("messageNonInterruptingSubProcess").build());
    List<Task> allTasks = taskRuntime.tasks(Pageable.of(0, 2), TaskPayloadBuilder.tasks().withProcessInstanceId(processInstance.getId()).build()).getContent();
    assertThat(allTasks.size()).isEqualTo(1);
    assertThat(MessageTestConfiguration.messageEvents).isNotEmpty().extracting(BPMNMessageEvent::getEventType, BPMNMessageEvent::getProcessDefinitionId, BPMNMessageEvent::getProcessInstanceId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getMessagePayload().getName(), event -> event.getEntity().getMessagePayload().getCorrelationKey(), event -> event.getEntity().getMessagePayload().getBusinessKey(), event -> event.getEntity().getMessagePayload().getVariables()).contains(Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_WAITING, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "nonInterruptedMessage", "correlationKey", processInstance.getBusinessKey(), null));
    assertThat(localEventSource.getEvents()).filteredOn(event -> event.getEventType().equals(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED)).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, allTasks.get(0).getName()));
    // sending the Non Interrupted Start Message to process
    processRuntime.receive(MessagePayloadBuilder.receive("nonInterruptedMessage").withCorrelationKey("correlationKey").build());
    // then
    assertThat(MessageTestConfiguration.messageEvents).isNotEmpty().extracting(BPMNMessageEvent::getEventType, BPMNMessageEvent::getProcessDefinitionId, BPMNMessageEvent::getProcessInstanceId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getMessagePayload().getName(), event -> event.getEntity().getMessagePayload().getCorrelationKey(), event -> event.getEntity().getMessagePayload().getBusinessKey(), event -> event.getEntity().getMessagePayload().getVariables()).contains(Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_WAITING, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "nonInterruptedMessage", "correlationKey", processInstance.getBusinessKey(), null), Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_RECEIVED, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "nonInterruptedMessage", "correlationKey", processInstance.getBusinessKey(), null));
    assertThat(taskBaseRuntime.getTasksByProcessInstanceId(processInstance.getId()).size()).isEqualTo(1);
    assertThat(localEventSource.getEvents()).filteredOn(event -> event.getEventType().equals(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED)).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, allTasks.get(0).getName()));
    localEventSource.clearEvents();
    taskBaseRuntime.completeTask(allTasks.get(0).getId());
    assertThat(localEventSource.getEvents()).filteredOn(event -> event.getEventType().equals(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED)).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, allTasks.get(0).getName()));
    assertThat(localEventSource.getEvents()).extracting(RuntimeEvent::getEventType, RuntimeEvent::getProcessInstanceId).contains(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, processInstance.getId()));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Pageable(org.activiti.api.runtime.shared.query.Pageable) TaskBaseRuntime(org.activiti.spring.boot.tasks.TaskBaseRuntime) ProcessRuntimeEvent(org.activiti.api.process.model.events.ProcessRuntimeEvent) Task(org.activiti.api.task.model.Task) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SecurityUtil(org.activiti.spring.boot.security.util.SecurityUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) MessagePayloadBuilder(org.activiti.api.process.model.builders.MessagePayloadBuilder) ProcessPayloadBuilder(org.activiti.api.process.model.builders.ProcessPayloadBuilder) ProcessRuntimeEventListener(org.activiti.api.process.runtime.events.listener.ProcessRuntimeEventListener) ArrayList(java.util.ArrayList) ProcessRuntime(org.activiti.api.process.runtime.ProcessRuntime) LocalEventSource(org.activiti.test.LocalEventSource) Collections.singletonMap(java.util.Collections.singletonMap) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) MessageSubscriptionEvent(org.activiti.api.process.model.events.MessageSubscriptionEvent) TaskRuntimeEvent(org.activiti.api.task.model.events.TaskRuntimeEvent) StartMessageDeploymentDefinition(org.activiti.api.process.model.StartMessageDeploymentDefinition) TaskRuntime(org.activiti.api.task.runtime.TaskRuntime) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Tuple(org.assertj.core.groups.Tuple) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TaskPayloadBuilder(org.activiti.api.task.model.builders.TaskPayloadBuilder) TestComponent(org.springframework.boot.test.context.TestComponent) RuntimeEvent(org.activiti.api.model.shared.event.RuntimeEvent) StartMessageDeployedEvents(org.activiti.api.runtime.event.impl.StartMessageDeployedEvents) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) MessageTestConfiguration(org.activiti.spring.boot.MessageTestConfiguration) Import(org.springframework.context.annotation.Import) EventListener(org.springframework.context.event.EventListener) Page(org.activiti.api.runtime.shared.query.Page) MessageSubscriptionCancelledEvent(org.activiti.api.process.model.events.MessageSubscriptionCancelledEvent) Test(org.junit.jupiter.api.Test) StartMessageSubscription(org.activiti.api.process.model.StartMessageSubscription) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProcessCleanUpUtil(org.activiti.spring.boot.test.util.ProcessCleanUpUtil) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) StartMessageDeployedEvent(org.activiti.api.process.model.events.StartMessageDeployedEvent) BPMNMessageEvent(org.activiti.api.process.model.events.BPMNMessageEvent) Task(org.activiti.api.task.model.Task) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class UserTaskAssigneeDeleteRuntimeTest method shouldFailOnDeleteTask.

@Test
public void shouldFailOnDeleteTask() {
    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.ASSIGNED);
    assertThat(task).isEqualTo(taskById);
    assertThat(task.getAssignee()).isEqualTo("user1");
    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, TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED);
    clearEvents();
    Throwable throwable = catchThrowable(() -> taskRuntime.delete(TaskPayloadBuilder.delete().withTaskId(task.getId()).withReason("I don't want this task anymore").build()));
    assertThat(throwable).isInstanceOf(ActivitiException.class).hasMessage("The task cannot be deleted because is part of a running process");
}
Also used : Task(org.activiti.api.task.model.Task) ActivitiException(org.activiti.engine.ActivitiException) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 23 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class TaskRuntimeTaskAssigneeTest method aCreateStandaloneTaskForAnotherAssignee.

@Test
public void aCreateStandaloneTaskForAnotherAssignee() {
    securityUtil.logInAs("garth");
    taskRuntime.create(TaskPayloadBuilder.create().withName("task for dean").withAssignee(// but he should still be assigned the task
    "dean").build());
    // the owner should be able to see the created task
    Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getContent()).hasSize(1);
    Task task = tasks.getContent().get(0);
    assertThat(task.getAssignee()).isEqualTo("dean");
    assertThat(task.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
    // Now the task should be visible for dean
    securityUtil.logInAs("dean");
    // the target user should be able to see the task as well
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getContent()).hasSize(1);
    task = tasks.getContent().get(0);
    assertThat(task.getAssignee()).isEqualTo("dean");
    assertThat(task.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
    Task deletedTask = taskRuntime.delete(TaskPayloadBuilder.delete().withTaskId(task.getId()).withReason("test clean up").build());
    assertThat(deletedTask).isNotNull();
    assertThat(deletedTask.getStatus()).isEqualTo(Task.TaskStatus.CANCELLED);
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getContent()).hasSize(0);
}
Also used : Task(org.activiti.api.task.model.Task) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 24 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class TaskRuntimeTerminateEndEventTest method should_ProcessesAndTasksDisappear_whenTerminateEventIsExecuted.

@Test
public void should_ProcessesAndTasksDisappear_whenTerminateEventIsExecuted() {
    ProcessInstance process = processBaseRuntime.startProcessWithProcessDefinitionKey(TASK_PROCESS_TERMINATE_EVENT);
    List<Task> taskList = taskBaseRuntime.getTasksByProcessInstanceId(process.getId());
    assertThat(taskList).isNotEmpty();
    assertThat(taskList).hasSize(2);
    Task task1 = taskList.get(0);
    taskBaseRuntime.completeTask(task1.getId());
    List<Task> taskAfterCompleted = taskBaseRuntime.getTasksByProcessInstanceId(process.getId());
    assertThat(taskAfterCompleted).hasSize(0);
}
Also used : Task(org.activiti.api.task.model.Task) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 25 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class TaskRuntimeTerminateEndEventTest method should_CancelledTasksByTerminateEndEventHaveCancellationReasonSet.

@Test
public void should_CancelledTasksByTerminateEndEventHaveCancellationReasonSet() {
    securityUtil.logInAs("user");
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey(PROCESS_TERMINATE_EVENT);
    assertThat(processInstance).isNotNull();
    List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
    assertThat(tasks).hasSize(2);
    Task task2 = tasks.get(1);
    taskBaseRuntime.completeTask(task2.getId());
    List<Task> tasksAfterCompletion = taskBaseRuntime.getTasks(processInstance);
    assertThat(tasksAfterCompletion).hasSize(0);
    List<TaskCancelledEvent> taskCancelledEvents = localEventSource.getEvents(TaskCancelledEvent.class);
    assertThat(taskCancelledEvents).hasSize(1);
    assertThat(taskCancelledEvents.get(0).getReason()).contains("Terminated by end event");
}
Also used : Task(org.activiti.api.task.model.Task) ProcessInstance(org.activiti.api.process.model.ProcessInstance) TaskCancelledEvent(org.activiti.api.task.runtime.events.TaskCancelledEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Task (org.activiti.api.task.model.Task)115 Test (org.junit.jupiter.api.Test)99 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)95 ProcessInstance (org.activiti.api.process.model.ProcessInstance)59 VariableInstance (org.activiti.api.model.shared.model.VariableInstance)29 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)25 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)23 AfterEach (org.junit.jupiter.api.AfterEach)23 Autowired (org.springframework.beans.factory.annotation.Autowired)23 SecurityUtil (org.activiti.spring.boot.security.util.SecurityUtil)22 Page (org.activiti.api.runtime.shared.query.Page)21 ProcessCleanUpUtil (org.activiti.spring.boot.test.util.ProcessCleanUpUtil)20 BeforeEach (org.junit.jupiter.api.BeforeEach)20 Import (org.springframework.context.annotation.Import)20 Date (java.util.Date)19 List (java.util.List)19 Collections.singletonMap (java.util.Collections.singletonMap)15 RuntimeEvent (org.activiti.api.model.shared.event.RuntimeEvent)15 ProcessRuntimeEvent (org.activiti.api.process.model.events.ProcessRuntimeEvent)15 TaskRuntimeEvent (org.activiti.api.task.model.events.TaskRuntimeEvent)15