org.axonframework.test
Class ResultValidatorImpl

java.lang.Object
  extended by org.axonframework.test.ResultValidatorImpl
All Implemented Interfaces:
CommandCallback<Object>, ResultValidator

public class ResultValidatorImpl
extends Object
implements ResultValidator, CommandCallback<Object>

Implementation of the ResultValidator. It also acts as a CommandCallback, and registers the actual result.

Since:
0.7
Author:
Allard Buijze

Constructor Summary
ResultValidatorImpl(Collection<DomainEventMessage> storedEvents, Collection<EventMessage> publishedEvents, FieldFilter fieldFilter)
          Initialize the ResultValidatorImpl with the given storedEvents and publishedEvents.
 
Method Summary
 void assertValidRecording()
          Makes sure the execution phase has finishes without any Errors ir FixtureExecutionExceptions.
 ResultValidator expectEvents(Object... expectedEvents)
          Expect the given set of events to have been stored and published.
 ResultValidator expectEventsMatching(org.hamcrest.Matcher<? extends Iterable<?>> matcher)
          Expect the published events to match the given matcher.
 ResultValidator expectException(Class<? extends Throwable> expectedException)
          Expect the given expectedException to occur during command handler execution.
 ResultValidator expectException(org.hamcrest.Matcher<?> matcher)
          Expect an exception to occur during command handler execution that matches with the given matcher.
 ResultValidator expectPublishedEvents(Object... expectedEvents)
          Expect the given set of events to have been published on the events bus.
 ResultValidator expectPublishedEventsMatching(org.hamcrest.Matcher<? extends Iterable<?>> matcher)
          Expect the list of published event to match the given matcher.
 ResultValidator expectReturnValue(org.hamcrest.Matcher<?> matcher)
          Expect the command handler to return a value that matches the given matcher after execution.
 ResultValidator expectReturnValue(Object expectedReturnValue)
          Expect the command handler to return the given expectedReturnValue after execution.
 ResultValidator expectStoredEvents(Object... expectedEvents)
          Expect the given set of events to have been stored in the event store.
 ResultValidator expectStoredEventsMatching(org.hamcrest.Matcher<? extends Iterable<?>> matcher)
          Expect the list of stored event to match the given matcher.
 ResultValidator expectVoidReturnType()
          Explicitly expect a void return type on the given command handler.
 void onFailure(Throwable cause)
          Invoked when command handling execution resulted in an error.
 void onSuccess(Object result)
          Invoked when command handling execution was successful.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResultValidatorImpl

public ResultValidatorImpl(Collection<DomainEventMessage> storedEvents,
                           Collection<EventMessage> publishedEvents,
                           FieldFilter fieldFilter)
Initialize the ResultValidatorImpl with the given storedEvents and publishedEvents.

Parameters:
storedEvents - The events that were stored during command execution
publishedEvents - The events that were published during command execution
fieldFilter - The filter describing which fields to include in the comparison
Method Detail

expectEvents

public ResultValidator expectEvents(Object... expectedEvents)
Description copied from interface: ResultValidator
Expect the given set of events to have been stored and published. Note that this assertion will fail if events were published but not saved. If you expect events (e.g. Application Events) to have been dispatched, use the ResultValidator.expectPublishedEvents(Object...) and ResultValidator.expectStoredEvents(Object...) methods instead.

All events are compared for equality using a shallow equals comparison on all the fields of the events. This means that all assigned values on the events' fields should have a proper equals implementation.

Note that the event identifier is ignored in the comparison.

Specified by:
expectEvents in interface ResultValidator
Parameters:
expectedEvents - The expected events, in the exact order they are expected to be dispatched and stored.
Returns:
the current ResultValidator, for fluent interfacing

expectEventsMatching

public ResultValidator expectEventsMatching(org.hamcrest.Matcher<? extends Iterable<?>> matcher)
Description copied from interface: ResultValidator
Expect the published events to match the given matcher. Note that this assertion will fail if events were published but not saved.

Note: if no events were published or stored, the matcher receives an empty List.

Specified by:
expectEventsMatching in interface ResultValidator
Parameters:
matcher - The matcher to match with the actually published events
Returns:
the current ResultValidator, for fluent interfacing

expectPublishedEvents

public ResultValidator expectPublishedEvents(Object... expectedEvents)
Description copied from interface: ResultValidator
Expect the given set of events to have been published on the events bus. If you expect the same events to be stored, too, consider using the ResultValidator.expectEvents(Object...) instead.

All events are compared for equality using a shallow equals comparison on all the fields of the events. This means that all assigned values on the events' fields should have a proper equals implementation.

Note that the event identifier is ignored in the comparison. For Application and System events, however, the source of the events must be equal, too.

