Search in sources :

Example 16 with EventEnvelope

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

the class EventRoutingShould method apply_custom_route.

@Test
public void apply_custom_route() {
    eventRouting.route(StringValue.class, customRoute);
    // An event which has `StringValue` as its message, which should go the custom route.
    final EventEnvelope event = EventEnvelope.of(eventFactory.createEvent(TestValues.newUuidValue()));
    final Set<Long> ids = eventRouting.apply(event.getMessage(), event.getEventContext());
    assertEquals(CUSTOM_ROUTE, ids);
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) Test(org.junit.Test)

Example 17 with EventEnvelope

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

the class AggregateMessageDeliveryShould method postpone_events_dispatched_to_reactor_method.

@Test
public void postpone_events_dispatched_to_reactor_method() {
    assertNull(ReactingProject.getEventReceived());
    final Event event = projectStarted();
    boundedContext.getEventBus().post(event);
    assertNull(ReactingProject.getEventReceived());
    final EventEnvelope expectedEnvelope = EventEnvelope.of(event);
    final PostponingEventDelivery delivery = repository.getEventEndpointDelivery();
    final Map<ProjectId, EventEnvelope> postponedEvents = delivery.getPostponedEvents();
    assertTrue(postponedEvents.size() == 1 && postponedEvents.containsValue(expectedEnvelope));
    final ProjectId projectId = postponedEvents.keySet().iterator().next();
    delivery.deliverNow(projectId, postponedEvents.get(projectId));
    final AggProjectStarted deliveredEventMsg = ReactingProject.getEventReceived();
    assertNotNull(deliveredEventMsg);
    assertEquals(Events.getMessage(event), deliveredEventMsg);
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) ProjectId(io.spine.test.aggregate.ProjectId) Event(io.spine.core.Event) PostponingEventDelivery(io.spine.server.aggregate.given.AggregateMessageDeliveryTestEnv.PostponingEventDelivery) AggProjectStarted(io.spine.test.aggregate.event.AggProjectStarted) Test(org.junit.Test)

Example 18 with EventEnvelope

use of io.spine.core.EventEnvelope 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 EventEnvelope dummyEvent = EventEnvelope.of(createEvent(toMessage(newUuid())));
    assertFalse(enricher.canBeEnriched(dummyEvent));
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) Test(org.junit.Test)

Example 19 with EventEnvelope

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

the class EventSubscriberShould method catch_exceptions_caused_by_methods.

@Test
public void catch_exceptions_caused_by_methods() {
    // Create event which should fail.
    final EventEnvelope eventEnvelope = createEvent(false);
    final Set<String> dispatchingResult = subscriber.dispatch(eventEnvelope);
    final FailingSubscriber sub = (FailingSubscriber) this.subscriber;
    assertTrue(sub.isMethodCalled());
    assertEquals(0, dispatchingResult.size());
    assertEquals(eventEnvelope, sub.getLastErrorEnvelope());
    assertNotNull(sub.getLastException());
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) FailingSubscriber(io.spine.server.event.given.EventSubscriberTestEnv.FailingSubscriber) Test(org.junit.Test)

Example 20 with EventEnvelope

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

the class PmMessageDeliveryShould method postpone_events_dispatched_to_reactor_method.

@Test
public void postpone_events_dispatched_to_reactor_method() {
    assertNull(ReactingProjectWizard.getEventReceived());
    final Event event = projectStarted();
    boundedContext.getEventBus().post(event);
    assertNull(ReactingProjectWizard.getEventReceived());
    final EventEnvelope expectedEnvelope = EventEnvelope.of(event);
    final PostponingEventDelivery delivery = repository.getEventEndpointDelivery();
    final Map<ProjectId, EventEnvelope> postponedEvents = delivery.getPostponedEvents();
    assertTrue(postponedEvents.size() == 1 && postponedEvents.containsValue(expectedEnvelope));
    final ProjectId projectId = postponedEvents.keySet().iterator().next();
    delivery.deliverNow(projectId, postponedEvents.get(projectId));
    final PmProjectStarted deliveredEventMsg = ReactingProjectWizard.getEventReceived();
    assertNotNull(deliveredEventMsg);
    assertEquals(Events.getMessage(event), deliveredEventMsg);
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) ProjectId(io.spine.test.procman.ProjectId) Event(io.spine.core.Event) PmProjectStarted(io.spine.test.procman.event.PmProjectStarted) PostponingEventDelivery(io.spine.server.procman.given.PmMessageDeliveryTestEnv.PostponingEventDelivery) Test(org.junit.Test)

Aggregations

EventEnvelope (io.spine.core.EventEnvelope)24 Test (org.junit.Test)19 Event (io.spine.core.Event)9 StringValue (com.google.protobuf.StringValue)3 TestEventFactory (io.spine.server.command.TestEventFactory)3 GivenEvent (io.spine.server.event.given.EventBusTestEnv.GivenEvent)2 FailingSubscriber (io.spine.server.event.given.EventSubscriberTestEnv.FailingSubscriber)2 FloatValue (com.google.protobuf.FloatValue)1 Message (com.google.protobuf.Message)1 Command (io.spine.core.Command)1 EventClass (io.spine.core.EventClass)1 MessageEnvelope (io.spine.core.MessageEnvelope)1 GivenEvent (io.spine.core.given.GivenEvent)1 PostponingEventDelivery (io.spine.server.aggregate.given.AggregateMessageDeliveryTestEnv.PostponingEventDelivery)1 FailingAggregateRepository (io.spine.server.aggregate.given.AggregateRepositoryTestEnv.FailingAggregateRepository)1 EventCatcher (io.spine.server.event.given.CommandHandlerTestEnv.EventCatcher)1 GivenEvent (io.spine.server.event.given.EventEnricherTestEnv.GivenEvent)1 ExternalMessageClass (io.spine.server.integration.ExternalMessageClass)1 ExternalMessageDispatcher (io.spine.server.integration.ExternalMessageDispatcher)1 ExternalMessageEnvelope (io.spine.server.integration.ExternalMessageEnvelope)1