use of io.spine.core.EventContext in project core-java by SpineEventEngine.
the class EventFactory method toEvent.
/**
* Creates an event based on the passed integration event.
*/
public static Event toEvent(IntegrationEvent integrationEvent) {
final IntegrationEventContext sourceContext = integrationEvent.getContext();
final EventContext context = toEventContext(sourceContext);
final Event result = createEvent(sourceContext.getEventId(), integrationEvent.getMessage(), context);
return result;
}
use of io.spine.core.EventContext in project core-java by SpineEventEngine.
the class EventBusAdapter method markExternal.
@Override
ExternalMessageEnvelope markExternal(ExternalMessage externalMsg) {
final Any packedEvent = externalMsg.getOriginalMessage();
final Event event = AnyPacker.unpack(packedEvent);
final Event.Builder eventBuilder = event.toBuilder();
final EventContext modifiedContext = eventBuilder.getContext().toBuilder().setExternal(true).build();
final Event marked = eventBuilder.setContext(modifiedContext).build();
final ExternalMessage result = ExternalMessages.of(marked, externalMsg.getBoundedContextName());
return ExternalMessageEnvelope.of(result, Events.getMessage(event));
}
use of io.spine.core.EventContext in project core-java by SpineEventEngine.
the class EventStoreShould method not_store_enrichment_for_EventContext.
@Test
public void not_store_enrichment_for_EventContext() {
final Event event = projectCreated(Time.getCurrentTime());
final Event enriched = event.toBuilder().setContext(event.getContext().toBuilder().setEnrichment(withOneAttribute())).build();
eventStore.append(enriched);
final MemoizingObserver<Event> observer = memoizingObserver();
eventStore.read(EventStreamQuery.getDefaultInstance(), observer);
final EventContext context = observer.responses().get(0).getContext();
assertTrue(isDefault(context.getEnrichment()));
}
use of io.spine.core.EventContext in project core-java by SpineEventEngine.
the class EventStoreShould method not_store_enrichment_for_origin_of_EventContext_type.
@Test
public void not_store_enrichment_for_origin_of_EventContext_type() {
final EventContext.Builder originContext = EventContext.newBuilder().setEnrichment(withOneAttribute());
final Event event = projectCreated(Time.getCurrentTime());
final Event enriched = event.toBuilder().setContext(event.getContext().toBuilder().setEventContext(originContext)).build();
eventStore.append(enriched);
final MemoizingObserver<Event> observer = memoizingObserver();
eventStore.read(EventStreamQuery.getDefaultInstance(), observer);
final EventContext loadedOriginContext = observer.responses().get(0).getContext().getEventContext();
assertTrue(isDefault(loadedOriginContext.getEnrichment()));
}
use of io.spine.core.EventContext in project core-java by SpineEventEngine.
the class ProcessManagerRepositoryShould method testDispatchEvent.
private void testDispatchEvent(Message eventMessage) {
final CommandContext commandContext = requestFactory.createCommandContext();
// EventContext should have CommandContext with appropriate TenantId to avoid usage
// of different storages during command and event dispatching.
final EventContext eventContextWithTenantId = GivenEvent.context().toBuilder().setCommandContext(commandContext).build();
final Event event = GivenEvent.withMessage(eventMessage).toBuilder().setContext(eventContextWithTenantId).build();
repository().dispatch(EventEnvelope.of(event));
assertTrue(TestProcessManager.processed(eventMessage));
}
Aggregations