use of io.spine.server.event.EventBus in project core-java by SpineEventEngine.
the class IntegrationBusBuilderShould method return_previously_set_EventBus.
@Test
public void return_previously_set_EventBus() {
final EventBus mock = mock(EventBus.class);
assertEquals(mock, builder().setEventBus(mock).getEventBus().get());
}
use of io.spine.server.event.EventBus in project core-java by SpineEventEngine.
the class IntegrationBusShould method update_local_subscriptions_upon_repeated_RequestedMessageTypes.
@Test
public void update_local_subscriptions_upon_repeated_RequestedMessageTypes() {
final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
final BoundedContext sourceContext = contextWithTransport(transportFactory);
final BoundedContext destinationCtx = contextWithTransport(transportFactory);
// Prepare two external subscribers for the different events in the the `destinationCtx`.
final ProjectEventsSubscriber projectCreatedSubscriber = new ProjectEventsSubscriber();
final ProjectStartedExtSubscriber projectStartedSubscriber = new ProjectStartedExtSubscriber();
// Before anything happens, there were no events received by those.
assertNull(ProjectEventsSubscriber.getExternalEvent());
assertNull(ProjectStartedExtSubscriber.getExternalEvent());
// Both events are prepared along with the `EventBus` of the source bounded context.
final EventBus sourceEventBus = sourceContext.getEventBus();
final Event eventA = projectCreated();
final Event eventB = projectStarted();
// Both events are emitted, `ProjectCreated` subscriber only is present.
destinationCtx.getIntegrationBus().register(projectCreatedSubscriber);
sourceEventBus.post(eventA);
sourceEventBus.post(eventB);
// Only `ProjectCreated` should have been dispatched.
assertEquals(AnyPacker.unpack(eventA.getMessage()), ProjectEventsSubscriber.getExternalEvent());
assertNull(ProjectStartedExtSubscriber.getExternalEvent());
// Clear before the next round starts.
ProjectStartedExtSubscriber.clear();
ProjectEventsSubscriber.clear();
// Both events are emitted, No external subscribers at all.
destinationCtx.getIntegrationBus().unregister(projectCreatedSubscriber);
sourceEventBus.post(eventA);
sourceEventBus.post(eventB);
// No events should have been dispatched.
assertNull(ProjectEventsSubscriber.getExternalEvent());
assertNull(ProjectStartedExtSubscriber.getExternalEvent());
// Both events are emitted, `ProjectStarted` subscriber only is present
destinationCtx.getIntegrationBus().register(projectStartedSubscriber);
sourceEventBus.post(eventA);
sourceEventBus.post(eventB);
// This time `ProjectStarted` event should only have been dispatched.
assertNull(ProjectEventsSubscriber.getExternalEvent());
assertEquals(AnyPacker.unpack(eventB.getMessage()), ProjectStartedExtSubscriber.getExternalEvent());
}
use of io.spine.server.event.EventBus in project core-java by SpineEventEngine.
the class IntegrationBusShould method not_dispatch_events_to_domestic_subscribers_if_they_requested_external.
@Test
public void not_dispatch_events_to_domestic_subscribers_if_they_requested_external() {
final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
final BoundedContext context = contextWithExtEntitySubscribers(transportFactory);
final ProjectEventsSubscriber eventSubscriber = new ProjectEventsSubscriber();
final EventBus eventBus = context.getEventBus();
eventBus.register(eventSubscriber);
assertNull(ProjectEventsSubscriber.getExternalEvent());
assertNull(ProjectDetails.getExternalEvent());
assertNull(ProjectWizard.getExternalEvent());
assertNull(ProjectCountAggregate.getExternalEvent());
final Event projectCreated = projectCreated();
eventBus.post(projectCreated);
assertNull(ProjectEventsSubscriber.getExternalEvent());
assertNull(ProjectDetails.getExternalEvent());
assertNull(ProjectWizard.getExternalEvent());
assertNull(ProjectCountAggregate.getExternalEvent());
}
use of io.spine.server.event.EventBus in project core-java by SpineEventEngine.
the class IntegrationBusShould method dispatch_events_from_one_BC_to_two_BCs_with_different_needs.
// variables declared for readability.
@SuppressWarnings("unused")
@Test
public void dispatch_events_from_one_BC_to_two_BCs_with_different_needs() {
final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
final BoundedContext sourceContext = contextWithTransport(transportFactory);
final BoundedContext destA = contextWithProjectCreatedNeeds(transportFactory);
final BoundedContext destB = contextWithProjectStartedNeeds(transportFactory);
assertNull(ProjectStartedExtSubscriber.getExternalEvent());
assertNull(ProjectEventsSubscriber.getExternalEvent());
final EventBus sourceEventBus = sourceContext.getEventBus();
final Event eventA = projectCreated();
sourceEventBus.post(eventA);
final Event eventB = projectStarted();
sourceEventBus.post(eventB);
assertEquals(AnyPacker.unpack(eventA.getMessage()), ProjectEventsSubscriber.getExternalEvent());
assertEquals(AnyPacker.unpack(eventB.getMessage()), ProjectStartedExtSubscriber.getExternalEvent());
}
Aggregations