use of io.spine.base.EventContext in project core-java by SpineEventEngine.
the class TestEventFactory method createEvent.
/**
* Creates an event produced at the passed time.
*/
public Event createEvent(Message messageOrAny, @Nullable Version version, Timestamp atTime) {
final Event event = createEvent(messageOrAny, version);
final EventContext context = event.getContext().toBuilder().setTimestamp(atTime).build();
final Event result = event.toBuilder().setContext(context).build();
return result;
}
use of io.spine.base.EventContext in project core-java by SpineEventEngine.
the class TestTransaction method injectState.
/**
* A hack allowing to inject state and version into an {@code EventPlayingEntity} instance
* by creating and committing a fake transaction.
*
* <p>To be used in tests only.
*/
public static void injectState(EventPlayingEntity entity, Message state, Version version) {
@SuppressWarnings("unchecked") final Transaction tx = new Transaction(entity, state, version) {
@Override
protected void dispatch(EventPlayingEntity entity, Message eventMessage, EventContext context) throws InvocationTargetException {
// do nothing.
}
};
tx.commit();
}
use of io.spine.base.EventContext in project core-java by SpineEventEngine.
the class ProjectionRepositoryShould method use_id_set_function.
@Test
public void use_id_set_function() {
final IdSetEventFunction<ProjectId, ProjectCreated> delegateFn = new IdSetEventFunction<ProjectId, ProjectCreated>() {
@Override
public Set<ProjectId> apply(ProjectCreated message, EventContext context) {
return newHashSet();
}
};
final IdSetEventFunction<ProjectId, ProjectCreated> idSetFunction = spy(delegateFn);
repository().addIdSetFunction(ProjectCreated.class, idSetFunction);
final Event event = createEvent(PRODUCER_ID, projectCreated());
repository().dispatch(event);
final ProjectCreated expectedEventMessage = Events.getMessage(event);
final EventContext context = event.getContext();
verify(idSetFunction).apply(eq(expectedEventMessage), eq(context));
}
use of io.spine.base.EventContext in project core-java by SpineEventEngine.
the class EnrichmentsShould method return_specific_event_enrichment.
@SuppressWarnings("OptionalGetWithoutIsPresent")
// We're sure the optional is populated in this method.
@Test
public void return_specific_event_enrichment() {
final EventContext context = newEventContextWithEnrichment(TypeName.of(stringValue).value(), stringValue);
final Optional<? extends StringValue> enrichment = Enrichments.getEnrichment(stringValue.getClass(), context);
assertTrue(enrichment.isPresent());
assertEquals(stringValue, enrichment.get());
}
use of io.spine.base.EventContext in project core-java by SpineEventEngine.
the class EnrichmentsShould method return_false_if_event_enrichment_is_disabled.
@Test
public void return_false_if_event_enrichment_is_disabled() {
final EventContext withDisabledEnrichment = context.toBuilder().setEnrichment(Enrichment.newBuilder().setDoNotEnrich(true)).build();
final Event event = EventTests.createEvent(stringValue, withDisabledEnrichment);
assertFalse(isEnrichmentEnabled(event));
}
Aggregations