Package com.opencqrs.framework.command
Interface EventAsserting
- All Known Implementing Classes:
CommandHandlingTestFixture.EventAsserter
public interface EventAsserting
Interface for comprehensive assertions on captured events, providing access to payload, meta-data, and subject.
Instances are obtained via
ExpectDsl.EventValidator.asserting(Consumer).
The API follows a consistent pattern for each event aspect:
- Direct comparison methods (
payload(E),metaData(java.util.Map<java.lang.String, ?>),subject(java.lang.String)) - Consumer-based methods for custom assertions (
payloadSatisfying(java.util.function.Consumer<E>),metaDataSatisfying(java.util.function.Consumer<java.util.Map<java.lang.String, ?>>),subjectSatisfying(java.util.function.Consumer<java.lang.String>)) - Specialized convenience methods (
payloadType(java.lang.Class<?>),payloadExtracting(java.util.function.Function<E, R>, R),noMetaData(),commandSubject())
All methods return this to allow method chaining.
-
Method Summary
Modifier and TypeMethodDescriptionAsserts that the event subject equals the command's subject.Asserts that the event meta-data equals the expected map usingObject.equals(Object).metaDataSatisfying(Consumer<Map<String, ?>> assertion) Asserts that the event meta-data satisfies custom assertions.Asserts that the event has no meta-data (empty map).<E> EventAssertingpayload(E expected) Asserts that the event payload equals the expected value usingObject.equals(Object).<E,R> EventAsserting payloadExtracting(Function<E, R> extractor, R expected) Extracts a value from the event payload and asserts it equals the expected value.<E> EventAssertingpayloadSatisfying(Consumer<E> assertion) Asserts that the event payload satisfies custom assertions.payloadType(Class<?> type) Asserts that the event payload is an instance of the specified type.Asserts that the event subject equals the expected value.subjectSatisfying(Consumer<String> assertion) Asserts that the event subject satisfies custom assertions.
-
Method Details
-
payloadType
Asserts that the event payload is an instance of the specified type.- Parameters:
type- the expected payload class- Returns:
thisfor further assertions- Throws:
AssertionError- if the payload is not assignable to the expected type
-
payload
Asserts that the event payload equals the expected value usingObject.equals(Object).- Type Parameters:
E- the payload type- Parameters:
expected- the expected payload- Returns:
thisfor further assertions- Throws:
AssertionError- if the payloads are not equal
-
payloadExtracting
Extracts a value from the event payload and asserts it equals the expected value. Useful for comparing specific fields without matching the entire payload.Example:
a.payloadExtracting((MyEvent e) -> e.name(), "expected-name")- Type Parameters:
E- the payload typeR- the extracted value type- Parameters:
extractor- function to extract a value from the payloadexpected- the expected extracted value (may benull)- Returns:
thisfor further assertions- Throws:
AssertionError- if the extracted values are not equal
-
payloadSatisfying
Asserts that the event payload satisfies custom assertions.- Type Parameters:
E- the payload type- Parameters:
assertion- consumer receiving the payload- Returns:
thisfor further assertions- Throws:
AssertionError- if thrown by the consumer
-
metaData
Asserts that the event meta-data equals the expected map usingObject.equals(Object).- Parameters:
expected- the expected meta-data- Returns:
thisfor further assertions- Throws:
AssertionError- if the meta-data maps are not equal
-
metaDataSatisfying
Asserts that the event meta-data satisfies custom assertions.- Parameters:
assertion- consumer receiving the meta-data map- Returns:
thisfor further assertions- Throws:
AssertionError- if thrown by the consumer
-
noMetaData
EventAsserting noMetaData()Asserts that the event has no meta-data (empty map).- Returns:
thisfor further assertions- Throws:
AssertionError- if the meta-data is not empty
-
subject
Asserts that the event subject equals the expected value.- Parameters:
expected- the expected subject- Returns:
thisfor further assertions- Throws:
AssertionError- if the subjects are not equal
-
subjectSatisfying
Asserts that the event subject satisfies custom assertions.- Parameters:
assertion- consumer receiving the subject- Returns:
thisfor further assertions- Throws:
AssertionError- if thrown by the consumer
-
commandSubject
EventAsserting commandSubject()Asserts that the event subject equals the command's subject. Convenience method equivalent tosubject(command.getSubject()).- Returns:
thisfor further assertions- Throws:
AssertionError- if the subjects do not match
-