Package org.axonframework.test.utils
Class RecordingCommandBus
java.lang.Object
org.axonframework.test.utils.RecordingCommandBus
- All Implemented Interfaces:
org.axonframework.commandhandling.CommandBus,org.axonframework.messaging.MessageDispatchInterceptorSupport<org.axonframework.commandhandling.CommandMessage<?>>,org.axonframework.messaging.MessageHandlerInterceptorSupport<org.axonframework.commandhandling.CommandMessage<?>>
public class RecordingCommandBus
extends Object
implements org.axonframework.commandhandling.CommandBus
CommandBus implementation that does not perform any actions on subscriptions or dispatched commands, but records
them instead. This implementation is not a stand-in replacement for a mock, but might prove useful in many simple
cases.
- Since:
- 1.1
- Author:
- Allard Buijze
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClears all the commands recorded by this Command Bus.voidClears all subscribed handlers on this command bus.<C> voiddispatch(org.axonframework.commandhandling.CommandMessage<C> command) <C,R> void dispatch(org.axonframework.commandhandling.CommandMessage<C> command, org.axonframework.commandhandling.CommandCallback<? super C, ? super R> callback) List<org.axonframework.commandhandling.CommandMessage<?>>Returns a list with all commands that have been dispatched by this command bus.Map<String,org.axonframework.messaging.MessageHandler<? super org.axonframework.commandhandling.CommandMessage<?>>> Returns a Map will all Command Names and their Command Handler that have been subscribed to this command bus.<C> booleanisSubscribed(String commandName, org.axonframework.messaging.MessageHandler<? super org.axonframework.commandhandling.CommandMessage<?>> commandHandler) Indicates whether the givencommandHandleris subscribed to commands of the givencommandTypeon this command bus.booleanisSubscribed(org.axonframework.messaging.MessageHandler<? super org.axonframework.commandhandling.CommandMessage<?>> commandHandler) Indicates whether the givencommandHandleris subscribed to this command bus.org.axonframework.common.RegistrationregisterDispatchInterceptor(org.axonframework.messaging.MessageDispatchInterceptor<? super org.axonframework.commandhandling.CommandMessage<?>> dispatchInterceptor) org.axonframework.common.RegistrationregisterHandlerInterceptor(org.axonframework.messaging.MessageHandlerInterceptor<? super org.axonframework.commandhandling.CommandMessage<?>> handlerInterceptor) voidsetCallbackBehavior(CallbackBehavior callbackBehavior) Sets the instance that defines the behavior of the Command Bus when a command is dispatched with a callback.org.axonframework.common.Registrationsubscribe(String commandName, org.axonframework.messaging.MessageHandler<? super org.axonframework.commandhandling.CommandMessage<?>> handler)
-
Constructor Details
-
RecordingCommandBus
public RecordingCommandBus()
-
-
Method Details
-
dispatch
public <C> void dispatch(@Nonnull org.axonframework.commandhandling.CommandMessage<C> command) - Specified by:
dispatchin interfaceorg.axonframework.commandhandling.CommandBus
-
dispatch
public <C,R> void dispatch(@Nonnull org.axonframework.commandhandling.CommandMessage<C> command, @Nonnull org.axonframework.commandhandling.CommandCallback<? super C, ? super R> callback) - Specified by:
dispatchin interfaceorg.axonframework.commandhandling.CommandBus
-
subscribe
public org.axonframework.common.Registration subscribe(@Nonnull String commandName, @Nonnull org.axonframework.messaging.MessageHandler<? super org.axonframework.commandhandling.CommandMessage<?>> handler) - Specified by:
subscribein interfaceorg.axonframework.commandhandling.CommandBus
-
clearCommands
public void clearCommands()Clears all the commands recorded by this Command Bus. -
clearSubscriptions
public void clearSubscriptions()Clears all subscribed handlers on this command bus. -
isSubscribed
public boolean isSubscribed(org.axonframework.messaging.MessageHandler<? super org.axonframework.commandhandling.CommandMessage<?>> commandHandler) Indicates whether the givencommandHandleris subscribed to this command bus.- Parameters:
commandHandler- The command handler to verify the subscription for- Returns:
trueif the handler is subscribed, otherwisefalse.
-
isSubscribed
public <C> boolean isSubscribed(String commandName, org.axonframework.messaging.MessageHandler<? super org.axonframework.commandhandling.CommandMessage<?>> commandHandler) Indicates whether the givencommandHandleris subscribed to commands of the givencommandTypeon this command bus.- Type Parameters:
C- The type of command to verify the subscription for- Parameters:
commandName- The name of the command to verify the subscription forcommandHandler- The command handler to verify the subscription for- Returns:
trueif the handler is subscribed, otherwisefalse.
-
getSubscriptions
public Map<String,org.axonframework.messaging.MessageHandler<? super org.axonframework.commandhandling.CommandMessage<?>>> getSubscriptions()Returns a Map will all Command Names and their Command Handler that have been subscribed to this command bus.- Returns:
- a Map will all Command Names and their Command Handler
-
getDispatchedCommands
Returns a list with all commands that have been dispatched by this command bus.- Returns:
- a list with all commands that have been dispatched
-
setCallbackBehavior
Sets the instance that defines the behavior of the Command Bus when a command is dispatched with a callback.- Parameters:
callbackBehavior- The instance deciding to how the callback should be invoked.
-
registerDispatchInterceptor
public org.axonframework.common.Registration registerDispatchInterceptor(@Nonnull org.axonframework.messaging.MessageDispatchInterceptor<? super org.axonframework.commandhandling.CommandMessage<?>> dispatchInterceptor) - Specified by:
registerDispatchInterceptorin interfaceorg.axonframework.messaging.MessageDispatchInterceptorSupport<org.axonframework.commandhandling.CommandMessage<?>>
-
registerHandlerInterceptor
public org.axonframework.common.Registration registerHandlerInterceptor(@Nonnull org.axonframework.messaging.MessageHandlerInterceptor<? super org.axonframework.commandhandling.CommandMessage<?>> handlerInterceptor) - Specified by:
registerHandlerInterceptorin interfaceorg.axonframework.messaging.MessageHandlerInterceptorSupport<org.axonframework.commandhandling.CommandMessage<?>>
-