Search in sources :

Example 1 with CloudBPMNActivityStartedEvent

use of org.activiti.cloud.api.process.model.events.CloudBPMNActivityStartedEvent in project activiti-cloud by Activiti.

the class AuditServiceIT method unknownEventShouldNotPreventHandlingOfKnownEvents.

@Test
public void unknownEventShouldNotPreventHandlingOfKnownEvents() {
    // given
    CloudRuntimeEvent[] events = new CloudRuntimeEvent[2];
    BPMNActivityImpl bpmnActivityStarted = new BPMNActivityImpl();
    bpmnActivityStarted.setActivityName("first step");
    String eventId = "ActivityStartedEventId" + UUID.randomUUID().toString();
    CloudBPMNActivityStartedEventImpl cloudBPMNActivityStartedEvent = new CloudBPMNActivityStartedEventImpl(eventId, System.currentTimeMillis(), bpmnActivityStarted, "3", "4");
    events[0] = cloudBPMNActivityStartedEvent;
    events[1] = new CloudRuntimeEventImpl() {

        @Override
        public Enum<?> getEventType() {
            return IgnoredRuntimeEvent.IgnoredRuntimeEvents.IGNORED;
        }
    };
    producer.send(events);
    await().untilAsserted(() -> {
        // then
        ResponseEntity<PagedResources<CloudRuntimeEvent>> eventsPagedResources = eventsRestTemplate.executeFindAll();
        assertThat(eventsPagedResources.getBody()).isNotEmpty();
        Collection<CloudRuntimeEvent> retrievedEvents = eventsPagedResources.getBody().getContent();
        assertThat(retrievedEvents).hasSize(1);
        CloudRuntimeEvent event = retrievedEvents.iterator().next();
        // when
        assertThat(event).isInstanceOf(CloudBPMNActivityStartedEvent.class);
        CloudBPMNActivityStartedEvent cloudProcessStartedEvent = (CloudBPMNActivityStartedEvent) event;
        assertThat(cloudProcessStartedEvent.getEventType()).isEqualTo(BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
        assertThat(cloudProcessStartedEvent.getProcessDefinitionId()).isEqualTo("3");
        assertThat(cloudProcessStartedEvent.getProcessInstanceId()).isEqualTo("4");
        assertThat(cloudProcessStartedEvent.getEntity().getActivityName()).isEqualTo("first step");
    });
}
Also used : CloudRuntimeEventImpl(org.activiti.cloud.api.model.shared.impl.events.CloudRuntimeEventImpl) BPMNActivityImpl(org.activiti.api.runtime.model.impl.BPMNActivityImpl) PagedResources(org.springframework.hateoas.PagedResources) CloudBPMNActivityStartedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNActivityStartedEventImpl) CloudBPMNActivityStartedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNActivityStartedEvent) 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 CloudBPMNActivityStartedEvent

use of org.activiti.cloud.api.process.model.events.CloudBPMNActivityStartedEvent in project activiti-cloud by Activiti.

the class AuditServiceIT method findByIdShouldReturnTheEventIdentifiedByTheGivenId.

@Test
public void findByIdShouldReturnTheEventIdentifiedByTheGivenId() {
    // given
    CloudRuntimeEvent[] events = new CloudRuntimeEvent[1];
    BPMNActivityImpl bpmnActivityStarted = new BPMNActivityImpl();
    bpmnActivityStarted.setActivityName("first step");
    String eventId = "ActivityStartedEventId" + UUID.randomUUID().toString();
    CloudBPMNActivityStartedEventImpl cloudBPMNActivityStartedEvent = new CloudBPMNActivityStartedEventImpl(eventId, System.currentTimeMillis(), bpmnActivityStarted, "3", "4");
    events[0] = cloudBPMNActivityStartedEvent;
    producer.send(events);
    await().untilAsserted(() -> {
        // when
        ResponseEntity<CloudRuntimeEvent> responseEntity = eventsRestTemplate.executeFindById(eventId);
        // then
        CloudRuntimeEvent event = responseEntity.getBody();
        assertThat(event).isInstanceOf(CloudBPMNActivityStartedEvent.class);
        CloudBPMNActivityStartedEvent cloudProcessStartedEvent = (CloudBPMNActivityStartedEvent) event;
        assertThat(cloudProcessStartedEvent.getEventType()).isEqualTo(BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
        assertThat(cloudProcessStartedEvent.getProcessDefinitionId()).isEqualTo("3");
        assertThat(cloudProcessStartedEvent.getProcessInstanceId()).isEqualTo("4");
        assertThat(cloudProcessStartedEvent.getEntity().getActivityName()).isEqualTo("first step");
    });
}
Also used : BPMNActivityImpl(org.activiti.api.runtime.model.impl.BPMNActivityImpl) CloudBPMNActivityStartedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNActivityStartedEventImpl) CloudBPMNActivityStartedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNActivityStartedEvent) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with CloudBPMNActivityStartedEvent

