Class TestKit.Settings

Object
akka.javasdk.testkit.TestKit.Settings
Enclosing class:
TestKit

public static class TestKit.Settings extends Object
Settings for testkit.
  • Field Details

    • DEFAULT

      public static TestKit.Settings DEFAULT
      Default settings for testkit.
    • serviceName

      public final String serviceName
      The name of this service when deployed.
    • aclEnabled

      public final boolean aclEnabled
      Whether ACL checking is enabled.
    • eventingSupport

      public final TestKit.Settings.EventingSupport eventingSupport
    • mockedEventing

      public final TestKit.MockedEventing mockedEventing
    • additionalConfig

      public final com.typesafe.config.Config additionalConfig
    • dependencyProvider

      public final Optional<akka.javasdk.DependencyProvider> dependencyProvider
    • disabledComponents

      public final Set<Class<?>> disabledComponents
    • overrideDisabledComponents

      public final boolean overrideDisabledComponents
      When true, the testkit disabled components override any disabled components from ServiceSetup, rather than being combined with them.
    • modelProvidersByAgentId

      public final Map<String,akka.javasdk.agent.ModelProvider> modelProvidersByAgentId
    • httpMocks

      public final Map<String,Function<akka.http.javadsl.model.HttpRequest,akka.http.javadsl.model.HttpResponse>> httpMocks
      Map from service name to a synchronous HTTP request handler that mocks responses for that service.
    • grpcMocks

      public final Map<String,Map<Class<? extends akka.grpc.javadsl.AkkaGrpcClient>,akka.grpc.javadsl.AkkaGrpcClient>> grpcMocks
      Map from service name to a map of gRPC service client class -> mock instance, used to mock gRPC service calls for the given service name.
    • objectStorageBuckets

      public final List<ObjectStorageBucketConfig> objectStorageBuckets
  • Method Details

    • withServiceName

      public TestKit.Settings withServiceName(String serviceName)
      Set the name of this service. This will be used by the service when making calls on other services run by the testkit to authenticate itself, allowing those services to apply ACLs based on that name. If not defined, the value from configuration key akka.javasdk.dev-mode.service-name will be used in the test.
      Parameters:
      serviceName - The name of this service.
      Returns:
      The updated settings.
    • withAclDisabled

      public TestKit.Settings withAclDisabled()
      Disable ACL checking in this service.
      Returns:
      The updated settings.
    • withAclEnabled

      public TestKit.Settings withAclEnabled()
      Enable ACL checking in this service (this is the default).
      Returns:
      The updated settings.
    • withKeyValueEntityIncomingMessages

      public TestKit.Settings withKeyValueEntityIncomingMessages(Class<? extends akka.javasdk.keyvalueentity.KeyValueEntity<?>> keyValueEntityClass)
      Mock the incoming messages flow from a KeyValueEntity.
    • withEventSourcedEntityIncomingMessages

      public TestKit.Settings withEventSourcedEntityIncomingMessages(Class<? extends akka.javasdk.eventsourcedentity.EventSourcedEntity<?,?>> eventSourcedEntityClass)
      Mock the incoming events flow from an EventSourcedEntity.
    • withWorkflowIncomingMessages

      public TestKit.Settings withWorkflowIncomingMessages(Class<? extends akka.javasdk.workflow.Workflow<?>> workflowClass)
      Mock the incoming state updates flow from a Workflow.
    • withStreamIncomingMessages

      public TestKit.Settings withStreamIncomingMessages(String service, String streamId)
      Mock the incoming messages flow from a Stream (eventing.in.direct in case of protobuf SDKs).
    • withTopicIncomingMessages

      public TestKit.Settings withTopicIncomingMessages(String topic)
      Mock the incoming events flow from a Topic.
    • withTopicOutgoingMessages

      public TestKit.Settings withTopicOutgoingMessages(String topic)
      Mock the outgoing events flow for a Topic.
    • withStreamOutgoingMessages

      public TestKit.Settings withStreamOutgoingMessages(String service, String streamId)
      Capture the outgoing messages produced by a @Produce.ServiceStream for test assertions.
    • withEventingSupport

      public TestKit.Settings withEventingSupport(TestKit.Settings.EventingSupport eventingSupport)
    • withAdditionalConfig

      public TestKit.Settings withAdditionalConfig(com.typesafe.config.Config additionalConfig)
      Specify additional config that will override the application-test.conf or application.conf configuration in a particular test.
    • withAdditionalConfig

      public TestKit.Settings withAdditionalConfig(String additionalConfig)
      Specify additional config that will override the application-test.conf or application.conf configuration in a particular test.
    • withDependencyProvider

      public TestKit.Settings withDependencyProvider(akka.javasdk.DependencyProvider dependencyProvider)
      Set a dependency provider that will be used for looking up arbitrary dependencies, useful to provide mocks for production dependencies in tests rather than calling the real thing.
    • withDisabledComponents

      public TestKit.Settings withDisabledComponents(Set<Class<?>> disabledComponents)
      Disable components from running, useful for testing components in isolation. This set of disabled components will be added to ServiceSetup.disabledComponents() if configured.
    • withOverriddenDisabledComponents

      public TestKit.Settings withOverriddenDisabledComponents(Set<Class<?>> disabledComponents)
      Disable components from running, useful for testing components in isolation. This set of disabled components will override the ServiceSetup.disabledComponents() if configured.
    • withAllComponentsEnabled

      public TestKit.Settings withAllComponentsEnabled()
      Enable all components to run, overriding any disabled components from ServiceSetup.disabledComponents(). This is useful for integration tests that need to test all components even if some are disabled in the Bootstrap configuration.
      Returns:
      The updated settings with all components enabled.
    • withModelProvider

      public TestKit.Settings withModelProvider(Class<?> agentClass, akka.javasdk.agent.ModelProvider modelProvider)
      Override the model provider for an Agent or
      invalid reference
      AutonomousAgent
      component. The class must be annotated with @Component(id = "...") or @ComponentId.
    • withMockedHttpService

      public TestKit.Settings withMockedHttpService(String mockServiceName, Function<akka.http.javadsl.model.HttpRequest,akka.http.javadsl.model.HttpResponse> handler)
      Mock an HTTP service for calls made through HttpClientProvider.httpClientFor(String) with the given service name. The handler runs synchronously on the SDK dispatcher (virtual threads), so blocking in the handler is safe. Calls for service names that are not mocked continue to go through normal resolution.

      Handler invocations can overlap when the service under test issues concurrent requests, so any state shared between the handler and the test class (captured fields, counters, queues) must be thread-safe.

      Parameters:
      mockServiceName - The service name (or full URL) that the service under test will pass to HttpClientProvider.httpClientFor(String).
      handler - A function that maps an incoming HttpRequest to the HttpResponse the mock should return.
      Returns:
      The updated settings.
    • withObjectStorageBucket

      public TestKit.Settings withObjectStorageBucket(ObjectStorageBucketConfig bucket)
      Add a named object-storage bucket for use in dev mode / integration tests. When any bucket is configured, only the named buckets are accessible (same as production).
      Parameters:
      bucket - the bucket configuration
      Returns:
      The updated settings.
    • withMockedGrpcService

      public <T extends akka.grpc.javadsl.AkkaGrpcClient> TestKit.Settings withMockedGrpcService(String mockServiceName, Class<T> serviceClass, T mockInstance)
      Mock a gRPC service for calls made through GrpcClientProvider.grpcClientFor(Class, String) with the given service name and generated service client interface. The mock is a user-provided instance of the generated Akka gRPC client interface. Calls for service-class/name combinations that are not mocked continue to go through normal resolution.

      The mock instance is shared across calls and method invocations can overlap when the service under test issues concurrent requests, so any state shared between the mock and the test class (captured fields, counters, queues) must be thread-safe.

      Parameters:
      mockServiceName - The service name that the service under test will pass to GrpcClientProvider.grpcClientFor(Class, String).
      serviceClass - The Akka gRPC generated client interface.
      mockInstance - A user-provided implementation of the generated client interface.
      Returns:
      The updated settings.
    • toString

      public String toString()
      Overrides:
      toString in class Object