Search in sources :

Example 56 with Task

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

the class ProcessRuntimeBPMNMessageIT method should_cancelTask_when_interruptedMessageReceived.

@Test
public void should_cancelTask_when_interruptedMessageReceived() {
    ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withBusinessKey("businessKey").withVariable("correlationKey", "correlationKey").withProcessDefinitionKey("messageInterruptingSubProcess").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(), "interruptedMessage", "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 Interrupted Start Message to process
    processRuntime.receive(MessagePayloadBuilder.receive("interruptedMessage").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(), "interruptedMessage", "correlationKey", processInstance.getBusinessKey(), null), Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_RECEIVED, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "interruptedMessage", "correlationKey", processInstance.getBusinessKey(), null));
    // then
    assertThat(taskBaseRuntime.getTasksByProcessInstanceId(processInstance.getId())).isEmpty();
    assertThat(localEventSource.getEvents()).filteredOn(event -> event.getEventType().equals(TaskRuntimeEvent.TaskEvents.TASK_CANCELLED)).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_CANCELLED, 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 57 with Task

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

the class ProcessRuntimeTerminatedEndEventIT method should_CancelledProcessesByTerminateEndEventsHaveCancellationReasonSet.

@Test
public void should_CancelledProcessesByTerminateEndEventsHaveCancellationReasonSet() {
    // given
    ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(PROCESS_TERMINATE_EVENT).withName("to be terminated").withBusinessKey("My business key").build());
    List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
    assertThat(tasks).hasSize(2);
    Task task2 = tasks.get(1);
    // when
    taskBaseRuntime.completeTask(task2.getId());
    // then
    List<Task> tasksAfterCompletion = taskBaseRuntime.getTasks(processInstance);
    assertThat(tasksAfterCompletion).hasSize(0);
    List<ProcessCancelledEvent> processCancelledEvents = localEventSource.getEvents(ProcessCancelledEvent.class);
    assertThat(processCancelledEvents).hasSize(1);
    ProcessCancelledEvent processCancelledEvent = processCancelledEvents.get(0);
    assertThat(processCancelledEvent.getCause()).contains("Terminated by end event");
    assertThat(processCancelledEvent.getEntity().getId()).isEqualTo(processInstance.getId());
    assertThat(processCancelledEvent.getEntity().getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
    assertThat(processCancelledEvent.getEntity().getName()).isEqualTo(processInstance.getName());
    assertThat(processCancelledEvent.getEntity().getBusinessKey()).isEqualTo(processInstance.getBusinessKey());
    assertThat(processCancelledEvent.getEntity().getStartDate()).isEqualTo(processInstance.getStartDate());
    assertThat(processCancelledEvent.getEntity().getInitiator()).isEqualTo(LOGGED_USER);
}
Also used : Task(org.activiti.api.task.model.Task) ProcessCancelledEvent(org.activiti.api.process.runtime.events.ProcessCancelledEvent) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 58 with Task

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

the class ProcessRuntimeBPMNErrorReceivedIT method should_CatchCallActivityBoundaryErrorEvent_When_ErrorEndEvenThrown.

@Test
public void should_CatchCallActivityBoundaryErrorEvent_When_ErrorEndEvenThrown() {
    securityUtil.logInAs("user");
    ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(ERROR_BOUNDARY_EVENT_CALLACTIVITY).build());
    assertThat(processInstance).isNotNull();
    checkProcessAndTask(processInstance.getId(), "Task");
    assertThat(listener.getErrorReceivedEvents()).isNotEmpty().extracting(BPMNErrorReceivedEvent::getEventType, BPMNErrorReceivedEvent::getProcessDefinitionId, BPMNErrorReceivedEvent::getProcessInstanceId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getElementId(), event -> event.getEntity().getActivityName(), event -> event.getEntity().getActivityType(), event -> event.getEntity().getErrorId(), event -> event.getEntity().getErrorCode()).contains(Tuple.tuple(BPMNErrorReceivedEvent.ErrorEvents.ERROR_RECEIVED, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "catchError", null, null, "errorId", "123"));
}
Also used : ProcessInstance(org.activiti.api.process.model.ProcessInstance) BeforeEach(org.junit.jupiter.api.BeforeEach) Pageable(org.activiti.api.runtime.shared.query.Pageable) Tuple(org.assertj.core.groups.Tuple) GetTasksPayloadBuilder(org.activiti.api.task.model.builders.GetTasksPayloadBuilder) 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) Import(org.springframework.context.annotation.Import) Page(org.activiti.api.runtime.shared.query.Page) ProcessPayloadBuilder(org.activiti.api.process.model.builders.ProcessPayloadBuilder) GetTasksPayload(org.activiti.api.task.model.payloads.GetTasksPayload) ProcessRuntime(org.activiti.api.process.runtime.ProcessRuntime) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProcessCleanUpUtil(org.activiti.spring.boot.test.util.ProcessCleanUpUtil) BPMNErrorReceivedEvent(org.activiti.api.process.model.events.BPMNErrorReceivedEvent) DummyBPMNErrorReceivedListener(org.activiti.spring.boot.process.listener.DummyBPMNErrorReceivedListener) TaskRuntime(org.activiti.api.task.runtime.TaskRuntime) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 59 with Task

use of org.activiti.api.task.model.Task 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 60 with Task

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

the class ProcessRuntimeBPMNErrorReceivedIT method should_StartSubProcess_When_ErrorEndEvenThrown.

@Test
public void should_StartSubProcess_When_ErrorEndEvenThrown() {
    securityUtil.logInAs("user");
    ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(ERROR_START_EVENT_SUBPROCESS).build());
    assertThat(processInstance).isNotNull();
    checkProcessAndTask(processInstance.getId(), "Task");
    assertThat(listener.getErrorReceivedEvents()).isNotEmpty().extracting(BPMNErrorReceivedEvent::getEventType, BPMNErrorReceivedEvent::getProcessDefinitionId, BPMNErrorReceivedEvent::getProcessInstanceId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getElementId(), event -> event.getEntity().getActivityName(), event -> event.getEntity().getActivityType(), event -> event.getEntity().getErrorId(), event -> event.getEntity().getErrorCode()).contains(Tuple.tuple(BPMNErrorReceivedEvent.ErrorEvents.ERROR_RECEIVED, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "subStart1", null, null, "errorId", "123"));
}
Also used : ProcessInstance(org.activiti.api.process.model.ProcessInstance) BeforeEach(org.junit.jupiter.api.BeforeEach) Pageable(org.activiti.api.runtime.shared.query.Pageable) Tuple(org.assertj.core.groups.Tuple) GetTasksPayloadBuilder(org.activiti.api.task.model.builders.GetTasksPayloadBuilder) 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) Import(org.springframework.context.annotation.Import) Page(org.activiti.api.runtime.shared.query.Page) ProcessPayloadBuilder(org.activiti.api.process.model.builders.ProcessPayloadBuilder) GetTasksPayload(org.activiti.api.task.model.payloads.GetTasksPayload) ProcessRuntime(org.activiti.api.process.runtime.ProcessRuntime) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProcessCleanUpUtil(org.activiti.spring.boot.test.util.ProcessCleanUpUtil) BPMNErrorReceivedEvent(org.activiti.api.process.model.events.BPMNErrorReceivedEvent) DummyBPMNErrorReceivedListener(org.activiti.spring.boot.process.listener.DummyBPMNErrorReceivedListener) TaskRuntime(org.activiti.api.task.runtime.TaskRuntime) 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)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