use of org.activiti.cloud.api.process.model.events.CloudBPMNActivityStartedEvent in project activiti-cloud by Activiti.

the class AuditServiceIT method shouldBeAbleToFilterOnEventTypeActivitiStarted.

@Test
public void shouldBeAbleToFilterOnEventTypeActivitiStarted() {
    // 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", BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED.name()));
        // then
        Collection<CloudRuntimeEvent> retrievedEvents = eventsPagedResources.getBody().getContent();
        assertThat(retrievedEvents).hasSize(3);
        for (CloudRuntimeEvent event : retrievedEvents) {
            CloudBPMNActivityEvent cloudBPMNActivityEvent = (CloudBPMNActivityStartedEvent) event;
            assertThat(cloudBPMNActivityEvent.getEventType()).isEqualTo(BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
        }
    });
}
Also used : PagedResources(org.springframework.hateoas.PagedResources) CloudBPMNActivityEvent(org.activiti.cloud.api.process.model.events.CloudBPMNActivityEvent) CloudBPMNActivityStartedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNActivityStartedEvent) 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 CloudBPMNActivityStartedEvent

use of org.activiti.cloud.api.process.model.events.CloudBPMNActivityStartedEvent in project activiti-cloud by Activiti.

the class AuditServiceIT method shouldBeAbleToFilterOnProcessInstanceIdAndEventType.

@Test
public void shouldBeAbleToFilterOnProcessInstanceIdAndEventType() {
    // given
    List<CloudRuntimeEvent> coveredEvents = getTestEvents();
    producer.send(coveredEvents.toArray(new CloudRuntimeEvent[coveredEvents.size()]));
    await().untilAsserted(() -> {
        // when
        Map<String, Object> filters = new HashMap<>();
        filters.put("processInstanceId", "4");
        filters.put("eventType", BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED.name());
        ResponseEntity<PagedResources<CloudRuntimeEvent>> eventsPagedResources = eventsRestTemplate.executeFind(filters);
        // then
        Collection<CloudRuntimeEvent> retrievedEvents = eventsPagedResources.getBody().getContent();
        assertThat(retrievedEvents).hasSize(2);
        for (CloudRuntimeEvent event : retrievedEvents) {
            CloudBPMNActivityEvent cloudBPMNActivityEvent = (CloudBPMNActivityStartedEvent) event;
            assertThat(cloudBPMNActivityEvent.getEventType()).isEqualTo(BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
        }
    });
}
Also used : HashMap(java.util.HashMap) PagedResources(org.springframework.hateoas.PagedResources) CloudBPMNActivityEvent(org.activiti.cloud.api.process.model.events.CloudBPMNActivityEvent) CloudBPMNActivityStartedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNActivityStartedEvent) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with CloudBPMNActivityStartedEvent

use of org.activiti.cloud.api.process.model.events.CloudBPMNActivityStartedEvent in project activiti-cloud by Activiti.

the class BPMNActivityStartedEventHandler method handle.

@Override
public void handle(CloudRuntimeEvent<?, ?> event) {
    CloudBPMNActivityStartedEvent activityEvent = CloudBPMNActivityStartedEvent.class.cast(event);
    BPMNActivityEntity bpmnActivityEntity = findOrCreateBPMNActivityEntity(event);
    // Activity can be cyclical, so we just update the status and started date anyways
    bpmnActivityEntity.setStartedDate(new Date(activityEvent.getTimestamp()));
    bpmnActivityEntity.setStatus(BPMNActivityStatus.STARTED);
}
Also used : CloudBPMNActivityStartedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNActivityStartedEvent) BPMNActivityEntity(org.activiti.cloud.services.query.model.BPMNActivityEntity) Date(java.util.Date)

Aggregations

CloudBPMNActivityStartedEvent (org.activiti.cloud.api.process.model.events.CloudBPMNActivityStartedEvent)9 CloudRuntimeEvent (org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent)8 Test (org.junit.jupiter.api.Test)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 PagedResources (org.springframework.hateoas.PagedResources)6 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Stream (java.util.stream.Stream)4 ACTIVITY_COMPLETED (org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED)4 ACTIVITY_STARTED (org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED)4 CloudProcessInstance (org.activiti.cloud.api.process.model.CloudProcessInstance)4 CloudTask (org.activiti.cloud.api.task.model.CloudTask)4 ProcessInstanceRestTemplate (org.activiti.cloud.starter.tests.helper.ProcessInstanceRestTemplate)4 TaskRestTemplate (org.activiti.cloud.starter.tests.helper.TaskRestTemplate)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Assertions.tuple (org.assertj.core.api.Assertions.tuple)4 Awaitility.await (org.awaitility.Awaitility.await)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Value (org.springframework.beans.factory.annotation.Value)4 ResponseEntity (org.springframework.http.ResponseEntity)4