use of org.activiti.cloud.api.task.model.events.CloudTaskCancelledEvent in project activiti-cloud by Activiti.
the class AuditServiceIT method shouldBeAbleToFilterOnEventTypeTaskCancelled.
@Test
public void shouldBeAbleToFilterOnEventTypeTaskCancelled() {
// given
List<CloudRuntimeEvent> coveredEvents = getTestEvents();
producer.send(coveredEvents.toArray(new CloudRuntimeEvent[coveredEvents.size()]));
await().untilAsserted(() -> {
// when
ResponseEntity<PagedResources<CloudRuntimeEvent>> eventsPagedResources = eventsRestTemplate.executeFind(Collections.singletonMap("eventType", TaskRuntimeEvent.TaskEvents.TASK_CANCELLED.name()));
// then
Collection<CloudRuntimeEvent> retrievedEvents = eventsPagedResources.getBody().getContent();
assertThat(retrievedEvents).hasSize(1);
CloudTaskCancelledEvent cloudBPMNTaskCancelled = (CloudTaskCancelledEvent) retrievedEvents.iterator().next();
assertThat(cloudBPMNTaskCancelled.getEventType()).isEqualTo(TaskRuntimeEvent.TaskEvents.TASK_CANCELLED);
assertThat(cloudBPMNTaskCancelled.getEntityId()).isEqualTo("1234-abc-5678-def");
assertThat(cloudBPMNTaskCancelled.getEntity()).isInstanceOf(Task.class);
assertThat(cloudBPMNTaskCancelled.getEntity().getId()).isEqualTo("1234-abc-5678-def");
});
}
use of org.activiti.cloud.api.task.model.events.CloudTaskCancelledEvent in project activiti-cloud by Activiti.
the class TaskEntityCancelledEventHandlerTest method handleShouldThrowExceptionWhenTaskNotFound.
@Test
public void handleShouldThrowExceptionWhenTaskNotFound() {
// given
CloudTaskCancelledEvent event = buildTaskCancelledEvent();
String taskId = event.getEntity().getId();
given(taskRepository.findById(taskId)).willReturn(Optional.empty());
// then
// when
assertThatExceptionOfType(QueryException.class).isThrownBy(() -> handler.handle(event)).withMessageContaining("Unable to find task with id: " + taskId);
}
use of org.activiti.cloud.api.task.model.events.CloudTaskCancelledEvent in project activiti-cloud by Activiti.
the class AuditProducerIT method shouldEmitEventsForTaskDelete.
@Test
public void shouldEmitEventsForTaskDelete() {
// given
CloudTask task = taskRestTemplate.createTask(TaskPayloadBuilder.create().withName("my task name").withDescription("long description here").withCandidateUsers("hruser").build());
// when
taskRestTemplate.delete(task);
// then
await().untilAsserted(() -> {
List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getAllReceivedEvents();
CloudRuntimeEvent<?, ?> cloudTaskCancelledEvent = receivedEvents.stream().filter(cloudRuntimeEvent -> cloudRuntimeEvent instanceof CloudTaskCancelledEvent && cloudRuntimeEvent.getEntityId().equals(task.getId())).findFirst().orElse(null);
assertThat(cloudTaskCancelledEvent).isNotNull();
assertThat(cloudTaskCancelledEvent.getEventType()).isEqualTo(TASK_CANCELLED);
Task cancelledTask = (Task) cloudTaskCancelledEvent.getEntity();
assertThat(cancelledTask.getStatus()).isEqualTo(Task.TaskStatus.CANCELLED);
assertThat(cancelledTask.getName()).isEqualTo(task.getName());
assertThat(cancelledTask.getId()).isEqualTo(task.getId());
CloudRuntimeEvent<?, ?> cloudTaskCandidateUserRemoved = receivedEvents.stream().filter(cloudRuntimeEvent -> cloudRuntimeEvent instanceof CloudTaskCandidateUserRemovedEvent && ((TaskCandidateUser) cloudRuntimeEvent.getEntity()).getTaskId().equals(task.getId())).findFirst().orElse(null);
assertThat(cloudTaskCandidateUserRemoved).isNotNull();
assertThat(cloudTaskCandidateUserRemoved.getEntityId()).isEqualTo("hruser");
assertThat(cloudTaskCandidateUserRemoved.getEventType()).isEqualTo(TASK_CANDIDATE_USER_REMOVED);
TaskCandidateUser taskCandidateUser = (TaskCandidateUser) cloudTaskCandidateUserRemoved.getEntity();
assertThat(taskCandidateUser.getUserId()).isEqualTo("hruser");
assertThat(taskCandidateUser.getTaskId()).isEqualTo(task.getId());
});
}
use of org.activiti.cloud.api.task.model.events.CloudTaskCancelledEvent in project activiti-cloud by Activiti.
the class TaskCancelledEventHandler method handle.
@Override
public void handle(CloudRuntimeEvent<?, ?> event) {
CloudTaskCancelledEvent taskCancelledEvent = (CloudTaskCancelledEvent) event;
Task eventTask = taskCancelledEvent.getEntity();
updateTaskStatus(taskRepository.findById(eventTask.getId()).orElseThrow(() -> new QueryException("Unable to find task with id: " + eventTask.getId())), taskCancelledEvent.getTimestamp());
}
use of org.activiti.cloud.api.task.model.events.CloudTaskCancelledEvent in project activiti-cloud by Activiti.
the class TaskEntityCancelledEventHandlerTest method handleShouldUpdateTaskStatusToCancelled.
@Test
public void handleShouldUpdateTaskStatusToCancelled() {
// given
CloudTaskCancelledEvent event = buildTaskCancelledEvent();
String taskId = event.getEntity().getId();
TaskEntity taskEntity = aTask().withId(taskId).build();
given(taskRepository.findById(taskId)).willReturn(Optional.of(taskEntity));
// when
handler.handle(event);
// then
verify(taskRepository).save(taskEntity);
verify(taskEntity).setStatus(Task.TaskStatus.CANCELLED);
verify(taskEntity).setLastModified(any(Date.class));
}
Aggregations