Package org.axonframework.test.aggregate
Class StubAggregateLifecycle
java.lang.Object
org.axonframework.messaging.Scope
org.axonframework.modelling.command.AggregateLifecycle
org.axonframework.test.aggregate.StubAggregateLifecycle
- Direct Known Subclasses:
StubAggregateLifecycleExtension,StubAggregateLifecycleRule
Stub implementation of an AggregateLifecycle that registers all applied events for verification later. This
lifecycle instance can be activated (see
activate()) and deactivated (see close()) at will. Events
applied while it is active are stored and can be retrieved using getAppliedEvents() or
getAppliedEventPayloads().
When using with JUnit, consider using the StubAggregateLifecycleRule with @Rule
instead, as it is easier and safer to use.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate()Activates this lifecycle instance.voidclose()Closes this lifecycle instance, restoring to the situation prior to this lifecycle being started.protected <T> ApplyMoreApply aDomainEventMessagewith given payload and metadata (metadata from interceptors will be combined with the provided metadata).protected <T> Aggregate<T> doCreateNew(Class<T> aggregateType, Callable<T> factoryMethod) Creates a new aggregate instance.protected voidMarks this aggregate as deleted.Returns the payloads of the Events applied while this lifecycle instance was active.List<EventMessage<?>> Returns the list of applied Events for this lifecycle instance.protected booleanIndicates whether this Aggregate instance is 'live'.protected ObjectRetrieve aObjectdenoting the identifier of this Aggregate.booleanIndicates whether an Aggregate has invoked "markDeleted" while this lifecycle was active.protected Stringtype()Retrieve aStringdenoting the type of this Aggregate.protected Longversion()Gets the version of the aggregate.Methods inherited from class org.axonframework.modelling.command.AggregateLifecycle
apply, apply, createNew, describeScope, execute, getInstance, getVersion, isLive, markDeletedMethods inherited from class org.axonframework.messaging.Scope
describeCurrentScope, endScope, executeWithResult, getCurrentScope, startScope
-
Constructor Details
-
StubAggregateLifecycle
public StubAggregateLifecycle()
-
-
Method Details
-
activate
public void activate()Activates this lifecycle instance. Any invocations to static AggregateLifecycle methods will use this instance untilclose()is called. -
close
public void close()Closes this lifecycle instance, restoring to the situation prior to this lifecycle being started. If any lifecycle instance was active before this one started, it will be reactivated. -
getIsLive
protected boolean getIsLive()Description copied from class:AggregateLifecycleIndicates whether this Aggregate instance is 'live'. This means events currently applied represent events that are currently happening, as opposed to events representing historic decisions.- Specified by:
getIsLivein classAggregateLifecycle- Returns:
trueif the aggregate is 'live',falseif the aggregate is initializing state based on historic events
-
doCreateNew
protected <T> Aggregate<T> doCreateNew(Class<T> aggregateType, Callable<T> factoryMethod) throws Exception Description copied from class:AggregateLifecycleCreates a new aggregate instance. In order for new aggregate to be created, aRepositoryshould be available to the current aggregate.Repositoryof an aggregate to be created is exposed to the current aggregate viaRepositoryProvider.- Specified by:
doCreateNewin classAggregateLifecycle- Type Parameters:
T- type of new aggregate to be created- Parameters:
aggregateType- type of new aggregate to be createdfactoryMethod- factory method which creates new aggregate- Returns:
- a new aggregate instance
- Throws:
Exception- thrown if something goes wrong during instantiation of new aggregate
-
type
Description copied from class:AggregateLifecycleRetrieve aStringdenoting the type of this Aggregate.- Specified by:
typein classAggregateLifecycle- Returns:
- a
Stringdenoting the type of this Aggregate
-
identifier
Description copied from class:AggregateLifecycleRetrieve aObjectdenoting the identifier of this Aggregate.- Specified by:
identifierin classAggregateLifecycle- Returns:
- a
Objectdenoting the identifier of this Aggregate
-
version
Description copied from class:AggregateLifecycleGets the version of the aggregate.- Specified by:
versionin classAggregateLifecycle- Returns:
- the current version of the aggregate
-
doMarkDeleted
protected void doMarkDeleted()Description copied from class:AggregateLifecycleMarks this aggregate as deleted. Implementations may react differently to aggregates marked for deletion. Typically, Event Sourced Repositories will ignore the marking and expect deletion to be provided as part of Event information.- Specified by:
doMarkDeletedin classAggregateLifecycle
-
doApply
Description copied from class:AggregateLifecycleApply aDomainEventMessagewith given payload and metadata (metadata from interceptors will be combined with the provided metadata). The event should be applied to the aggregate immediately and scheduled for publication to other event handlers. The event should be applied on all entities part of this aggregate. If the event is applied from an event handler of the aggregate and additional events need to be applied that depends on state changes brought about by the first event the returnedApplyMoreinstance should allow for additional events to be applied after this event.- Specified by:
doApplyin classAggregateLifecycle- Parameters:
payload- the payload of the event to applymetaData- any meta-data that must be registered with the Event- Returns:
- a gizmo to apply additional events after the given event has been processed by the entire aggregate
- See Also:
-
getAppliedEvents
Returns the list of applied Events for this lifecycle instance.Note that this list is not reset when activating or deactivating the lifecycle.
- Returns:
- the list of messages applied while this lifecycle instance was active
-
getAppliedEventPayloads
Returns the payloads of the Events applied while this lifecycle instance was active. This is usually the parameter passed to theAggregateLifecycle.apply(Object)method.- Returns:
- the payloads of the applied events.
-
isMarkedDeleted
public boolean isMarkedDeleted()Indicates whether an Aggregate has invoked "markDeleted" while this lifecycle was active.- Returns:
trueifAggregateLifecycle.markDeleted()was invoked, otherwisefalse
-