Search in sources :

Example 6 with EventEnvelope

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

the class EventBusShould method enrich_event_if_it_can_be_enriched.

@Test
public void enrich_event_if_it_can_be_enriched() {
    final EventEnricher enricher = mock(EventEnricher.class);
    final EventEnvelope event = EventEnvelope.of(GivenEvent.projectCreated());
    doReturn(true).when(enricher).canBeEnriched(any(EventEnvelope.class));
    doReturn(event).when(enricher).enrich(any(EventEnvelope.class));
    setUp(enricher);
    eventBus.register(new ProjectCreatedSubscriber());
    eventBus.post(event.getOuterObject());
    verify(enricher).enrich(any(EventEnvelope.class));
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) Test(org.junit.Test)

Example 7 with EventEnvelope

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

the class EventEnricherShould method enrich_several_events_bound_by_fields.

@Test
public void enrich_several_events_bound_by_fields() {
    final EventEnvelope permissionGranted = EventEnvelope.of(GivenEvent.permissionGranted());
    final EventEnvelope permissionRevoked = EventEnvelope.of(GivenEvent.permissionRevoked());
    final EventEnvelope sharingRequestApproved = EventEnvelope.of(GivenEvent.sharingRequestApproved());
    assertTrue(enricher.canBeEnriched(permissionGranted));
    assertTrue(enricher.canBeEnriched(permissionRevoked));
    assertTrue(enricher.canBeEnriched(sharingRequestApproved));
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) Test(org.junit.Test)

Example 8 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_enrichment_disabled.

@Test
public void confirm_that_event_can_not_be_enriched_if_enrichment_disabled() {
    final Event event = createEvent(toMessage(newUuid()));
    final EventEnvelope notEnrichableEvent = EventEnvelope.of(event.toBuilder().setContext(event.getContext().toBuilder().setEnrichment(event.getContext().getEnrichment().toBuilder().setDoNotEnrich(true))).build());
    assertFalse(enricher.canBeEnriched(notEnrichableEvent));
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) Event(io.spine.core.Event) GivenEvent(io.spine.server.event.given.EventEnricherTestEnv.GivenEvent) Test(org.junit.Test)

Example 9 with EventEnvelope

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

the class EventSubscriberShould method dispatch_event.

@Test
public void dispatch_event() {
    final EventEnvelope eventEnvelope = createEvent(true);
    final Set<String> dispatchingResult = subscriber.dispatch(eventEnvelope);
    final FailingSubscriber sub = (FailingSubscriber) this.subscriber;
    assertTrue(sub.isMethodCalled());
    assertEquals(1, dispatchingResult.size());
    assertNull(sub.getLastException());
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) FailingSubscriber(io.spine.server.event.given.EventSubscriberTestEnv.FailingSubscriber) Test(org.junit.Test)

Example 10 with EventEnvelope

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

the class ProjectionEventDeliveryShould method postpone_events_dispatched_to_subscriber_method.

@Test
public void postpone_events_dispatched_to_subscriber_method() {
    assertNull(ProjectDetails.getEventReceived());
    final Event event = projectCreated();
    boundedContext.getEventBus().post(event);
    assertNull(ProjectDetails.getEventReceived());
    final EventEnvelope expectedEnvelope = EventEnvelope.of(event);
    final PostponingEventDelivery delivery = repository.getEndpointDelivery();
    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 PrjProjectCreated deliveredEventMsg = ProjectDetails.getEventReceived();
    assertNotNull(deliveredEventMsg);
    assertEquals(Events.getMessage(event), deliveredEventMsg);
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) PrjProjectCreated(io.spine.test.projection.event.PrjProjectCreated) ProjectId(io.spine.test.projection.ProjectId) Event(io.spine.core.Event) PostponingEventDelivery(io.spine.server.projection.given.ProjectionEventDeliveryTestEnv.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