Package kalix.javasdk.testkit
Class ActionTestkit<A extends kalix.javasdk.action.Action>
Object
kalix.javasdk.testkit.ActionTestkit<A>
Action Testkit for use in unit tests for Actions.
To test an Action create a testkit instance by calling one of the available
ActionTestkit.of
methods. The returned testkit can be used as many times as you want. It doesn't
preserve any state between invocations.
Use the call or stream
methods to interact with the testkit.
-
Method Summary
Modifier and TypeMethodDescription<R> kalix.javasdk.testkit.ActionResult<R>
Thecall
method can be used to simulate a unary call to the Action.<R> kalix.javasdk.testkit.ActionResult<R>
Thecall
method can be used to simulate a unary call to the Action.static <A extends kalix.javasdk.action.Action>
ActionTestkit<A>static <A extends kalix.javasdk.action.Action>
ActionTestkit<A><R> reactor.core.publisher.Flux<kalix.javasdk.testkit.ActionResult<R>>
streamedCall
(Function<A, reactor.core.publisher.Flux<kalix.javasdk.action.Action.Effect<R>>> func) ThestreamedCall
method can be used to simulate a streamed call to the Action.
-
Method Details
-
of
public static <A extends kalix.javasdk.action.Action> ActionTestkit<A> of(Function<kalix.javasdk.action.ActionCreationContext, A> actionFactory) -
of
public static <A extends kalix.javasdk.action.Action> ActionTestkit<A> of(Supplier<A> actionFactory) -
call
public <R> kalix.javasdk.testkit.ActionResult<R> call(Function<A, kalix.javasdk.action.Action.Effect<R>> func) Thecall
method can be used to simulate a unary call to the Action. The passed java lambda should return an Action.Effect. The Effect is interpreted into an ActionResult 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 Action to Action.Effect- Returns:
- an ActionResult
-
call
public <R> kalix.javasdk.testkit.ActionResult<R> call(Function<A, kalix.javasdk.action.Action.Effect<R>> func, kalix.javasdk.Metadata metadata) Thecall
method can be used to simulate a unary call to the Action. The passed java lambda should return an Action.Effect. The Effect is interpreted into an ActionResult 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 Action to Action.Effectmetadata
- A metadata passed as a call context- Returns:
- an ActionResult
-
streamedCall
public <R> reactor.core.publisher.Flux<kalix.javasdk.testkit.ActionResult<R>> streamedCall(Function<A, reactor.core.publisher.Flux<kalix.javasdk.action.Action.Effect<R>>> func) ThestreamedCall
method can be used to simulate a streamed call to the Action. The passed java lambda should return aFlux<Action.Effect>
. TheFlux<Action.Effect>
is interpreted into anFlux<ActionResult>
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 fromFlux<Action.Effect>
to aFlux<ActionResult<R>>
- Returns:
- a
Flux<ActionResult<R>>
-