ToTaskCancelledConverter implements EventConverter<TaskCancelledEvent, ActivitiEntityEvent> { @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); } ToTaskCancelledConverter(APITaskConverter taskConverter); @Override Optional<TaskCancelledEvent> from(ActivitiEntityEvent internalEvent);  }
@Test public void should_returnConvertedTask_when_entityIsACancelledTask() { 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); TaskCancelledEvent convertedTaskCancelledEvent = eventConverter.from(internalEvent).orElse(null); assertThat(convertedTaskCancelledEvent).isNotNull(); assertThat(convertedTaskCancelledEvent.getEntity()).isEqualTo(apiTask); assertThat(convertedTaskCancelledEvent.getEventType()).isEqualTo(TaskRuntimeEvent.TaskEvents.TASK_CANCELLED); }
@Test public void should_ReturnEmpty_when_entityIsANonCancelledTask() { Task internalTask = taskEntityBuilder() .withCancelled(false) .build(); ActivitiEntityEventImpl internalEvent = new ActivitiEntityEventImpl(internalTask, ActivitiEventType.ENTITY_DELETED); Optional<TaskCancelledEvent> convertedTaskCancelledEvent = eventConverter.from(internalEvent); assertThat(convertedTaskCancelledEvent).isEmpty(); }
@Test public void should_returnEmpty_when_entityIsNotTask() { ActivitiEntityEventImpl internalEvent = new ActivitiEntityEventImpl(mock(ProcessInstance.class), ActivitiEventType.ENTITY_DELETED); Optional<TaskCancelledEvent> convertedTaskCancelledEvent = eventConverter.from(internalEvent); assertThat(convertedTaskCancelledEvent).isEmpty(); }