Search in sources :

Example 1 with EventContext

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

Example 2 with EventContext

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();
}
Also used : EventContext(io.spine.base.EventContext) Transaction(io.spine.server.entity.Transaction) Message(com.google.protobuf.Message)

Example 3 with EventContext

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));
}
Also used : EventContext(io.spine.base.EventContext) ProjectId(io.spine.test.projection.ProjectId) Event(io.spine.base.Event) IdSetEventFunction(io.spine.server.entity.idfunc.IdSetEventFunction) ProjectCreated(io.spine.test.projection.event.ProjectCreated) Test(org.junit.Test)

Example 4 with EventContext

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

Example 5 with EventContext

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

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