Package com.opencqrs.framework.command
Interface EventSpecifierDsl
public interface EventSpecifierDsl
Fluent API for specifying the attributes of a single given event. Instances are passed to the consumer in
GivenDsl.event(java.util.function.Consumer).
The only required method is payload(Object) - all other attributes have the following defaults if not
explicitly specified via this:
subject- uses the value fromGivenDsl.usingSubject(String)or the command's subjecttime- uses the value fromGivenDsl.time(Instant)orInstant.now()id- generated randomlymetaData- empty map
Example:
fixture.given()
.event(e -> e
.payload(new OrderPlacedEvent("order-123", "customer-456"))
.subject("/orders/order-123")
.time(Instant.parse("2024-01-15T14:30:00Z"))
.id("event-001")
.metaData(Map.of("userId", "user-789")))
.when(...)
-
Method Summary
Modifier and TypeMethodDescriptionSets the unique identifier for this event.Sets the meta-data for this event.Sets the event payload.Sets the subject for this specific event, overriding the value fromGivenDsl.usingSubject(String).Sets the timestamp for this specific event, overriding the value fromGivenDsl.time(Instant).
-
Method Details
-
payload
Sets the event payload. This is the actual event object that will be passed to theStateRebuildingHandler.This method must be called - an
IllegalArgumentExceptionis thrown if the event is used without specifying a payload.- Parameters:
payload- the event payload object- Returns:
thisfor method chaining
-
time
Sets the timestamp for this specific event, overriding the value fromGivenDsl.time(Instant). This timestamp is available inStateRebuildingHandler.FromObjectAndRawEventvia the raw event'stime()method.- Parameters:
time- the timestamp for this event- Returns:
thisfor method chaining
-
subject
Sets the subject for this specific event, overriding the value fromGivenDsl.usingSubject(String). This subject is applied as the raw event's subject.- Parameters:
subject- the subject for this event, ornullto use the default- Returns:
thisfor method chaining
-
id
Sets the unique identifier for this event. If not specified, a random UUID is generated. This id is available inStateRebuildingHandler.FromObjectAndRawEventvia the raw event'sid()method.- Parameters:
id- the unique identifier for this event- Returns:
thisfor method chaining
-
metaData
Sets the meta-data for this event. Meta-data is available inStateRebuildingHandler.FromObjectAndMetaDataAndSubjectAndRawEvent.If not specified, an empty map is used.
- Parameters:
metaData- the meta-data map for this event- Returns:
thisfor method chaining
-