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 Details

    • KalixTestKitResource

      public KalixTestKitResource(kalix.javasdk.Kalix kalix)
    • KalixTestKitResource

      public KalixTestKitResource(kalix.javasdk.Kalix kalix, KalixTestKit.Settings settings)
    • 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 class org.junit.rules.ExternalResource
    • after

      protected void after()
      JUnit4 support - rule based
      Overrides:
      after in class org.junit.rules.ExternalResource
    • getTopic

      @Deprecated public EventingTestKit.Topic getTopic(String topic)
      Deprecated.
      Use getTopicIncomingMessages or getTopicOutgoingMessages instead.

      If your Kalix service publishes or consumes from/to an eventing services (i.e. kafka or pub/sub), this will allow assertions on messages consumed / produced to such broker.

      Parameters:
      topic - name of the topic to interact with
      Returns:
      a structure to allow interactions with a topic
    • getValueEntityIncomingMessages

      public EventingTestKit.IncomingMessages getValueEntityIncomingMessages(String typeId)
      Get incoming messages for ValueEntity.
      Parameters:
      typeId -
    • getEventSourcedEntityIncomingMessages

      public EventingTestKit.IncomingMessages getEventSourcedEntityIncomingMessages(String typeId)
      Get incoming messages for EventSourcedEntity.
      Parameters:
      typeId -
    • getStreamIncomingMessages

      public EventingTestKit.IncomingMessages getStreamIncomingMessages(String service, String streamId)
      Get incoming messages for Stream (eventing.in.direct in case of protobuf SDKs).
      Parameters:
      service - service name
      streamId - service stream id
    • getTopicIncomingMessages

      public EventingTestKit.IncomingMessages getTopicIncomingMessages(String topic)
      Get incoming messages for Topic.
      Parameters:
      topic - topic name
    • getTopicOutgoingMessages

      public EventingTestKit.OutgoingMessages getTopicOutgoingMessages(String topic)
      Get mocked topic destination.
      Parameters:
      topic - topic name
    • getMessageBuilder

      public EventingTestKit.MessageBuilder getMessageBuilder()
      Returns EventingTestKit.MessageBuilder utility to create EventingTestKit.Messages for the eventing testkit.
    • getHost

      public String 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

      public <T> T getGrpcClient(Class<T> clientClass)
      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 an ActorSystem for creating Akka HTTP clients.
      Returns:
      test actor system
    • getGrpcClientSettings

      @Deprecated(since="0.8.1", forRemoval=true) public akka.grpc.GrpcClientSettings getGrpcClientSettings()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getGrpcClient instead.
      Get GrpcClientSettings for creating Akka gRPC clients.
      Returns:
      test gRPC client settings