Package akka.javasdk.testkit
Class TestKit.Settings
Object
akka.javasdk.testkit.TestKit.Settings
- Enclosing class:
TestKit
Settings for testkit.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal booleanWhether ACL checking is enabled.final com.typesafe.config.Configstatic TestKit.SettingsDefault settings for testkit.final Optional<akka.javasdk.DependencyProvider> final Map<String, Map<Class<? extends akka.grpc.javadsl.AkkaGrpcClient>, akka.grpc.javadsl.AkkaGrpcClient>> 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.final Map<String, Function<akka.http.javadsl.model.HttpRequest, akka.http.javadsl.model.HttpResponse>> Map from service name to a synchronous HTTP request handler that mocks responses for that service.final TestKit.MockedEventingfinal List<ObjectStorageBucketConfig> final booleanWhen true, the testkit disabled components override any disabled components from ServiceSetup, rather than being combined with them.final StringThe name of this service when deployed. -
Method Summary
Modifier and TypeMethodDescriptiontoString()Disable ACL checking in this service.Enable ACL checking in this service (this is the default).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(String additionalConfig) Specify additional config that will override the application-test.conf or application.conf configuration in a particular test.Enable all components to run, overriding any disabled components fromServiceSetup.disabledComponents().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(Set<Class<?>> disabledComponents) Disable components from running, useful for testing components in isolation.withEventingSupport(TestKit.Settings.EventingSupport eventingSupport) withEventSourcedEntityIncomingMessages(Class<? extends akka.javasdk.eventsourcedentity.EventSourcedEntity<?, ?>> eventSourcedEntityClass) Mock the incoming events flow from an EventSourcedEntity.withKeyValueEntityIncomingMessages(Class<? extends akka.javasdk.keyvalueentity.KeyValueEntity<?>> keyValueEntityClass) Mock the incoming messages flow from a KeyValueEntity.<T extends akka.grpc.javadsl.AkkaGrpcClient>
TestKit.SettingswithMockedGrpcService(String mockServiceName, Class<T> serviceClass, T mockInstance) Mock a gRPC service for calls made throughGrpcClientProvider.grpcClientFor(Class, String)with the given service name and generated service client interface.withMockedHttpService(String mockServiceName, Function<akka.http.javadsl.model.HttpRequest, akka.http.javadsl.model.HttpResponse> handler) Mock an HTTP service for calls made throughHttpClientProvider.httpClientFor(String)with the given service name.withModelProvider(Class<?> agentClass, akka.javasdk.agent.ModelProvider modelProvider) Override the model provider for anAgentorcomponent.invalid reference
AutonomousAgentAdd a named object-storage bucket for use in dev mode / integration tests.withOverriddenDisabledComponents(Set<Class<?>> disabledComponents) Disable components from running, useful for testing components in isolation.withServiceName(String serviceName) Set the name of this service.withStreamIncomingMessages(String service, String streamId) Mock the incoming messages flow from a Stream (eventing.in.direct in case of protobuf SDKs).withStreamOutgoingMessages(String service, String streamId) Capture the outgoing messages produced by a@Produce.ServiceStreamfor test assertions.withTopicIncomingMessages(String topic) Mock the incoming events flow from a Topic.withTopicOutgoingMessages(String topic) Mock the outgoing events flow for a Topic.withWorkflowIncomingMessages(Class<? extends akka.javasdk.workflow.Workflow<?>> workflowClass) Mock the incoming state updates flow from a Workflow.
-
Field Details
-
DEFAULT
Default settings for testkit. -
serviceName
The name of this service when deployed. -
aclEnabled
public final boolean aclEnabledWhether ACL checking is enabled. -
eventingSupport
-
mockedEventing
-
additionalConfig
public final com.typesafe.config.Config additionalConfig -
dependencyProvider
-
disabledComponents
-
overrideDisabledComponents
public final boolean overrideDisabledComponentsWhen true, the testkit disabled components override any disabled components from ServiceSetup, rather than being combined with them. -
modelProvidersByAgentId
-
httpMocks
public final Map<String,Function<akka.http.javadsl.model.HttpRequest, httpMocksakka.http.javadsl.model.HttpResponse>> 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>, grpcMocksakka.grpc.javadsl.AkkaGrpcClient>> 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
-
-
Method Details
-
withServiceName
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 keyakka.javasdk.dev-mode.service-namewill be used in the test.- Parameters:
serviceName- The name of this service.- Returns:
- The updated settings.
-
withAclDisabled
Disable ACL checking in this service.- Returns:
- The updated 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
Mock the incoming messages flow from a Stream (eventing.in.direct in case of protobuf SDKs). -
withTopicIncomingMessages
Mock the incoming events flow from a Topic. -
withTopicOutgoingMessages
Mock the outgoing events flow for a Topic. -
withStreamOutgoingMessages
Capture the outgoing messages produced by a@Produce.ServiceStreamfor test assertions. -
withEventingSupport
-
withAdditionalConfig
Specify additional config that will override the application-test.conf or application.conf configuration in a particular test. -
withAdditionalConfig
Specify additional config that will override the application-test.conf or application.conf configuration in a particular test. -
withDependencyProvider
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
Disable components from running, useful for testing components in isolation. This set of disabled components will be added toServiceSetup.disabledComponents()if configured. -
withOverriddenDisabledComponents
Disable components from running, useful for testing components in isolation. This set of disabled components will override theServiceSetup.disabledComponents()if configured. -
withAllComponentsEnabled
Enable all components to run, overriding any disabled components fromServiceSetup.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 anAgentorcomponent. The class must be annotated withinvalid reference
AutonomousAgent@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 throughHttpClientProvider.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 toHttpClientProvider.httpClientFor(String).handler- A function that maps an incomingHttpRequestto theHttpResponsethe mock should return.- Returns:
- The updated settings.
-
withObjectStorageBucket
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 throughGrpcClientProvider.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 toGrpcClientProvider.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
-