Search in sources :

Example 1 with ProjectStartedExtSubscriber

use of io.spine.server.integration.given.IntegrationBusTestEnv.ProjectStartedExtSubscriber 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());
}
Also used : ProjectStartedExtSubscriber(io.spine.server.integration.given.IntegrationBusTestEnv.ProjectStartedExtSubscriber) InMemoryTransportFactory(io.spine.server.integration.memory.InMemoryTransportFactory) Event(io.spine.core.Event) BoundedContext(io.spine.server.BoundedContext) EventBus(io.spine.server.event.EventBus) ProjectEventsSubscriber(io.spine.server.integration.given.IntegrationBusTestEnv.ProjectEventsSubscriber) Test(org.junit.Test)

Aggregations

Event (io.spine.core.Event)1 BoundedContext (io.spine.server.BoundedContext)1 EventBus (io.spine.server.event.EventBus)1 ProjectEventsSubscriber (io.spine.server.integration.given.IntegrationBusTestEnv.ProjectEventsSubscriber)1 ProjectStartedExtSubscriber (io.spine.server.integration.given.IntegrationBusTestEnv.ProjectStartedExtSubscriber)1 InMemoryTransportFactory (io.spine.server.integration.memory.InMemoryTransportFactory)1 Test (org.junit.Test)1