Class StubAggregateLifecycle

java.lang.Object
org.axonframework.messaging.Scope
org.axonframework.modelling.command.AggregateLifecycle
org.axonframework.test.aggregate.StubAggregateLifecycle
Direct Known Subclasses:
StubAggregateLifecycleExtension, StubAggregateLifecycleRule

public class StubAggregateLifecycle extends org.axonframework.modelling.command.AggregateLifecycle
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Activates this lifecycle instance.
    void
    Closes this lifecycle instance, restoring to the situation prior to this lifecycle being started.
    protected <T> org.axonframework.modelling.command.ApplyMore
    doApply(T payload, org.axonframework.messaging.MetaData metaData)
     
    protected <T> org.axonframework.modelling.command.Aggregate<T>
    doCreateNew(Class<T> aggregateType, Callable<T> factoryMethod)
     
    protected void
     
    Returns the payloads of the Events applied while this lifecycle instance was active.
    List<org.axonframework.eventhandling.EventMessage<?>>
    Returns the list of applied Events for this lifecycle instance.
    protected boolean
     
    protected Object
     
    boolean
    Indicates whether an Aggregate has invoked "markDeleted" while this lifecycle was active.
    protected String
     
    protected Long
     

    Methods inherited from class org.axonframework.modelling.command.AggregateLifecycle

    apply, apply, createNew, describeScope, execute, getInstance, getVersion, isLive, markDeleted

    Methods inherited from class org.axonframework.messaging.Scope

    describeCurrentScope, endScope, executeWithResult, getCurrentScope, startScope

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 until close() 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()
      Specified by:
      getIsLive in class org.axonframework.modelling.command.AggregateLifecycle
    • doCreateNew

      protected <T> org.axonframework.modelling.command.Aggregate<T> doCreateNew(Class<T> aggregateType, Callable<T> factoryMethod) throws Exception
      Specified by:
      doCreateNew in class org.axonframework.modelling.command.AggregateLifecycle
      Throws:
      Exception
    • type

      protected String type()
      Specified by:
      type in class org.axonframework.modelling.command.AggregateLifecycle
    • identifier

      protected Object identifier()
      Specified by:
      identifier in class org.axonframework.modelling.command.AggregateLifecycle
    • version

      protected Long version()
      Specified by:
      version in class org.axonframework.modelling.command.AggregateLifecycle
    • doMarkDeleted

      protected void doMarkDeleted()
      Specified by:
      doMarkDeleted in class org.axonframework.modelling.command.AggregateLifecycle
    • doApply

      protected <T> org.axonframework.modelling.command.ApplyMore doApply(T payload, org.axonframework.messaging.MetaData metaData)
      Specified by:
      doApply in class org.axonframework.modelling.command.AggregateLifecycle
    • getAppliedEvents

      public List<org.axonframework.eventhandling.EventMessage<?>> 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

      public List<Object> getAppliedEventPayloads()
      Returns the payloads of the Events applied while this lifecycle instance was active. This is usually the parameter passed to the AggregateLifecycle.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:
      true if AggregateLifecycle.markDeleted() was invoked, otherwise false