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