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