Search in sources :

Example 1 with EventFactory

use of io.spine.server.event.EventFactory in project core-java by SpineEventEngine.

the class EventsShould method setUp.

@Before
public void setUp() {
    final TestActorRequestFactory requestFactory = TestActorRequestFactory.newInstance(getClass());
    final CommandEnvelope cmd = requestFactory.generateEnvelope();
    final StringValue producerId = toMessage(getClass().getSimpleName());
    EventFactory eventFactory = EventFactory.on(cmd, Identifier.pack(producerId));
    event = eventFactory.createEvent(Time.getCurrentTime(), Tests.<Version>nullRef());
    context = event.getContext();
}
Also used : TestActorRequestFactory(io.spine.client.TestActorRequestFactory) EventFactory(io.spine.server.event.EventFactory) StringValue(com.google.protobuf.StringValue) Before(org.junit.Before)

Example 2 with EventFactory

use of io.spine.server.event.EventFactory in project core-java by SpineEventEngine.

the class EventsShould method obtain_type_name_of_event.

@Test
public void obtain_type_name_of_event() {
    final CommandEnvelope command = requestFactory.generateEnvelope();
    final StringValue producerId = toMessage(getClass().getSimpleName());
    final EventFactory ef = EventFactory.on(command, Identifier.pack(producerId));
    final Event event = ef.createEvent(Time.getCurrentTime(), Tests.<Version>nullRef());
    final TypeName typeName = EventEnvelope.of(event).getTypeName();
    assertNotNull(typeName);
    assertEquals(Timestamp.class.getSimpleName(), typeName.getSimpleName());
}
Also used : TypeName(io.spine.type.TypeName) EventFactory(io.spine.server.event.EventFactory) GivenEvent(io.spine.core.given.GivenEvent) StringValue(com.google.protobuf.StringValue) Timestamp(com.google.protobuf.Timestamp) Events.getTimestamp(io.spine.core.Events.getTimestamp) Test(org.junit.Test)

Example 3 with EventFactory

use of io.spine.server.event.EventFactory in project core-java by SpineEventEngine.

the class EventsShould method obtain_root_command_id.

@Test
public void obtain_root_command_id() {
    final CommandEnvelope command = requestFactory.generateEnvelope();
    final StringValue producerId = toMessage(getClass().getSimpleName());
    final EventFactory ef = EventFactory.on(command, Identifier.pack(producerId));
    final Event event = ef.createEvent(Time.getCurrentTime(), Tests.<Version>nullRef());
    assertEquals(command.getId(), Events.getRootCommandId(event));
}
Also used : EventFactory(io.spine.server.event.EventFactory) GivenEvent(io.spine.core.given.GivenEvent) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Example 4 with EventFactory

use of io.spine.server.event.EventFactory in project core-java by SpineEventEngine.

the class HandlerMethod method toEvents.

public static List<Event> toEvents(final Any producerId, @Nullable final Version version, final List<? extends Message> eventMessages, final MessageEnvelope origin) {
    checkNotNull(producerId);
    checkNotNull(eventMessages);
    checkNotNull(origin);
    final EventFactory eventFactory = EventFactory.on(origin, producerId);
    return Lists.transform(eventMessages, new Function<Message, Event>() {

        @Override
        public Event apply(@Nullable Message eventMessage) {
            checkNotNull(eventMessage);
            final Event result = eventFactory.createEvent(eventMessage, version);
            return result;
        }
    });
}
Also used : Message(com.google.protobuf.Message) EventFactory(io.spine.server.event.EventFactory) Event(io.spine.core.Event)

Example 5 with EventFactory

use of io.spine.server.event.EventFactory in project core-java by SpineEventEngine.

the class Given method validEvent.

static Event validEvent() {
    final Command cmd = validCommand();
    final PrjProjectCreated eventMessage = PrjProjectCreated.newBuilder().setProjectId(ProjectId.newBuilder().setId("12345AD0")).build();
    final StringValue producerId = toMessage(Given.class.getSimpleName());
    final EventFactory eventFactory = EventFactory.on(CommandEnvelope.of(cmd), Identifier.pack(producerId));
    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;
}
Also used : PrjProjectCreated(io.spine.test.projection.event.PrjProjectCreated) Command(io.spine.core.Command) EventFactory(io.spine.server.event.EventFactory) Event(io.spine.core.Event) StringValue(com.google.protobuf.StringValue)

Aggregations

EventFactory (io.spine.server.event.EventFactory)6 StringValue (com.google.protobuf.StringValue)4 Event (io.spine.core.Event)3 Message (com.google.protobuf.Message)2 GivenEvent (io.spine.core.given.GivenEvent)2 Test (org.junit.Test)2 Timestamp (com.google.protobuf.Timestamp)1 TestActorRequestFactory (io.spine.client.TestActorRequestFactory)1 Command (io.spine.core.Command)1 CommandEnvelope (io.spine.core.CommandEnvelope)1 Events.getMessage (io.spine.core.Events.getMessage)1 Events.getTimestamp (io.spine.core.Events.getTimestamp)1 Version (io.spine.core.Version)1 PrjProjectCreated (io.spine.test.projection.event.PrjProjectCreated)1 TypeName (io.spine.type.TypeName)1 Before (org.junit.Before)1