|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.axonframework.test.GivenWhenThenTestFixture<T>
T
- The type of Aggregate tested in this Fixturepublic class GivenWhenThenTestFixture<T extends EventSourcedAggregateRoot>
A test fixture that allows the execution of given-when-then style test cases. For detailed usage information, see
FixtureConfiguration
.
Constructor Summary | |
---|---|
GivenWhenThenTestFixture(Class<T> aggregateType)
Initializes a new given-when-then style test fixture for the given aggregateType . |
Method Summary | |
---|---|
CommandBus |
getCommandBus()
Returns the command bus used by this fixture. |
EventBus |
getEventBus()
Returns the event bus used by this fixture. |
EventStore |
getEventStore()
Returns the event store used by this fixture. |
Repository<T> |
getRepository()
Returns the repository used by this fixture. |
TestExecutor |
given(List<?> domainEvents)
Configures the given domainEvents as the "given" events. |
TestExecutor |
given(Object... domainEvents)
Configures the given domainEvents as the "given" events. |
TestExecutor |
givenCommands(List<?> commands)
Configures the given commands as the command that will provide the "given" events. |
TestExecutor |
givenCommands(Object... commands)
Configures the given commands as the command that will provide the "given" events. |
TestExecutor |
givenNoPriorActivity()
Indicates that no relevant activity has occurred in the past. |
FixtureConfiguration<T> |
registerAggregateFactory(AggregateFactory<T> aggregateFactory)
Registers the given aggregateFactory with the fixture. |
FixtureConfiguration<T> |
registerAnnotatedCommandHandler(Object annotatedCommandHandler)
Registers an annotatedCommandHandler with this fixture. |
FixtureConfiguration<T> |
registerCommandHandler(Class<?> payloadType,
CommandHandler commandHandler)
Registers a commandHandler to handle commands of the given commandType with the
command bus used by this fixture. |
FixtureConfiguration<T> |
registerCommandHandler(String commandName,
CommandHandler commandHandler)
Registers a commandHandler to handle commands of the given commandType with the
command bus used by this fixture. |
FixtureConfiguration<T> |
registerFieldFilter(FieldFilter fieldFilter)
Registers the given fieldFilter , which is used to define which Fields are used when comparing
objects. |
FixtureConfiguration<T> |
registerIgnoredField(Class<?> declaringClass,
String fieldName)
Indicates that a field with given fieldName , which is declared in given declaringClass
is ignored when performing deep equality checks. |
FixtureConfiguration<T> |
registerInjectableResource(Object resource)
Registers a resource that is eligible for injection in handler method (e.g. |
FixtureConfiguration<T> |
registerRepository(EventSourcingRepository<T> eventSourcingRepository)
Registers an arbitrary event sourcing repository with the fixture. |
void |
setReportIllegalStateChange(boolean reportIllegalStateChange)
Sets whether or not the fixture should detect and report state changes that occur outside of Event Handler methods. |
ResultValidator |
when(Object command)
Dispatches the given command to the appropriate command handler and records all activity in the fixture for result validation. |
ResultValidator |
when(Object command,
Map<String,?> metaData)
Dispatches the given command and meta data to the appropriate command handler and records all activity in the fixture for result validation. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public GivenWhenThenTestFixture(Class<T> aggregateType)
aggregateType
.
aggregateType
- The aggregate to initialize the test fixture forMethod Detail |
---|
public FixtureConfiguration<T> registerRepository(EventSourcingRepository<T> eventSourcingRepository)
FixtureConfiguration
repository
with the fixture. The repository must be wired
with the Event Store of this test fixture.
Should not be used in combination with FixtureConfiguration.registerAggregateFactory(org.axonframework.eventsourcing.AggregateFactory)
, as that will overwrite any
repository previously registered.
registerRepository
in interface FixtureConfiguration<T extends EventSourcedAggregateRoot>
eventSourcingRepository
- The repository to use in the test case
public FixtureConfiguration<T> registerAggregateFactory(AggregateFactory<T> aggregateFactory)
FixtureConfiguration
aggregateFactory
with the fixture. The repository used by the fixture will use
the given factory to create new aggregate instances. Defaults to an Aggregate Factory that uses the no-arg
constructor to create new instances.
Should not be used in combination with FixtureConfiguration.registerRepository(org.axonframework.eventsourcing.EventSourcingRepository)
, as that will overwrite any
aggregate factory previously registered.
registerAggregateFactory
in interface FixtureConfiguration<T extends EventSourcedAggregateRoot>
aggregateFactory
- The Aggregate Factory to create empty aggregates with
public FixtureConfiguration<T> registerAnnotatedCommandHandler(Object annotatedCommandHandler)
FixtureConfiguration
annotatedCommandHandler
with this fixture. This will register this command handler
with the command bus used in this fixture.
registerAnnotatedCommandHandler
in interface FixtureConfiguration<T extends EventSourcedAggregateRoot>
annotatedCommandHandler
- The command handler to register for this test
public FixtureConfiguration<T> registerCommandHandler(Class<?> payloadType, CommandHandler commandHandler)
FixtureConfiguration
commandHandler
to handle commands of the given commandType
with the
command bus used by this fixture.
registerCommandHandler
in interface FixtureConfiguration<T extends EventSourcedAggregateRoot>
payloadType
- The type of command to register the handler forcommandHandler
- The handler to register
public FixtureConfiguration<T> registerCommandHandler(String commandName, CommandHandler commandHandler)
FixtureConfiguration
commandHandler
to handle commands of the given commandType
with the
command bus used by this fixture.
registerCommandHandler
in interface FixtureConfiguration<T extends EventSourcedAggregateRoot>
commandName
- The name of the command to register the handler forcommandHandler
- The handler to register
public FixtureConfiguration<T> registerInjectableResource(Object resource)
FixtureConfiguration
@CommandHandler
, @EventSourcingHandler
and @EventHandler
. These resource must be
registered before registering any command handler.
registerInjectableResource
in interface FixtureConfiguration<T extends EventSourcedAggregateRoot>
resource
- The resource eligible for injection
public FixtureConfiguration<T> registerFieldFilter(FieldFilter fieldFilter)
FixtureConfiguration
fieldFilter
, which is used to define which Fields are used when comparing
objects. The ResultValidator.expectEvents(Object...)
and ResultValidator.expectReturnValue(Object)
,
for example, use this filter.
When multiple filters are registered, a Field must be accepted by all registered filters in order to be
accepted.
By default, all Fields are included in the comparison.
registerFieldFilter
in interface FixtureConfiguration<T extends EventSourcedAggregateRoot>
fieldFilter
- The FieldFilter that defines which fields to include in the comparison
public FixtureConfiguration<T> registerIgnoredField(Class<?> declaringClass, String fieldName)
FixtureConfiguration
fieldName
, which is declared in given declaringClass
is ignored when performing deep equality checks.
registerIgnoredField
in interface FixtureConfiguration<T extends EventSourcedAggregateRoot>
declaringClass
- The class declaring the fieldfieldName
- The name of the field
public TestExecutor given(Object... domainEvents)
FixtureConfiguration
domainEvents
as the "given" events. These are the events returned by the event
store when an aggregate is loaded.
If an item in the given domainEvents
implements Message
, the
payload and meta data from that message are copied into a newly created Domain Event Message. Otherwise, a
Domain Event Message with the item as payload and empty meta data is created.
given
in interface FixtureConfiguration<T extends EventSourcedAggregateRoot>
domainEvents
- the domain events the event store should return
public TestExecutor givenNoPriorActivity()
FixtureConfiguration
FixtureConfiguration.given(java.util.List)
method.
givenNoPriorActivity
in interface FixtureConfiguration<T extends EventSourcedAggregateRoot>
public TestExecutor given(List<?> domainEvents)
FixtureConfiguration
domainEvents
as the "given" events. These are the events returned by the event
store when an aggregate is loaded.
If an item in the list implements Message
, the payload and meta data from that
message are copied into a newly created Domain Event Message. Otherwise, a Domain Event Message with the item
as payload and empty meta data is created.
given
in interface FixtureConfiguration<T extends EventSourcedAggregateRoot>
domainEvents
- the domain events the event store should return
public TestExecutor givenCommands(Object... commands)
FixtureConfiguration
commands
as the command that will provide the "given" events. The commands are
executed, and the resulting stored events are captured.
givenCommands
in interface FixtureConfiguration<T extends EventSourcedAggregateRoot>
commands
- the domain events the event store should return
public TestExecutor givenCommands(List<?> commands)
FixtureConfiguration
commands
as the command that will provide the "given" events. The commands are
executed, and the resulting stored events are captured.
givenCommands
in interface FixtureConfiguration<T extends EventSourcedAggregateRoot>
commands
- the domain events the event store should return
public ResultValidator when(Object command)
TestExecutor
command
is a CommandMessage
instance, it will be dispatched as-is. Any other object will
cause the given command
to be wrapped in a CommandMessage
as its payload.
when
in interface TestExecutor
command
- The command to execute
public ResultValidator when(Object command, Map<String,?> metaData)
TestExecutor
command
is a CommandMessage
instance, it will be dispatched as-is, with given
additional metaData
. Any other object will cause the given command
to be wrapped in a
CommandMessage
as its payload.
when
in interface TestExecutor
command
- The command to executemetaData
- The meta data to attach to the
public void setReportIllegalStateChange(boolean reportIllegalStateChange)
FixtureConfiguration
setReportIllegalStateChange
in interface FixtureConfiguration<T extends EventSourcedAggregateRoot>
reportIllegalStateChange
- whether or not to detect and report state changes outside of Event Handler
methods.public CommandBus getCommandBus()
FixtureConfiguration
getCommandBus
in interface FixtureConfiguration<T extends EventSourcedAggregateRoot>
public EventBus getEventBus()
FixtureConfiguration
ResultValidator
operations.
getEventBus
in interface FixtureConfiguration<T extends EventSourcedAggregateRoot>
public EventStore getEventStore()
FixtureConfiguration
getEventStore
in interface FixtureConfiguration<T extends EventSourcedAggregateRoot>
public Repository<T> getRepository()
FixtureConfiguration
getRepository
in interface FixtureConfiguration<T extends EventSourcedAggregateRoot>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |