use of io.spine.server.command.EventFactory 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.server.command.EventFactory in project core-java by SpineEventEngine.
the class EventsShould method setUp.
@Before
public void setUp() {
final TestActorRequestFactory requestFactory = TestActorRequestFactory.newInstance(getClass());
final Command cmd = requestFactory.command().create(Time.getCurrentTime());
final StringValue producerId = Wrapper.forString(getClass().getSimpleName());
EventFactory eventFactory = EventFactory.newBuilder().setCommandId(Commands.generateId()).setProducerId(producerId).setCommandContext(cmd.getContext()).build();
event = eventFactory.createEvent(Time.getCurrentTime(), Tests.<Version>nullRef());
context = event.getContext();
}
use of io.spine.server.command.EventFactory in project core-java by SpineEventEngine.
the class Aggregate method applyMessages.
/**
* Applies the passed event message or {@code Event} to the aggregate.
*
* @param eventMessages the event messages or events to apply
* @param envelope the envelope of the command which generated the events
* @see #ensureEventMessage(Message)
*/
private void applyMessages(Iterable<? extends Message> eventMessages, CommandEnvelope envelope) {
final List<? extends Message> messages = newArrayList(eventMessages);
final EventFactory eventFactory = createEventFactory(envelope, messages.size());
final List<Event> events = newArrayListWithCapacity(messages.size());
Version projectedEventVersion = getVersion();
for (Message eventOrMessage : messages) {
// Applying each message would increment the entity version.
// Therefore we should simulate this behaviour.
projectedEventVersion = Versions.increment(projectedEventVersion);
final Message eventMessage = ensureEventMessage(eventOrMessage);
final Event event;
if (eventOrMessage instanceof Event) {
event = importEvent((Event) eventOrMessage, envelope.getCommandContext(), projectedEventVersion);
} else {
event = eventFactory.createEvent(eventMessage, projectedEventVersion);
}
events.add(event);
}
play(events);
uncommittedEvents.addAll(events);
}
use of io.spine.server.command.EventFactory in project core-java by SpineEventEngine.
the class Given method validEvent.
static Event validEvent() {
final Command cmd = validCommand();
final ProjectCreated eventMessage = ProjectCreated.newBuilder().setProjectId(ProjectId.newBuilder().setId("12345AD0")).build();
final StringValue producerId = Wrapper.forString(Given.class.getSimpleName());
final EventFactory eventFactory = EventFactory.newBuilder().setCommandId(cmd.getId()).setProducerId(producerId).setCommandContext(cmd.getContext()).build();
final Event event = eventFactory.createEvent(eventMessage, Tests.<Version>nullRef());
final Event result = event.toBuilder().setContext(event.getContext().toBuilder().setEnrichment(Enrichment.newBuilder().setDoNotEnrich(true)).build()).build();
return result;
}
use of io.spine.server.command.EventFactory in project core-java by SpineEventEngine.
the class CommandHandlerMethod method toEvents.
public static List<Event> toEvents(final Any producerId, @Nullable final Version version, final List<? extends Message> eventMessages, final CommandEnvelope envelope) {
checkNotNull(producerId);
checkNotNull(eventMessages);
checkNotNull(envelope);
final EventFactory eventFactory = EventFactory.newBuilder().setCommandId(envelope.getCommandId()).setProducerId(producerId).setMaxEventCount(eventMessages.size()).setCommandContext(envelope.getCommandContext()).build();
return Lists.transform(eventMessages, new Function<Message, Event>() {
@Override
public Event apply(@Nullable Message eventMessage) {
if (eventMessage == null) {
return Event.getDefaultInstance();
}
final Event result = eventFactory.createEvent(eventMessage, version);
return result;
}
});
}
Aggregations