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