Package akka.javasdk.testkit
Class TestKit
Object
akka.javasdk.testkit.TestKit
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
Settings for testkit. -
Constructor Summary
ConstructorsConstructorDescriptionTestKit()
Create a new testkit for a service descriptor with the default settings.TestKit
(TestKit.Settings settings) Create a new testkit for a service descriptor with custom settings. -
Method Summary
Modifier and TypeMethodDescriptionstatic int
Get an available local port for testing.akka.actor.typed.ActorSystem
<?> Get anActorSystem
for creating Akka HTTP clients.com.typesafe.config.Config
akka.javasdk.client.ComponentClient
Get anComponentClient
for interacting "internally" with the components of a service.Optional
<akka.javasdk.DependencyProvider> getEventSourcedEntityIncomingMessages
(String componentId) Get incoming messages for EventSourcedEntity.getHost()
Get the host name/IP address where the service is available.akka.javasdk.http.HttpClientProvider
Get aHttpClientProvider
for looking up HTTP clients to interact with other services than the current.getKeyValueEntityIncomingMessages
(String componentId) Get incoming messages for KeyValueEntity.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 service is available.akka.javasdk.http.HttpClient
Get aHttpClient
for interacting with the service itself, the client will not be authenticated and will appear to the service as a request with the internet principal.getStreamIncomingMessages
(String service, String streamId) Get incoming messages for Consume.ServiceStream.akka.javasdk.timer.TimerScheduler
Get aTimerScheduler
for scheduling TimedAction.getTopicIncomingMessages
(String topic) Get incoming messages for Topic.getTopicOutgoingMessages
(String topic) Get mocked topic destination.start()
Start this testkit with default configuration.void
stop()
Stop the testkit and local runtime.
-
Constructor Details
-
TestKit
public TestKit()Create a new testkit for a service descriptor with the default settings. -
TestKit
Create a new testkit for a service descriptor with custom settings.- Parameters:
settings
- custom testkit settings
-
-
Method Details
-
start
Start this testkit with default configuration. The default configuration is loaded fromapplication-test.conf
if that exists, otherwise fromapplication.conf
.- Returns:
- this TestKit instance
-
getHost
Get the host name/IP address where the service is available. This is relevant in certain Continuous Integration environments. -
getPort
public int getPort()Get the local port where the service is available. -
getApplicationConfig
public com.typesafe.config.Config getApplicationConfig()- Returns:
- The config as the components of the service under test sees it, if injected.
-
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.typed.ActorSystem<?> getActorSystem()Get anActorSystem
for creating Akka HTTP clients.- Returns:
- test actor system
-
getComponentClient
public akka.javasdk.client.ComponentClient getComponentClient()Get anComponentClient
for interacting "internally" with the components of a service. -
getTimerScheduler
public akka.javasdk.timer.TimerScheduler getTimerScheduler()Get aTimerScheduler
for scheduling TimedAction. -
getHttpClientProvider
public akka.javasdk.http.HttpClientProvider getHttpClientProvider()Get aHttpClientProvider
for looking up HTTP clients to interact with other services than the current. Requests will appear as coming from this service from an ACL perspective. -
getSelfHttpClient
public akka.javasdk.http.HttpClient getSelfHttpClient()Get aHttpClient
for interacting with the service itself, the client will not be authenticated and will appear to the service as a request with the internet principal. -
getKeyValueEntityIncomingMessages
Get incoming messages for KeyValueEntity.- Parameters:
componentId
- As annotated with @ComponentId on the KeyValueEntity
-
getEventSourcedEntityIncomingMessages
Get incoming messages for EventSourcedEntity.- Parameters:
componentId
- As annotated with @ComponentId on the EventSourcedEntity
-
getStreamIncomingMessages
Get incoming messages for Consume.ServiceStream.- 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
-
stop
public void stop()Stop the testkit and local runtime. -
availableLocalPort
public static int availableLocalPort()Get an available local port for testing.- Returns:
- available local port
-
getMessageBuilder
ReturnsEventingTestKit.MessageBuilder
utility to createEventingTestKit.Message
s for the eventing testkit. -
getDependencyProvider
- Returns:
- The custom dependency provider used in this test, if one is defined, when overriding the dependency provided
through
TestKit.Settings.withDependencyProvider(DependencyProvider)
the overridden provider is returned.
-