Search in sources :

Example 6 with EventContext

use of io.spine.base.EventContext in project core-java by SpineEventEngine.

the class EnrichmentsShould method return_all_event_enrichments.

@SuppressWarnings("OptionalGetWithoutIsPresent")
// We're sure the optional is populated in this method.
@Test
public void return_all_event_enrichments() {
    final EventContext context = newEventContextWithEnrichment(TypeName.of(stringValue).value(), stringValue);
    final Optional<Enrichment.Container> enrichments = Enrichments.getEnrichments(context);
    assertTrue(enrichments.isPresent());
    assertEquals(context.getEnrichment().getContainer(), enrichments.get());
}
Also used : EventsShould.newEventContext(io.spine.base.EventsShould.newEventContext) EventContext(io.spine.base.EventContext) Test(org.junit.Test)

Example 7 with EventContext

use of io.spine.base.EventContext in project core-java by SpineEventEngine.

the class EventDispatchingRepository method dispatch.

/**
     * Dispatches the passed event envelope to entities.
     *
     * @param envelope the event envelope to dispatch
     */
@Override
public void dispatch(EventEnvelope envelope) {
    final Message eventMessage = envelope.getMessage();
    final EventContext context = envelope.getEventContext();
    final Set<I> ids = findIds(eventMessage, context);
    final EventOperation op = new EventOperation(envelope.getOuterObject()) {

        @Override
        public void run() {
            for (I id : ids) {
                dispatchToEntity(id, eventMessage, context);
            }
        }
    };
    op.execute();
}
Also used : EventContext(io.spine.base.EventContext) Message(com.google.protobuf.Message) EventOperation(io.spine.server.tenant.EventOperation)

Example 8 with EventContext

use of io.spine.base.EventContext in project core-java by SpineEventEngine.

the class EnrichmentsShould method newEventContextWithEnrichment.

private static EventContext newEventContextWithEnrichment(String enrichmentKey, Message enrichment) {
    final Enrichment.Builder enrichments = Enrichment.newBuilder().setContainer(Enrichment.Container.newBuilder().putItems(enrichmentKey, pack(enrichment)));
    final EventContext context = newEventContext().toBuilder().setEnrichment(enrichments.build()).build();
    return context;
}
Also used : EventsShould.newEventContext(io.spine.base.EventsShould.newEventContext) EventContext(io.spine.base.EventContext)

Example 9 with EventContext

use of io.spine.base.EventContext in project core-java by SpineEventEngine.

the class EnrichmentsShould method return_optional_absent_if_no_needed_event_enrichment_when_getting_one.

@Test
public void return_optional_absent_if_no_needed_event_enrichment_when_getting_one() {
    final EventContext context = newEventContextWithEnrichment(TypeName.of(boolValue).value(), boolValue);
    assertFalse(Enrichments.getEnrichment(StringValue.class, context).isPresent());
}
Also used : EventsShould.newEventContext(io.spine.base.EventsShould.newEventContext) EventContext(io.spine.base.EventContext) Test(org.junit.Test)

Example 10 with EventContext

use of io.spine.base.EventContext in project core-java by SpineEventEngine.

the class EventFactory method createContext.

private static EventContext createContext(Any producerId, CommandContext commandContext, @Nullable Version version) {
    final Timestamp timestamp = getCurrentTime();
    final EventContext.Builder builder = EventContext.newBuilder().setTimestamp(timestamp).setCommandContext(commandContext).setProducerId(producerId);
    if (version != null) {
        builder.setVersion(version);
    }
    return builder.build();
}
Also used : IntegrationEventContext(io.spine.server.integration.IntegrationEventContext) EventContext(io.spine.base.EventContext) Timestamp(com.google.protobuf.Timestamp)

Aggregations

EventContext (io.spine.base.EventContext)12 EventsShould.newEventContext (io.spine.base.EventsShould.newEventContext)5 Test (org.junit.Test)5 Event (io.spine.base.Event)4 IntegrationEventContext (io.spine.server.integration.IntegrationEventContext)3 Message (com.google.protobuf.Message)2 IntegrationEvent (io.spine.server.integration.IntegrationEvent)2 Timestamp (com.google.protobuf.Timestamp)1 EventId (io.spine.base.EventId)1 Transaction (io.spine.server.entity.Transaction)1 IdSetEventFunction (io.spine.server.entity.idfunc.IdSetEventFunction)1 EventOperation (io.spine.server.tenant.EventOperation)1 ProjectId (io.spine.test.projection.ProjectId)1 ProjectCreated (io.spine.test.projection.event.ProjectCreated)1