Package kalix.javasdk.testkit.junit
Class KalixTestKitResource
Object
org.junit.rules.ExternalResource
kalix.javasdk.testkit.junit.KalixTestKitResource
- All Implemented Interfaces:
org.junit.rules.TestRule
public final class KalixTestKitResource
extends org.junit.rules.ExternalResource
A JUnit 4 external resource for
KalixTestKit
, which automatically manages the lifecycle of
the testkit. The testkit will be automatically stopped when the test completes or fails.
If you prefer JUnit 5 "Jupiter" use KalixTestKitExtension
.
Example:
import kalix.javasdk.testkit.junit.KalixTestKitResource; public class MyKalixIntegrationTest { private static final Kalix MY_KALIX = new Kalix(); // with registered services @ClassRule public static final KalixTestKitResource testKit = new KalixTestKitResource(MY_KALIX); private final MyServiceClient client; // generated Akka gRPC client public MyKalixIntegrationTest() { this.client = MyServiceClient.create(testKit.getGrpcClientSettings(), testKit.getActorSystem()); } @Test public void test() { // use client to test service } }
-
Constructor Summary
ConstructorsConstructorDescriptionKalixTestKitResource
(kalix.javasdk.Kalix kalix) KalixTestKitResource
(kalix.javasdk.Kalix kalix, kalix.javasdk.impl.MessageCodec messageCodec, KalixTestKit.Settings settings) KalixTestKitResource
(kalix.javasdk.Kalix kalix, KalixTestKit.Settings settings) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
after()
JUnit4 support - rule basedprotected void
before()
JUnit4 support - rule basedakka.actor.ActorSystem
Get anActorSystem
for creating Akka HTTP clients.Get incoming messages for EventSourcedEntity.<T> T
getGrpcClient
(Class<T> clientClass) Get an Akka gRPC client for the given service name.getHost()
Get the host name/IP address where the Kalix service is available.akka.stream.Materializer
An Akka Stream materializer to use for running streams.ReturnsEventingTestKit.MessageBuilder
utility to createEventingTestKit.Message
s for the eventing testkit.int
getPort()
Get the local port where the Kalix service is available.getStreamIncomingMessages
(String service, String streamId) Get incoming messages for Stream (eventing.in.direct in case of protobuf SDKs).getTopicIncomingMessages
(String topic) Get incoming messages for Topic.getTopicOutgoingMessages
(String topic) Get mocked topic destination.getValueEntityIncomingMessages
(String typeId) Get incoming messages for ValueEntity.Methods inherited from class org.junit.rules.ExternalResource
apply
-
Constructor Details
-
KalixTestKitResource
public KalixTestKitResource(kalix.javasdk.Kalix kalix) -
KalixTestKitResource
-
KalixTestKitResource
public KalixTestKitResource(kalix.javasdk.Kalix kalix, kalix.javasdk.impl.MessageCodec messageCodec, KalixTestKit.Settings settings)
-
-
Method Details
-
before
protected void before()JUnit4 support - rule based- Overrides:
before
in classorg.junit.rules.ExternalResource
-
after
protected void after()JUnit4 support - rule based- Overrides:
after
in classorg.junit.rules.ExternalResource
-
getValueEntityIncomingMessages
Get incoming messages for ValueEntity.- Parameters:
typeId
-
-
getEventSourcedEntityIncomingMessages
Get incoming messages for EventSourcedEntity.- Parameters:
typeId
-
-
getStreamIncomingMessages
Get incoming messages for Stream (eventing.in.direct in case of protobuf SDKs).- Parameters:
service
- service namestreamId
- service stream id
-
getTopicIncomingMessages
Get incoming messages for Topic.- Parameters:
topic
- topic name
-
getTopicOutgoingMessages
Get mocked topic destination.- Parameters:
topic
- topic name
-
getMessageBuilder
ReturnsEventingTestKit.MessageBuilder
utility to createEventingTestKit.Message
s for the eventing testkit. -
getHost
Get the host name/IP address where the Kalix service is available. This is relevant in certain Continuous Integration environments.- Returns:
- Kalix host
-
getPort
public int getPort()Get the local port where the Kalix service is available.- Returns:
- local Kalix port
-
getGrpcClient
Get an Akka gRPC client for the given service name. The same client instance is shared for the test. The lifecycle of the client is managed by the SDK and it should not be stopped by user code.- Type Parameters:
T
- The "service" interface generated for the service by Akka gRPC- Parameters:
clientClass
- The class of a gRPC service generated by Akka gRPC
-
getMaterializer
public akka.stream.Materializer getMaterializer()An Akka Stream materializer to use for running streams. Needed for example in a command handler which accepts streaming elements but returns a single async reply once all streamed elements has been consumed. -
getActorSystem
public akka.actor.ActorSystem getActorSystem()Get anActorSystem
for creating Akka HTTP clients.- Returns:
- test actor system
-