Class RecordingEventBus
- All Implemented Interfaces:
DescribableComponent,SubscribableEventSource,EventBus,EventSink
EventBus implementation recording all the events that are
published.
The recorded events can then be used to assert expectations with test cases.
- Since:
- 5.0.0
- Author:
- Mateusz Nowak
-
Field Summary
Fields inherited from class org.axonframework.test.fixture.RecordingEventSink
delegate -
Constructor Summary
ConstructorsConstructorDescriptionRecordingEventBus(EventBus delegate) Creates a newRecordingEventBusthat will record all events published to the givendelegate. -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.subscribe(BiFunction<List<? extends EventMessage>, ProcessingContext, CompletableFuture<?>> eventsBatchConsumer) Subscribe the giveneventsBatchConsumerto this event source.Methods inherited from class org.axonframework.test.fixture.RecordingEventSink
publish, recorded, reset
-
Constructor Details
-
RecordingEventBus
Creates a newRecordingEventBusthat will record all events published to the givendelegate.- Parameters:
delegate- TheEventBusto which events will be published.
-
-
Method Details
-
subscribe
public Registration subscribe(@Nonnull BiFunction<List<? extends EventMessage>, ProcessingContext, CompletableFuture<?>> eventsBatchConsumer) Description copied from interface:SubscribableEventSourceSubscribe the giveneventsBatchConsumerto this event source. When subscribed, it will receive all events published to this source since the subscription.If the given
eventsBatchConsumeris already subscribed, nothing happens.Note on
ProcessingContext: TheProcessingContextparameter passed to the consumer may benull. Whennull, it is the responsibility of the registeredeventsBatchConsumerto create an appropriateProcessingContextas needed for processing the events.- Specified by:
subscribein interfaceSubscribableEventSource- Parameters:
eventsBatchConsumer- The event batches consumer to subscribe.- Returns:
- A
Registrationhandle to unsubscribe theeventsBatchConsumer. When unsubscribed, it will no longer receive events.
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.Best Practices: As a general rule, all relevant fields of a
DescribableComponentimplementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing thedescribeTomethod, who should focus on providing information that is useful for understanding the component's configuration and state.Example implementation:
public void describeTo(ComponentDescriptor descriptor) { descriptor.describeProperty("name", this.name); descriptor.describeProperty("enabled", this.enabled); descriptor.describeProperty("configuration", this.configuration); // A nested component descriptor.describeProperty("handlers", this.eventHandlers); // A collection }- Specified by:
describeToin interfaceDescribableComponent- Overrides:
describeToin classRecordingEventSink- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-