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