Search in sources :

Example 1 with TaskCancelledEvent

use of org.activiti.api.task.runtime.events.TaskCancelledEvent in project Activiti by Activiti.

the class ToTaskCancelledConverterTest method should_ReturnEmpty_when_entityIsANonCancelledTask.

@Test
public void should_ReturnEmpty_when_entityIsANonCancelledTask() {
    // given
    Task internalTask = taskEntityBuilder().withCancelled(false).build();
    ActivitiEntityEventImpl internalEvent = new ActivitiEntityEventImpl(internalTask, ActivitiEventType.ENTITY_DELETED);
    // when
    Optional<TaskCancelledEvent> convertedTaskCancelledEvent = eventConverter.from(internalEvent);
    // then
    assertThat(convertedTaskCancelledEvent).isEmpty();
}
Also used : Task(org.activiti.engine.task.Task) ActivitiEntityEventImpl(org.activiti.engine.delegate.event.impl.ActivitiEntityEventImpl) TaskCancelledEvent(org.activiti.api.task.runtime.events.TaskCancelledEvent) Test(org.junit.jupiter.api.Test)

Example 2 with TaskCancelledEvent

use of org.activiti.api.task.runtime.events.TaskCancelledEvent in project Activiti by Activiti.

the class ToTaskCancelledConverterTest method should_returnConvertedTask_when_entityIsACancelledTask.

@Test
public void should_returnConvertedTask_when_entityIsACancelledTask() {
    // given
    Task internalTask = taskEntityBuilder().withCancelled(true).build();
    ActivitiEntityEventImpl internalEvent = new ActivitiEntityEventImpl(internalTask, ActivitiEventType.ENTITY_DELETED);
    TaskImpl apiTask = new TaskImpl("id", "myTask", org.activiti.api.task.model.Task.TaskStatus.CANCELLED);
    given(taskConverter.from(internalTask, org.activiti.api.task.model.Task.TaskStatus.CANCELLED)).willReturn(apiTask);
    // when
    TaskCancelledEvent convertedTaskCancelledEvent = eventConverter.from(internalEvent).orElse(null);
    // then
    assertThat(convertedTaskCancelledEvent).isNotNull();
    assertThat(convertedTaskCancelledEvent.getEntity()).isEqualTo(apiTask);
    assertThat(convertedTaskCancelledEvent.getEventType()).isEqualTo(TaskRuntimeEvent.TaskEvents.TASK_CANCELLED);
}
Also used : Task(org.activiti.engine.task.Task) ActivitiEntityEventImpl(org.activiti.engine.delegate.event.impl.ActivitiEntityEventImpl) TaskImpl(org.activiti.api.task.model.impl.TaskImpl) TaskCancelledEvent(org.activiti.api.task.runtime.events.TaskCancelledEvent) Test(org.junit.jupiter.api.Test)

Example 3 with TaskCancelledEvent

use of org.activiti.api.task.runtime.events.TaskCancelledEvent in project Activiti by Activiti.

the class ToTaskCancelledConverterTest method should_returnEmpty_when_entityIsNotTask.

@Test
public void should_returnEmpty_when_entityIsNotTask() {
    // given
    ActivitiEntityEventImpl internalEvent = new ActivitiEntityEventImpl(mock(ProcessInstance.class), ActivitiEventType.ENTITY_DELETED);
    // when
    Optional<TaskCancelledEvent> convertedTaskCancelledEvent = eventConverter.from(internalEvent);
    // then
    assertThat(convertedTaskCancelledEvent).isEmpty();
}
Also used : ActivitiEntityEventImpl(org.activiti.engine.delegate.event.impl.ActivitiEntityEventImpl) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) TaskCancelledEvent(org.activiti.api.task.runtime.events.TaskCancelledEvent) Test(org.junit.jupiter.api.Test)

Example 4 with TaskCancelledEvent

use of org.activiti.api.task.runtime.events.TaskCancelledEvent 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)

Example 5 with TaskCancelledEvent

use of org.activiti.api.task.runtime.events.TaskCancelledEvent in project Activiti by Activiti.

the class ToTaskCancelledConverter method from.

@Override
public Optional<TaskCancelledEvent> from(ActivitiEntityEvent internalEvent) {
    TaskCancelledEvent event = null;
    if (isTaskCancelled(internalEvent)) {
        TaskEntity taskEntity = (TaskEntity) internalEvent.getEntity();
        Task task = taskConverter.from(taskEntity, Task.TaskStatus.CANCELLED);
        String reason = internalEvent.getReason();
        event = new TaskCancelledImpl(task, reason);
    }
    return Optional.ofNullable(event);
}
Also used : Task(org.activiti.api.task.model.Task) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) TaskCancelledEvent(org.activiti.api.task.runtime.events.TaskCancelledEvent)

Aggregations

TaskCancelledEvent (org.activiti.api.task.runtime.events.TaskCancelledEvent)5 Test (org.junit.jupiter.api.Test)4 ActivitiEntityEventImpl (org.activiti.engine.delegate.event.impl.ActivitiEntityEventImpl)3 Task (org.activiti.api.task.model.Task)2 Task (org.activiti.engine.task.Task)2 ProcessInstance (org.activiti.api.process.model.ProcessInstance)1 TaskImpl (org.activiti.api.task.model.impl.TaskImpl)1 TaskEntity (org.activiti.engine.impl.persistence.entity.TaskEntity)1 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1