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");
});
}
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());
}
}
}
}
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());
}
Aggregations