Class KeyValueEntityTestKit<S,E extends akka.javasdk.keyvalueentity.KeyValueEntity<S>>

Object
akka.javasdk.testkit.KeyValueEntityTestKit<S,E>

public class KeyValueEntityTestKit<S,E extends akka.javasdk.keyvalueentity.KeyValueEntity<S>> extends Object
KeyValueEntity Testkit for use in unit tests for Value entities.

To test a KeyValueEntity create a testkit instance by calling one of the available KeyValueEntityTestKit.of methods. The returned testkit is stateful, and it holds internally the state of the entity.

Use the call methods to interact with the testkit.

  • Method Summary

    Modifier and Type
    Method
    Description
    call(Function<E,akka.javasdk.keyvalueentity.KeyValueEntity.Effect<R>> func)
    The call method can be used to simulate a call to the KeyValueEntity.
    call(Function<E,akka.javasdk.keyvalueentity.KeyValueEntity.Effect<R>> func, akka.javasdk.Metadata metadata)
    The call method can be used to simulate a call to the KeyValueEntity.
     
    boolean
     
    static <S, E extends akka.javasdk.keyvalueentity.KeyValueEntity<S>>
    KeyValueEntityTestKit<S,E>
    of(String entityId, Function<akka.javasdk.keyvalueentity.KeyValueEntityContext,E> entityFactory)
    Creates a new testkit instance from a user defined entity id and a function KeyValueEntityContext to KeyValueEntity.
    static <S, E extends akka.javasdk.keyvalueentity.KeyValueEntity<S>>
    KeyValueEntityTestKit<S,E>
    of(String entityId, Supplier<E> entityFactory)
    Creates a new testkit instance from a user defined entity id and a KeyValueEntity Supplier.
    static <S, E extends akka.javasdk.keyvalueentity.KeyValueEntity<S>>
    KeyValueEntityTestKit<S,E>
    of(Function<akka.javasdk.keyvalueentity.KeyValueEntityContext,E> entityFactory)
    Creates a new testkit instance from a function KeyValueEntityContext to KeyValueEntity.
    static <S, E extends akka.javasdk.keyvalueentity.KeyValueEntity<S>>
    KeyValueEntityTestKit<S,E>
    of(Supplier<E> entityFactory)
    Creates a new testkit instance from a KeyValueEntity Supplier.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • of

      public static <S, E extends akka.javasdk.keyvalueentity.KeyValueEntity<S>> KeyValueEntityTestKit<S,E> of(Supplier<E> entityFactory)
      Creates a new testkit instance from a KeyValueEntity Supplier.

      A default test entity id will be automatically provided.

    • of

      public static <S, E extends akka.javasdk.keyvalueentity.KeyValueEntity<S>> KeyValueEntityTestKit<S,E> of(Function<akka.javasdk.keyvalueentity.KeyValueEntityContext,E> entityFactory)
      Creates a new testkit instance from a function KeyValueEntityContext to KeyValueEntity.

      A default test entity id will be automatically provided.

    • of

      public static <S, E extends akka.javasdk.keyvalueentity.KeyValueEntity<S>> KeyValueEntityTestKit<S,E> of(String entityId, Supplier<E> entityFactory)
      Creates a new testkit instance from a user defined entity id and a KeyValueEntity Supplier.
    • of

      public static <S, E extends akka.javasdk.keyvalueentity.KeyValueEntity<S>> KeyValueEntityTestKit<S,E> of(String entityId, Function<akka.javasdk.keyvalueentity.KeyValueEntityContext,E> entityFactory)
      Creates a new testkit instance from a user defined entity id and a function KeyValueEntityContext to KeyValueEntity.
    • getState

      public S getState()
      Returns:
      The current state of the key value entity under test
    • isDeleted

      public boolean isDeleted()
      Returns:
      true if the entity is deleted
    • call

      public <R> KeyValueEntityResult<R> call(Function<E,akka.javasdk.keyvalueentity.KeyValueEntity.Effect<R>> func)
      The call method can be used to simulate a call to the KeyValueEntity. The passed java lambda should return a KeyValueEntity.Effect. The Effect is interpreted into a KeyValueEntityResult that can be used in test assertions.
      Type Parameters:
      R - The type of reply that is expected from invoking a command handler
      Parameters:
      func - A function from KeyValueEntity to KeyValueEntity.Effect.
      Returns:
      a KeyValueEntityResult
    • call

      public <R> KeyValueEntityResult<R> call(Function<E,akka.javasdk.keyvalueentity.KeyValueEntity.Effect<R>> func, akka.javasdk.Metadata metadata)
      The call method can be used to simulate a call to the KeyValueEntity. The passed java lambda should return a KeyValueEntity.Effect. The Effect is interpreted into a KeyValueEntityResult that can be used in test assertions.
      Type Parameters:
      R - The type of reply that is expected from invoking a command handler
      Parameters:
      func - A function from KeyValueEntity to KeyValueEntity.Effect.
      metadata - A metadata passed as a call context.
      Returns:
      a KeyValueEntityResult