Search in sources :

Example 6 with Event

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

the class AggregateRepository method dispatch.

/**
     * Dispatches the passed command to an aggregate.
     *
     * <p>The aggregate ID is obtained from the passed command.
     *
     * <p>The repository loads the aggregate by this ID, or creates a new aggregate
     * if there is no aggregate with such ID.
     *
     * @param envelope the envelope of the command to dispatch
     */
@Override
public void dispatch(final CommandEnvelope envelope) {
    final Command command = envelope.getCommand();
    final CommandOperation op = new CommandOperation(command) {

        @Override
        public void run() {
            final AggregateCommandEndpoint<I, A> commandEndpoint = createFor(AggregateRepository.this, envelope);
            commandEndpoint.execute();
            final Optional<A> processedAggregate = commandEndpoint.getAggregate();
            if (!processedAggregate.isPresent()) {
                throw new IllegalStateException("No aggregate loaded for command: " + command);
            }
            final A aggregate = processedAggregate.get();
            final List<Event> events = aggregate.getUncommittedEvents();
            store(aggregate);
            stand.post(aggregate, command.getContext());
            postEvents(events);
        }
    };
    op.execute();
}
Also used : Command(io.spine.base.Command) GetTargetIdFromCommand(io.spine.server.entity.idfunc.GetTargetIdFromCommand) CommandOperation(io.spine.server.tenant.CommandOperation) Event(io.spine.base.Event)

Example 7 with Event

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

the class EventEnricherShould method confirm_that_event_can_not_be_enriched_if_enrichment_disabled.

@Test
public void confirm_that_event_can_not_be_enriched_if_enrichment_disabled() {
    final Event event = createEvent(Wrapper.forString(newUuid()));
    final Event notEnrichableEvent = event.toBuilder().setContext(event.getContext().toBuilder().setEnrichment(event.getContext().getEnrichment().toBuilder().setDoNotEnrich(true))).build();
    assertFalse(enricher.canBeEnriched(notEnrichableEvent));
}
Also used : Event(io.spine.base.Event) Test(org.junit.Test)

Example 8 with Event

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

the class EventEnricherShould method confirm_that_event_can_not_be_enriched_if_no_such_enrichment_registered.

@Test
public void confirm_that_event_can_not_be_enriched_if_no_such_enrichment_registered() {
    final Event dummyEvent = createEvent(Wrapper.forString(newUuid()));
    assertFalse(enricher.canBeEnriched(dummyEvent));
}
Also used : Event(io.spine.base.Event) Test(org.junit.Test)

Example 9 with Event

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

the class TypeNameShould method obtain_type_name_of_event.

@Test
public void obtain_type_name_of_event() {
    final Command command = requestFactory.command().create(newUuidValue());
    final StringValue producerId = Wrapper.forString(getClass().getSimpleName());
    final EventFactory ef = EventFactory.newBuilder().setCommandId(Commands.generateId()).setProducerId(producerId).setCommandContext(command.getContext()).build();
    final Event event = ef.createEvent(Time.getCurrentTime(), Tests.<Version>nullRef());
    final TypeName typeName = TypeName.ofEvent(event);
    assertNotNull(typeName);
    assertEquals(Timestamp.class.getSimpleName(), typeName.getSimpleName());
}
Also used : Command(io.spine.base.Command) EventFactory(io.spine.server.command.EventFactory) Event(io.spine.base.Event) StringValue(com.google.protobuf.StringValue) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 10 with Event

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

the class ProjectionRepositoryShould method checkDoesNotDispatchEventWith.

private void checkDoesNotDispatchEventWith(Status status) {
    repository().setStatus(status);
    final ProjectCreated eventMsg = projectCreated();
    final Event event = createEvent(PRODUCER_ID, eventMsg);
    repository().dispatch(event);
    assertFalse(TestProjection.processed(eventMsg));
}
Also used : Event(io.spine.base.Event) ProjectCreated(io.spine.test.projection.event.ProjectCreated)

Aggregations

Event (io.spine.base.Event)32 Test (org.junit.Test)14 Message (com.google.protobuf.Message)7 EventContext (io.spine.base.EventContext)4 IntegrationEvent (io.spine.server.integration.IntegrationEvent)4 StringValue (com.google.protobuf.StringValue)3 EventFactory (io.spine.server.command.EventFactory)3 TestEventFactory (io.spine.test.TestEventFactory)3 ProjectId (io.spine.test.projection.ProjectId)3 ProjectCreated (io.spine.test.projection.event.ProjectCreated)3 Duration (com.google.protobuf.Duration)2 Command (io.spine.base.Command)2 EventId (io.spine.base.EventId)2 EventStore (io.spine.server.event.EventStore)2 IntegrationEventContext (io.spine.server.integration.IntegrationEventContext)2 ImmutableCollection (com.google.common.collect.ImmutableCollection)1 Any (com.google.protobuf.Any)1 Timestamp (com.google.protobuf.Timestamp)1 CommandContext (io.spine.base.CommandContext)1 Events.getMessage (io.spine.base.Events.getMessage)1