Search in sources :

Example 1 with CloudTaskCancelledEvent

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");
    });
}
Also used : CloudTaskCancelledEvent(org.activiti.cloud.api.task.model.events.CloudTaskCancelledEvent) PagedResources(org.springframework.hateoas.PagedResources) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with CloudTaskCancelledEvent

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);
}
Also used : CloudTaskCancelledEvent(org.activiti.cloud.api.task.model.events.CloudTaskCancelledEvent) Test(org.junit.jupiter.api.Test)

Example 3 with CloudTaskCancelledEvent

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());
    });
}
Also used : CloudTask(org.activiti.cloud.api.task.model.CloudTask) CloudTaskCandidateUserRemovedEvent(org.activiti.cloud.api.task.model.events.CloudTaskCandidateUserRemovedEvent) CloudTaskCancelledEvent(org.activiti.cloud.api.task.model.events.CloudTaskCancelledEvent) Task(org.activiti.api.task.model.Task) CloudTask(org.activiti.cloud.api.task.model.CloudTask) TaskCandidateUser(org.activiti.api.task.model.TaskCandidateUser) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with CloudTaskCancelledEvent

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());
}
Also used : CloudTaskCancelledEvent(org.activiti.cloud.api.task.model.events.CloudTaskCancelledEvent) Task(org.activiti.api.task.model.Task) QueryException(org.activiti.cloud.services.query.model.QueryException)

Example 5 with CloudTaskCancelledEvent

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));
}
Also used : CloudTaskCancelledEvent(org.activiti.cloud.api.task.model.events.CloudTaskCancelledEvent) TaskEntity(org.activiti.cloud.services.query.model.TaskEntity) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

CloudTaskCancelledEvent (org.activiti.cloud.api.task.model.events.CloudTaskCancelledEvent)5 Test (org.junit.jupiter.api.Test)4 Task (org.activiti.api.task.model.Task)2 CloudRuntimeEvent (org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Date (java.util.Date)1 TaskCandidateUser (org.activiti.api.task.model.TaskCandidateUser)1 CloudTask (org.activiti.cloud.api.task.model.CloudTask)1 CloudTaskCandidateUserRemovedEvent (org.activiti.cloud.api.task.model.events.CloudTaskCandidateUserRemovedEvent)1 QueryException (org.activiti.cloud.services.query.model.QueryException)1 TaskEntity (org.activiti.cloud.services.query.model.TaskEntity)1 PagedResources (org.springframework.hateoas.PagedResources)1