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.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    final class 
     
    final class 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    call(akka.japi.function.Function<E,akka.javasdk.keyvalueentity.KeyValueEntity.Effect<R>> func)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use "method(MyEntity::myCommandHandler).invoke()" instead
    call(akka.japi.function.Function<E,akka.javasdk.keyvalueentity.KeyValueEntity.Effect<R>> func, akka.javasdk.Metadata metadata)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use "method(MyEntity::myCommandHandler).withMetadata(metadata).invoke()" instead
     
    boolean
     
    method(akka.japi.function.Function<E,akka.javasdk.keyvalueentity.KeyValueEntity.Effect<R>> func)
    Pass in a Key Value Entity command handler method reference without parameters, e.g.
    method(akka.japi.function.Function2<E,I,akka.javasdk.keyvalueentity.KeyValueEntity.Effect<R>> func)
    Pass in a Key Value Entity command handler method reference with a single parameter, e.g.
    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
    • method

      public <R> KeyValueEntityTestKit<S,E>.MethodRef<R> method(akka.japi.function.Function<E,akka.javasdk.keyvalueentity.KeyValueEntity.Effect<R>> func)
      Pass in a Key Value Entity command handler method reference without parameters, e.g. UserEntity::create
    • method

      public <I, R> KeyValueEntityTestKit<S,E>.MethodRef1<I,R> method(akka.japi.function.Function2<E,I,akka.javasdk.keyvalueentity.KeyValueEntity.Effect<R>> func)
      Pass in a Key Value Entity command handler method reference with a single parameter, e.g. UserEntity::create
    • call

      @Deprecated(since="3.2.1", forRemoval=true) public <R> KeyValueEntityResult<R> call(akka.japi.function.Function<E,akka.javasdk.keyvalueentity.KeyValueEntity.Effect<R>> func)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use "method(MyEntity::myCommandHandler).invoke()" instead
      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

      @Deprecated(since="3.2.1", forRemoval=true) public <R> KeyValueEntityResult<R> call(akka.japi.function.Function<E,akka.javasdk.keyvalueentity.KeyValueEntity.Effect<R>> func, akka.javasdk.Metadata metadata)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use "method(MyEntity::myCommandHandler).withMetadata(metadata).invoke()" instead
      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