org.axonframework.test
Interface FixtureConfiguration<T extends EventSourcedAggregateRoot>

Type Parameters:
T - The type of the aggregate under test
All Known Implementing Classes:
GivenWhenThenTestFixture

public interface FixtureConfiguration<T extends EventSourcedAggregateRoot>

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.

The fixture is initialized using a Command Handler that expects an @CommandHandler aggregate. If you have implemented your own command handler (either using annotations, or by implementing the CommandHandler interace), you must register the command handler using registerAnnotatedCommandHandler(Object) or registerCommandHandler(Class, org.axonframework.commandhandling.CommandHandler), respectively. A typical command handler will require a repository. The test fixture initializes an Event Sourcing Repository, which can be obtained using getRepository(). 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(MyAggregate.class); MyCommandHandler commandHandler = new MyCommandHandler(); commandHandler.setRepository(fixture.getRepository()); 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)); }
}

If you use @CommandHandler annotations on the aggregate, you do not need to configure any additional command handlers. In that case, no configuration is required:

Providing the "given" events using the given(Object...) or given(List<DomainEvent>) methods must be the last operation in the configuration stage. To indicate that no "given" events are available, just call given() with no parameters.

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
 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> repository)
          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.
 

Method Detail

registerRepository

FixtureConfiguration<T> registerRepository(EventSourcingRepository<T> repository)
Registers an arbitrary event sourcing repository with the fixture. The repository must be wired with the Event Store of this test fixture.

Should not be used in combination with registerAggregateFactory(org.axonframework.eventsourcing.AggregateFactory), as that will overwrite any repository previously registered.

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

registerAggregateFactory

FixtureConfiguration<T> registerAggregateFactory(AggregateFactory<T> aggregateFactory)
Registers the given 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 registerRepository(org.axonframework.eventsourcing.EventSourcingRepository), as that will overwrite any aggregate factory previously registered.

Parameters:
aggregateFactory - The Aggregate Factory to create empty aggregates with
Returns:
the current FixtureConfiguration, for fluent interfacing

registerAnnotatedCommandHandler

FixtureConfiguration<T> 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<T> registerCommandHandler(Class<?> payloadType,
                                               CommandHandler commandHandler)
Registers a commandHandler to handle commands of the given commandType with the command bus used by this fixture.

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

registerCommandHandler

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.

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

registerInjectableResource

FixtureConfiguration<T> registerInjectableResource(Object resource)
Registers a resource that is eligible for injection in handler method (e.g. methods annotated with @CommandHandler, @EventSourcingHandler and @EventHandler. These resource must be registered before registering any command handler.

Parameters:
resource - The resource eligible for injection
Returns:
the current FixtureConfiguration, for fluent interfacing

registerFieldFilter

FixtureConfiguration<T> registerFieldFilter(FieldFilter fieldFilter)
Registers the given 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.

Parameters:
fieldFilter - The FieldFilter that defines which fields to include in the comparison
Returns:
the current FixtureConfiguration, for fluent interfacing

registerIgnoredField

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.

Parameters:
declaringClass - The class declaring the field
fieldName - The name of the field
Returns:
the current FixtureConfiguration, for fluent interfacing
Throws:
FixtureExecutionException - when no such field is declared

given

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

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

givenNoPriorActivity

TestExecutor givenNoPriorActivity()
Indicates that no relevant activity has occurred in the past. The behavior of this method is identical to giving no events in the given(java.util.List) method.

Returns:
a TestExecutor instance that can execute the test with this configuration
Since:
2.1.1

given

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

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

givenCommands

TestExecutor givenCommands(Object... commands)
Configures the given commands as the command that will provide the "given" events. The commands are executed, and the resulting stored events are captured.

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

givenCommands

TestExecutor givenCommands(List<?> commands)
Configures the given commands as the command that will provide the "given" events. The commands are executed, and the resulting stored events are captured.

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

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

Repository<T> 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

setReportIllegalStateChange

void setReportIllegalStateChange(boolean reportIllegalStateChange)
Sets whether or not the fixture should detect and report state changes that occur outside of Event Handler methods.

Parameters:
reportIllegalStateChange - whether or not to detect and report state changes outside of Event Handler methods.


Copyright © 2010-2016. All Rights Reserved.