Package akka.javasdk.testkit
Interface MockedHttpServices
@DoNotInherit
public interface MockedHttpServices
Registry of mocked HTTP services for a running
TestKit. Lets individual tests install or
replace mock handlers without re-creating the testkit.
Handlers run synchronously on the SDK dispatcher (virtual threads); blocking in the handler is safe. 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.
Entries declared via TestKit.Settings.withMockedHttpService(String, Function) are used
to seed the registry at testkit startup and are restored by reset().
Not for user extension.
-
Method Summary
Modifier and TypeMethodDescriptionvoidmockResponse(String serviceName, Function<akka.http.javadsl.model.HttpRequest, akka.http.javadsl.model.HttpResponse> handler) Register or replace a mock handler for calls made throughhttpClientProvider.httpClientFor(serviceName).voidRemove the mock for the given service name, if any.voidreset()Reset the registry back to the mocks declared inTestKit.Settings.
-
Method Details
-
mockResponse
void mockResponse(String serviceName, Function<akka.http.javadsl.model.HttpRequest, akka.http.javadsl.model.HttpResponse> handler) Register or replace a mock handler for calls made throughhttpClientProvider.httpClientFor(serviceName). -
remove
Remove the mock for the given service name, if any. -
reset
void reset()Reset the registry back to the mocks declared inTestKit.Settings.
-