org.axonframework.test
Interface FixtureConfiguration


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 the createGenericRepository(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.

Since:
0.6
Author:
Allard Buijze

Method Summary
<T extends EventSourcedAggregateRoot>
EventSourcingRepository<T>
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

createGenericRepository

<T extends EventSourcedAggregateRoot> EventSourcingRepository<T> createGenericRepository(Class<T> aggregateClass)
Creates and registers a generic repository for the given 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.

Type Parameters:
T - The type of the aggregate to create the repository for
Parameters:
aggregateClass - The class of the aggregate to create the repository for
Returns:
The generic repository, which has been registered with the fixture
See Also:
GenericEventSourcingRepository

registerRepository

FixtureConfiguration registerRepository(EventSourcingRepository<?> repository)
Registers an arbitrary event sourcing repository with the fixture. The repository will be wired with an Event Store and Event Bus implementation suitable for this test fixture.

Parameters:
repository - The repository to use in the test case
Returns:
the current FixtureConfiguration, for fluent interfacing

registerAnnotatedCommandHandler

FixtureConfiguration registerAnnotatedCommandHandler(Object annotatedCommandHandler)
Registers an annotatedCommandHandler with this fixture. This will register this command handler with the command bus used in this fixture.

Parameters:
annotatedCommandHandler - The command handler to register for this test
Returns:
the current FixtureConfiguration, for fluent interfacing

registerCommandHandler

FixtureConfiguration registerCommandHandler(Class<?> commandType,
                                            CommandHandler commandHandler)
Registers a commandHandler to handle commands of the given commandType with the command bus used by this fixture.

Parameters:
commandType - The type of command to register the handler for
commandHandler - The handler to register
Returns:
the current FixtureConfiguration, for fluent interfacing

given

TestExecutor given(DomainEvent... domainEvents)
Configures the given 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.

Parameters:
domainEvents - the domain events the event store should return
Returns:
a TestExecutor instance that can execute the test with this configuration

given

TestExecutor given(List<DomainEvent> domainEvents)
Configures the given 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.

Parameters:
domainEvents - the domain events the event store should return
Returns:
a TestExecutor instance that can execute the test with this configuration

getAggregateIdentifier

UUID getAggregateIdentifier()
Returns the identifier of the aggregate that this fixture prepares. When commands need to load an aggregate using a specific identifier, use this method to obtain the correct identifier to use.

Returns:
the identifier of the aggregate prepared in this fixture

getCommandBus

CommandBus getCommandBus()
Returns the command bus used by this fixture. The command bus is provided for wiring purposes only, for example to support composite commands (a single command that causes the execution of one or more others).

Returns:
the command bus used by this fixture

getEventBus

EventBus getEventBus()
Returns the event bus used by this fixture. The event bus is provided for wiring purposes only, for example to allow command handlers to publish events other than Domain Events. Events published on the returned event bus are recorded an evaluated in the ResultValidator operations.

Returns:
the event bus used by this fixture

getEventStore

EventStore getEventStore()
Returns the event store used by this fixture. This event store is provided for wiring purposes only.

Returns:
the event store used by this fixture

getRepository

EventSourcingRepository<?> getRepository()
Returns the repository used by this fixture. This repository is provided for wiring purposes only. The repository is configured to use the fixture's event store to load events.

Returns:
the repository used by this fixture


Copyright © 2010. All Rights Reserved.