Search in sources :

Example 6 with InMemoryTransportFactory

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

Example 7 with InMemoryTransportFactory

use of io.spine.server.integration.memory.InMemoryTransportFactory in project core-java by SpineEventEngine.

the class IntegrationBusShould method throw_on_mismatch_of_external_attribute_during_dispatching.

@Test
public void throw_on_mismatch_of_external_attribute_during_dispatching() {
    final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
    final BoundedContext sourceContext = contextWithTransport(transportFactory);
    final RejectionSubscriber rejectionSubscriber = new ExternalMismatchSubscriber();
    sourceContext.getRejectionBus().register(rejectionSubscriber);
    sourceContext.getIntegrationBus().register(rejectionSubscriber);
    final Rejection rejection = cannotStartArchivedProject();
    try {
        sourceContext.getRejectionBus().post(rejection);
        fail("An exception is expected.");
    } catch (Exception e) {
        final String exceptionMsg = e.getMessage();
        assertContains("external", exceptionMsg);
    }
}
Also used : Rejection(io.spine.core.Rejection) RejectionSubscriber(io.spine.server.rejection.RejectionSubscriber) ExternalMismatchSubscriber(io.spine.server.integration.given.IntegrationBusTestEnv.ExternalMismatchSubscriber) InMemoryTransportFactory(io.spine.server.integration.memory.InMemoryTransportFactory) BoundedContext(io.spine.server.BoundedContext) Test(org.junit.Test)

Example 8 with InMemoryTransportFactory

use of io.spine.server.integration.memory.InMemoryTransportFactory in project core-java by SpineEventEngine.

the class IntegrationBusShould method dispatch_events_from_one_BC_to_entities_with_ext_subscribers_of_another_BC.

@Test
public void dispatch_events_from_one_BC_to_entities_with_ext_subscribers_of_another_BC() {
    final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
    final BoundedContext sourceContext = contextWithTransport(transportFactory);
    contextWithExtEntitySubscribers(transportFactory);
    assertNull(ProjectDetails.getExternalEvent());
    assertNull(ProjectWizard.getExternalEvent());
    assertNull(ProjectCountAggregate.getExternalEvent());
    final Event event = projectCreated();
    sourceContext.getEventBus().post(event);
    final Message expectedMessage = AnyPacker.unpack(event.getMessage());
    assertEquals(expectedMessage, ProjectDetails.getExternalEvent());
    assertEquals(expectedMessage, ProjectWizard.getExternalEvent());
    assertEquals(expectedMessage, ProjectCountAggregate.getExternalEvent());
}
Also used : Message(com.google.protobuf.Message) InMemoryTransportFactory(io.spine.server.integration.memory.InMemoryTransportFactory) Event(io.spine.core.Event) BoundedContext(io.spine.server.BoundedContext) Test(org.junit.Test)

Example 9 with InMemoryTransportFactory

use of io.spine.server.integration.memory.InMemoryTransportFactory in project core-java by SpineEventEngine.

the class IntegrationBusShould method dispatch_events_from_one_BC_to_external_subscribers_of_another_BC.

@Test
public void dispatch_events_from_one_BC_to_external_subscribers_of_another_BC() {
    final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
    final BoundedContext sourceContext = contextWithTransport(transportFactory);
    contextWithExternalSubscribers(transportFactory);
    assertNull(ProjectEventsSubscriber.getExternalEvent());
    final Event event = projectCreated();
    sourceContext.getEventBus().post(event);
    assertEquals(AnyPacker.unpack(event.getMessage()), ProjectEventsSubscriber.getExternalEvent());
}
Also used : InMemoryTransportFactory(io.spine.server.integration.memory.InMemoryTransportFactory) Event(io.spine.core.Event) BoundedContext(io.spine.server.BoundedContext) Test(org.junit.Test)

Example 10 with InMemoryTransportFactory

use of io.spine.server.integration.memory.InMemoryTransportFactory in project core-java by SpineEventEngine.

the class IntegrationBusShould method emit_unsupported_external_message_exception_if_message_type_is_unknown.

@Test
public void emit_unsupported_external_message_exception_if_message_type_is_unknown() {
    final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
    final BoundedContext boundedContext = contextWithTransport(transportFactory);
    final Event event = projectCreated();
    final BoundedContextName boundedContextName = BoundedContext.newName("External context ID");
    final ExternalMessage externalMessage = ExternalMessages.of(event, boundedContextName);
    final MemoizingObserver<Ack> observer = StreamObservers.memoizingObserver();
    boundedContext.getIntegrationBus().post(externalMessage, observer);
    final Error error = observer.firstResponse().getStatus().getError();
    assertFalse(Validate.isDefault(error));
    assertEquals(ExternalMessageValidationError.getDescriptor().getFullName(), error.getType());
    assertTrue(UNSUPPORTED_EXTERNAL_MESSAGE.getNumber() == error.getCode());
}
Also used : Ack(io.spine.core.Ack) InMemoryTransportFactory(io.spine.server.integration.memory.InMemoryTransportFactory) Event(io.spine.core.Event) Error(io.spine.base.Error) BoundedContext(io.spine.server.BoundedContext) BoundedContextName(io.spine.core.BoundedContextName) Test(org.junit.Test)

Aggregations

BoundedContext (io.spine.server.BoundedContext)12 InMemoryTransportFactory (io.spine.server.integration.memory.InMemoryTransportFactory)12 Test (org.junit.Test)12 Event (io.spine.core.Event)9 Rejection (io.spine.core.Rejection)3 EventBus (io.spine.server.event.EventBus)3 Message (com.google.protobuf.Message)2 BoundedContextName (io.spine.core.BoundedContextName)2 ProjectEventsSubscriber (io.spine.server.integration.given.IntegrationBusTestEnv.ProjectEventsSubscriber)2 Error (io.spine.base.Error)1 Ack (io.spine.core.Ack)1 ExternalMismatchSubscriber (io.spine.server.integration.given.IntegrationBusTestEnv.ExternalMismatchSubscriber)1 ProjectRejectionsExtSubscriber (io.spine.server.integration.given.IntegrationBusTestEnv.ProjectRejectionsExtSubscriber)1 ProjectStartedExtSubscriber (io.spine.server.integration.given.IntegrationBusTestEnv.ProjectStartedExtSubscriber)1 RejectionBus (io.spine.server.rejection.RejectionBus)1 RejectionSubscriber (io.spine.server.rejection.RejectionSubscriber)1