use of io.spine.server.commandbus.CommandDispatcher in project core-java by SpineEventEngine.
the class AbstractCommandRouterShould method setUp.
@Before
public void setUp() {
final BoundedContext boundedContext = BoundedContext.newBuilder().build();
final CommandBus commandBus = boundedContext.getCommandBus();
// Register dispatcher for `StringValue` message type.
// Otherwise we won't be able to post.
commandBus.register(new CommandDispatcher() {
@Override
public Set<CommandClass> getMessageClasses() {
return CommandClass.setOf(StringValue.class);
}
@Override
public void dispatch(CommandEnvelope envelope) {
// Do nothing.
}
});
sourceMessage = Wrapper.forString(getClass().getSimpleName());
sourceContext = requestFactory.createCommandContext();
router = createRouter(commandBus, sourceMessage, sourceContext);
router.addAll(messages);
}
use of io.spine.server.commandbus.CommandDispatcher in project core-java by SpineEventEngine.
the class BoundedContext method register.
/**
* Registers the passed repository with the {@code BoundedContext}.
*
* <p>If the repository does not have a storage assigned, it will be initialized
* using the {@code StorageFactory} associated with this bounded context.
*
* @param repository the repository to register
* @param <I> the type of IDs used in the repository
* @param <E> the type of entities or aggregates
* @see Repository#initStorage(StorageFactory)
*/
@SuppressWarnings("ChainOfInstanceofChecks")
public <// OK here since ways of registering are way too different
I, E extends Entity<I, ?>> void register(Repository<I, E> repository) {
checkStorageAssigned(repository);
guard.register(repository);
if (repository instanceof CommandDispatcher) {
commandBus.register((CommandDispatcher) repository);
}
if (repository instanceof ProcessManagerRepository) {
final ProcessManagerRepository procmanRepo = (ProcessManagerRepository) repository;
commandBus.register(DelegatingCommandDispatcher.of(procmanRepo));
}
if (repository instanceof EventDispatcher) {
eventBus.register((EventDispatcher) repository);
}
if (managesVersionableEntities(repository)) {
stand.registerTypeSupplier(cast(repository));
}
}
use of io.spine.server.commandbus.CommandDispatcher in project core-java by SpineEventEngine.
the class MultiTenantCommandBusShould method unregister_command_dispatcher.
@Test
public void unregister_command_dispatcher() {
final CommandDispatcher dispatcher = new AddTaskDispatcher();
commandBus.register(dispatcher);
commandBus.unregister(dispatcher);
commandBus.post(addTask(), responseObserver);
assertTrue(responseObserver.isError());
}
use of io.spine.server.commandbus.CommandDispatcher in project core-java by SpineEventEngine.
the class ProcessManagerRepositoryShould method setUp.
@Override
@Before
public void setUp() {
super.setUp();
boundedContext = TestBoundedContextFactory.MultiTenant.newBoundedContext();
boundedContext.getCommandBus().register(new CommandDispatcher() {
@Override
public Set<CommandClass> getMessageClasses() {
return CommandClass.setOf(AddTask.class);
}
@Override
public void dispatch(CommandEnvelope envelope) {
/* Simply swallow the command. We need this dispatcher for allowing
Process Manager under test to route the AddTask command. */
}
});
repository = new TestProcessManagerRepository(boundedContext);
repository.initStorage(storageFactory());
TestProcessManager.clearMessageDeliveryHistory();
}
Aggregations