Search in sources :

Example 1 with EventContext

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;
}
Also used : EventContext(io.spine.core.EventContext) IntegrationEventContext(io.spine.server.integration.IntegrationEventContext) IntegrationEventContext(io.spine.server.integration.IntegrationEventContext) Event(io.spine.core.Event) IntegrationEvent(io.spine.server.integration.IntegrationEvent)

Example 2 with EventContext

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));
}
Also used : EventContext(io.spine.core.EventContext) Event(io.spine.core.Event) Any(com.google.protobuf.Any)

Example 3 with EventContext

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()));
}
Also used : EventContext(io.spine.core.EventContext) Event(io.spine.core.Event) Test(org.junit.Test)

Example 4 with EventContext

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()));
}
Also used : EventContext(io.spine.core.EventContext) Event(io.spine.core.Event) Test(org.junit.Test)

Example 5 with EventContext

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));
}
Also used : EventContext(io.spine.core.EventContext) CommandContext(io.spine.core.CommandContext) GivenEvent(io.spine.core.given.GivenEvent) Event(io.spine.core.Event)

Aggregations

EventContext (io.spine.core.EventContext)16 Event (io.spine.core.Event)12 Test (org.junit.Test)6 Timestamp (com.google.protobuf.Timestamp)3 IntegrationEventContext (io.spine.server.integration.IntegrationEventContext)3 CommandContext (io.spine.core.CommandContext)2 IntegrationEvent (io.spine.server.integration.IntegrationEvent)2 Any (com.google.protobuf.Any)1 Message (com.google.protobuf.Message)1 TextFormat.shortDebugString (com.google.protobuf.TextFormat.shortDebugString)1 ActorContext (io.spine.core.ActorContext)1 EventId (io.spine.core.EventId)1 RejectionContext (io.spine.core.RejectionContext)1 TenantId (io.spine.core.TenantId)1 GivenEvent (io.spine.core.given.GivenEvent)1