Specified by:
expectPublishedEvents in interface ResultValidator
Parameters:
expectedEvents - The expected events, in the exact order they are expected to be dispatched.
Returns:
the current ResultValidator, for fluent interfacing

expectPublishedEventsMatching

public ResultValidator expectPublishedEventsMatching(org.hamcrest.Matcher<? extends Iterable<?>> matcher)
Description copied from interface: ResultValidator
Expect the list of published event to match the given matcher. This method will only take into account the events that have been published. Stored events that have not been published to the event bus are ignored.

Note: if no events were published, the matcher receives an empty List.

Specified by:
expectPublishedEventsMatching in interface ResultValidator
Parameters:
matcher - The matcher which validates the actual list of published events.
Returns:
the current ResultValidator, for fluent interfacing

expectStoredEvents

public ResultValidator expectStoredEvents(Object... expectedEvents)
Description copied from interface: ResultValidator
Expect the given set of events to have been stored in the event store. If you expect the same events to be published, too, consider using the ResultValidator.expectEvents(Object...) instead.

All events are compared for equality using a shallow equals comparison on all the fields of the events. This means that all assigned values on the events' fields should have a proper equals implementation.

Note that the event identifier is ignored in the comparison. For Application and System events, however, the source of the events must be equal, too.

Specified by:
expectStoredEvents in interface ResultValidator
Parameters:
expectedEvents - The expected events, in the exact order they are expected to be stored.
Returns:
the current ResultValidator, for fluent interfacing

expectStoredEventsMatching

public ResultValidator expectStoredEventsMatching(org.hamcrest.Matcher<? extends Iterable<?>> matcher)
Description copied from interface: ResultValidator
Expect the list of stored event to match the given matcher. This method will only take into account the events that have been stored. Stored events that have not been stored in the event store are ignored.

Note: if no events were stored, the matcher receives an empty List.

Specified by:
expectStoredEventsMatching in interface ResultValidator
Parameters:
matcher - The matcher which validates the actual list of stored events.
Returns:
the current ResultValidator, for fluent interfacing

expectVoidReturnType

public ResultValidator expectVoidReturnType()
Description copied from interface: ResultValidator
Explicitly expect a void return type on the given command handler. void is the recommended return value for all command handlers as they allow for a more scalable architecture.

Specified by:
expectVoidReturnType in interface ResultValidator
Returns:
the current ResultValidator, for fluent interfacing

expectReturnValue

public ResultValidator expectReturnValue(Object expectedReturnValue)
Description copied from interface: ResultValidator
Expect the command handler to return the given expectedReturnValue after execution. The actual and expected values are compared using their equals methods.

Specified by:
expectReturnValue in interface ResultValidator
Parameters:
expectedReturnValue - The expected return value of the command execution
Returns:
the current ResultValidator, for fluent interfacing

expectReturnValue

public ResultValidator expectReturnValue(org.hamcrest.Matcher<?> matcher)
Description copied from interface: ResultValidator
Expect the command handler to return a value that matches the given matcher after execution.

Specified by:
expectReturnValue in interface ResultValidator
Parameters:
matcher - The matcher to verify the actual return value against
Returns:
the current ResultValidator, for fluent interfacing

expectException

public ResultValidator expectException(Class<? extends Throwable> expectedException)
Description copied from interface: ResultValidator
Expect the given expectedException to occur during command handler execution. The actual exception should be exactly of that type, subclasses are not accepted.

Specified by:
expectException in interface ResultValidator
Parameters:
expectedException - The type of exception expected from the command handler execution
Returns:
the current ResultValidator, for fluent interfacing

expectException

public ResultValidator expectException(org.hamcrest.Matcher<?> matcher)
Description copied from interface: ResultValidator
Expect an exception to occur during command handler execution that matches with the given matcher.

Specified by:
expectException in interface ResultValidator
Parameters:
matcher - The matcher to validate the actual exception
Returns:
the current ResultValidator, for fluent interfacing

onSuccess

public void onSuccess(Object result)
Description copied from interface: CommandCallback
Invoked when command handling execution was successful.

Specified by:
onSuccess in interface CommandCallback<Object>
Parameters:
result - The result of the command handling execution, if any.

onFailure

public void onFailure(Throwable cause)
Description copied from interface: CommandCallback
Invoked when command handling execution resulted in an error.

Specified by:
onFailure in interface CommandCallback<Object>
Parameters:
cause - The exception raised during command handling

assertValidRecording

public void assertValidRecording()
Makes sure the execution phase has finishes without any Errors ir FixtureExecutionExceptions. If an error was recorded, it will be thrown immediately. This allow one to distinguish between failed tests, and tests in error.



Copyright © 2010-2016. All Rights Reserved.