Package kalix.javasdk.testkit
Class ValueEntityTestKit<S,E extends kalix.javasdk.valueentity.ValueEntity<S>>
Object
kalix.javasdk.testkit.ValueEntityTestKit<S,E>
public class ValueEntityTestKit<S,E extends kalix.javasdk.valueentity.ValueEntity<S>>
extends Object
ValueEntity Testkit for use in unit tests for Value entities.
To test a ValueEntity create a testkit instance by calling one of the available
ValueEntityTestKit.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 TypeMethodDescription<R> kalix.javasdk.testkit.ValueEntityResult<R>
The call method can be used to simulate a call to the ValueEntity.<R> kalix.javasdk.testkit.ValueEntityResult<R>
call
(Function<E, kalix.javasdk.valueentity.ValueEntity.Effect<R>> func, kalix.javasdk.Metadata metadata) The call method can be used to simulate a call to the ValueEntity.getState()
static <S,
E extends kalix.javasdk.valueentity.ValueEntity<S>>
ValueEntityTestKit<S,E> Creates a new testkit instance from a user defined entity id and a function ValueEntityContext to ValueEntity.static <S,
E extends kalix.javasdk.valueentity.ValueEntity<S>>
ValueEntityTestKit<S,E> Creates a new testkit instance from a user defined entity id and a ValueEntity Supplier.static <S,
E extends kalix.javasdk.valueentity.ValueEntity<S>>
ValueEntityTestKit<S,E> Creates a new testkit instance from a function ValueEntityContext to ValueEntity.static <S,
E extends kalix.javasdk.valueentity.ValueEntity<S>>
ValueEntityTestKit<S,E> Creates a new testkit instance from a ValueEntity Supplier.
-
Method Details
-
of
public static <S,E extends kalix.javasdk.valueentity.ValueEntity<S>> ValueEntityTestKit<S,E> of(Supplier<E> entityFactory) Creates a new testkit instance from a ValueEntity Supplier.A default test entity id will be automatically provided.
-
of
public static <S,E extends kalix.javasdk.valueentity.ValueEntity<S>> ValueEntityTestKit<S,E> of(Function<kalix.javasdk.valueentity.ValueEntityContext, E> entityFactory) Creates a new testkit instance from a function ValueEntityContext to ValueEntity.A default test entity id will be automatically provided.
-
of
public static <S,E extends kalix.javasdk.valueentity.ValueEntity<S>> ValueEntityTestKit<S,E> of(String entityId, Supplier<E> entityFactory) Creates a new testkit instance from a user defined entity id and a ValueEntity Supplier. -
of
public static <S,E extends kalix.javasdk.valueentity.ValueEntity<S>> ValueEntityTestKit<S,E> of(String entityId, Function<kalix.javasdk.valueentity.ValueEntityContext, E> entityFactory) Creates a new testkit instance from a user defined entity id and a function ValueEntityContext to ValueEntity. -
getState
- Returns:
- The current state of the value entity under test
-
call
public <R> kalix.javasdk.testkit.ValueEntityResult<R> call(Function<E, kalix.javasdk.valueentity.ValueEntity.Effect<R>> func) The call method can be used to simulate a call to the ValueEntity. The passed java lambda should return a ValueEntity.Effect. The Effect is interpreted into a ValueEntityResult 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 ValueEntity to ValueEntity.Effect.- Returns:
- a ValueEntityResult
-
call
public <R> kalix.javasdk.testkit.ValueEntityResult<R> call(Function<E, kalix.javasdk.valueentity.ValueEntity.Effect<R>> func, kalix.javasdk.Metadata metadata) The call method can be used to simulate a call to the ValueEntity. The passed java lambda should return a ValueEntity.Effect. The Effect is interpreted into a ValueEntityResult 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 ValueEntity to ValueEntity.Effect.metadata
- A metadata passed as a call context.- Returns:
- a ValueEntityResult
-