Search in sources :

Example 1 with CloudRuntimeEventImpl

use of org.activiti.cloud.api.model.shared.impl.events.CloudRuntimeEventImpl 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 CloudRuntimeEventImpl

use of org.activiti.cloud.api.model.shared.impl.events.CloudRuntimeEventImpl in project activiti-cloud by Activiti.

the class AuditConsumerChannelHandlerImpl method receiveCloudRuntimeEvent.

@SuppressWarnings("unchecked")
@Override
@StreamListener(AuditConsumerChannels.AUDIT_CONSUMER)
public void receiveCloudRuntimeEvent(@Headers Map<String, Object> headers, CloudRuntimeEvent<?, ?>... events) {
    if (events != null) {
        AtomicInteger counter = new AtomicInteger(0);
        for (CloudRuntimeEvent event : events) {
            EventToEntityConverter converter = eventConverters.getConverterByEventTypeName(event.getEventType().name());
            if (converter != null) {
                ((CloudRuntimeEventImpl) event).setMessageId((headers.get(MessageHeaders.ID).toString()));
                ((CloudRuntimeEventImpl) event).setSequenceNumber(counter.getAndIncrement());
                eventsRepository.save((AuditEventEntity) converter.convertToEntity(event));
            } else {
                LOGGER.warn(">>> Ignoring CloudRuntimeEvents type: " + event.getEventType().name());
            }
        }
    }
}
Also used : CloudRuntimeEventImpl(org.activiti.cloud.api.model.shared.impl.events.CloudRuntimeEventImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EventToEntityConverter(org.activiti.cloud.services.audit.api.converters.EventToEntityConverter) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) StreamListener(org.springframework.cloud.stream.annotation.StreamListener)

Example 3 with CloudRuntimeEventImpl

use of org.activiti.cloud.api.model.shared.impl.events.CloudRuntimeEventImpl in project activiti-cloud by Activiti.

the class AuditConsumerChannelHandlerImplTest method messageIdShouldBeSet.

@Test
public void messageIdShouldBeSet() {
    // given
    CloudRuntimeEvent cloudRuntimeEvent = mock(CloudRuntimeEventImpl.class);
    when(cloudRuntimeEvent.getEventType()).thenReturn(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED);
    EventToEntityConverter converter = mock(EventToEntityConverter.class);
    when(converters.getConverterByEventTypeName(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED.name())).thenReturn(converter);
    AuditEventEntity entity = mock(AuditEventEntity.class);
    when(converter.convertToEntity(cloudRuntimeEvent)).thenReturn(entity);
    CloudRuntimeEvent[] events = { cloudRuntimeEvent };
    HashMap<String, Object> headers = new HashMap<>();
    headers.put("id", UUID.randomUUID());
    // when
    handler.receiveCloudRuntimeEvent(headers, events);
    // then
    verify((CloudRuntimeEventImpl) cloudRuntimeEvent).setMessageId(headers.get("id").toString());
}
Also used : CloudRuntimeEventImpl(org.activiti.cloud.api.model.shared.impl.events.CloudRuntimeEventImpl) HashMap(java.util.HashMap) EventToEntityConverter(org.activiti.cloud.services.audit.api.converters.EventToEntityConverter) AuditEventEntity(org.activiti.cloud.services.audit.jpa.events.AuditEventEntity) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Test(org.junit.jupiter.api.Test)

Aggregations

CloudRuntimeEvent (org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent)3 CloudRuntimeEventImpl (org.activiti.cloud.api.model.shared.impl.events.CloudRuntimeEventImpl)3 EventToEntityConverter (org.activiti.cloud.services.audit.api.converters.EventToEntityConverter)2 Test (org.junit.jupiter.api.Test)2 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BPMNActivityImpl (org.activiti.api.runtime.model.impl.BPMNActivityImpl)1 CloudBPMNActivityStartedEvent (org.activiti.cloud.api.process.model.events.CloudBPMNActivityStartedEvent)1 CloudBPMNActivityStartedEventImpl (org.activiti.cloud.api.process.model.impl.events.CloudBPMNActivityStartedEventImpl)1 AuditEventEntity (org.activiti.cloud.services.audit.jpa.events.AuditEventEntity)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 StreamListener (org.springframework.cloud.stream.annotation.StreamListener)1 PagedResources (org.springframework.hateoas.PagedResources)1