|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface FixtureConfiguration
Interface describing the operations available on a test fixture in the configuration stage. This stage allows a test case to prepare the fixture for test execution.
In the preparation stage, you should register all components required for your test, mainly the command handler. A typical command handler will require a repository. The test fixture can create a generic repository using thecreateGenericRepository(Class) method. Alternatively, you can register your own repository using the registerRepository(org.axonframework.eventsourcing.EventSourcingRepository) method. Registering the repository will
cause the fixture to configure the correct EventBus and EventStore implementations required by the
test.
Typical usage example:
public class MyCommandHandlerTest() {
private FixtureConfiguration fixture;
@Before
public void setUp() {
fixture = Fixtures.newGivenWhenThenFixture();
MyCommandHandler commandHandler = new MyCommandHandler();
commandHandler.setRepository(fixture.createGenericRepository(MyAggregate.class));
fixture.registerAnnotatedCommandHandler(commandHandler);
}
@Test
public void testCommandHandlerCase() {
fixture.given(new MyEvent(1), new MyEvent(2))
.when(new TestCommand())
.expectReturnValue(Void.TYPE)
.expectEvents(new MyEvent(3));
}
}
Providing the "given" events using the given(org.axonframework.domain.DomainEvent...) or given(List<DomainEvent>) methods must be the last operation in the configuration
stage.
Besides setting configuration, you can also use the FixtureConfiguration to get access to the configured components.
This allows you to (manually) inject the EventBus or any other component into you command handler, for example.
| Method Summary | ||
|---|---|---|
|
createGenericRepository(Class<T> aggregateClass)
Creates and registers a generic repository for the given aggregateClass. |
|
UUID |
getAggregateIdentifier()
Returns the identifier of the aggregate that this fixture prepares. |
|
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. |
|
EventSourcingRepository<?> |
getRepository()
Returns the repository used by this fixture. |
|
TestExecutor |
given(DomainEvent... domainEvents)
Configures the given domainEvents as the "given" events. |
|
TestExecutor |
given(List<DomainEvent> domainEvents)
Configures the given domainEvents as the "given" events. |
|
FixtureConfiguration |
registerAnnotatedCommandHandler(Object annotatedCommandHandler)
Registers an annotatedCommandHandler with this fixture. |
|
FixtureConfiguration |
registerCommandHandler(Class<?> commandType,
CommandHandler commandHandler)
Registers a commandHandler to handle commands of the given commandType with the command
bus used by this fixture. |
|
FixtureConfiguration |
registerRepository(EventSourcingRepository<?> repository)
Registers an arbitrary event sourcing repository with the fixture. |
|
| Method Detail |
|---|
<T extends EventSourcedAggregateRoot> EventSourcingRepository<T> createGenericRepository(Class<T> aggregateClass)
aggregateClass. It is not recommended to
use this method to create more than a single generic repository. If multiple repositories are created, the exact
behavior is undefined.
T - The type of the aggregate to create the repository foraggregateClass - The class of the aggregate to create the repository for
GenericEventSourcingRepositoryFixtureConfiguration registerRepository(EventSourcingRepository<?> repository)
repository with the fixture. The repository will be wired with
an Event Store and Event Bus implementation suitable for this test fixture.
repository - The repository to use in the test case
FixtureConfiguration registerAnnotatedCommandHandler(Object annotatedCommandHandler)
annotatedCommandHandler with this fixture. This will register this command handler with
the command bus used in this fixture.
annotatedCommandHandler - The command handler to register for this test
FixtureConfiguration registerCommandHandler(Class<?> commandType,
CommandHandler commandHandler)
commandHandler to handle commands of the given commandType with the command
bus used by this fixture.
commandType - The type of command to register the handler forcommandHandler - The handler to register
TestExecutor given(DomainEvent... domainEvents)
domainEvents as the "given" events. These are the events returned by the event
store when an aggregate is loaded.
Note that the aggregate identifier and the sequence number do not have to be set on these events. The fixture
will automatically set those.
domainEvents - the domain events the event store should return
TestExecutor given(List<DomainEvent> domainEvents)
domainEvents as the "given" events. These are the events returned by the event
store when an aggregate is loaded.
Note that the aggregate identifier and the sequence number do not have to be set on these events. The fixture
will automatically set those.
domainEvents - the domain events the event store should return
UUID getAggregateIdentifier()
CommandBus getCommandBus()
EventBus getEventBus()
ResultValidator operations.
EventStore getEventStore()
EventSourcingRepository<?> getRepository()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||