use of io.spine.server.integration.given.IntegrationBusTestEnv.ProjectEventsSubscriber 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.integration.given.IntegrationBusTestEnv.ProjectEventsSubscriber 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());
}
Aggregations