use of io.spine.server.BoundedContext in project core-java by SpineEventEngine.
the class ProjectionRepositoryShould method throw_exception_on_attempt_to_register_in_bc_with_no_messages_handled.
@Test(expected = IllegalStateException.class)
public void throw_exception_on_attempt_to_register_in_bc_with_no_messages_handled() {
final SensoryDeprivedProjectionRepository repo = new SensoryDeprivedProjectionRepository();
final BoundedContext boundedContext = BoundedContext.newBuilder().setMultitenant(false).build();
repo.setBoundedContext(boundedContext);
repo.onRegistered();
}
use of io.spine.server.BoundedContext in project core-java by SpineEventEngine.
the class ProcessManagerRepository method onRegistered.
/**
* {@inheritDoc}
*
* <p>Registers with the {@code CommandBus} for dispatching commands
* (via {@linkplain DelegatingCommandDispatcher delegating dispatcher}).
*
* <p>Registers with the {@code IntegrationBus} for dispatching external events and rejections.
*
* <p>Ensures there is at least one message handler declared by the class of the managed
* process manager:
*
* <ul>
* <li>command handler methods;</li>
* <li>domestic or external event reactor methods;</li>
* <li>domestic or external rejection reactor methods.</li>
* </ul>
*
* <p>Throws an {@code IllegalStateException} otherwise.
*/
// It's fine, as reflects the logic.
@SuppressWarnings("MethodWithMoreThanThreeNegations")
@Override
public void onRegistered() {
super.onRegistered();
final BoundedContext boundedContext = getBoundedContext();
final DelegatingRejectionDispatcher<I> rejDispatcher = DelegatingRejectionDispatcher.of(this);
final boolean handlesCommands = register(boundedContext.getCommandBus(), DelegatingCommandDispatcher.of(this));
final boolean handlesDomesticRejections = register(boundedContext.getRejectionBus(), rejDispatcher);
final boolean handlesExternalRejections = register(boundedContext.getIntegrationBus(), rejDispatcher.getExternalDispatcher());
final boolean handlesDomesticEvents = !getMessageClasses().isEmpty();
final boolean handlesExternalEvents = !getExternalEventDispatcher().getMessageClasses().isEmpty();
final boolean subscribesToEvents = handlesDomesticEvents || handlesExternalEvents;
final boolean reactsUponRejections = handlesDomesticRejections || handlesExternalRejections;
if (!handlesCommands && !subscribesToEvents && !reactsUponRejections) {
throw newIllegalStateException("Process managers of the repository %s have no command handlers, " + "and do not react upon any rejections or events.", this);
}
this.commandErrorHandler = CommandErrorHandler.with(boundedContext.getRejectionBus());
}
use of io.spine.server.BoundedContext in project core-java by SpineEventEngine.
the class BoundedContextShould method not_notify_integration_event_subscriber_if_event_is_invalid.
@Test
public void not_notify_integration_event_subscriber_if_event_is_invalid() {
final BoundedContext boundedContext = BoundedContext.newBuilder().setMultitenant(true).build();
// Unsupported message.
final Any invalidMsg = AnyPacker.pack(BcProjectCreated.getDefaultInstance());
final IntegrationEvent event = Given.AnIntegrationEvent.projectCreated().toBuilder().setMessage(invalidMsg).build();
final MemoizingObserver<Ack> observer = memoizingObserver();
boundedContext.notify(event, observer);
assertEquals(ERROR, observer.firstResponse().getStatus().getStatusCase());
}
use of io.spine.server.BoundedContext in project core-java by SpineEventEngine.
the class BoundedContextShould method propagate_registered_repositories_to_stand.
@Test
public void propagate_registered_repositories_to_stand() {
final BoundedContext boundedContext = BoundedContext.newBuilder().build();
final Stand stand = Spy.ofClass(Stand.class).on(boundedContext);
verify(stand, never()).registerTypeSupplier(any(Repository.class));
final ProjectAggregateRepository repository = new ProjectAggregateRepository();
boundedContext.register(repository);
verify(stand).registerTypeSupplier(eq(repository));
}
use of io.spine.server.BoundedContext in project core-java by SpineEventEngine.
the class CommandDispatcherRegistryShould method setUp.
@Before
public void setUp() {
ModelTests.clearModel();
final BoundedContext boundedContext = BoundedContext.newBuilder().setName(getClass().getSimpleName()).build();
eventBus = boundedContext.getEventBus();
registry = new CommandDispatcherRegistry();
}
Aggregations