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 Type
    Method
    Description
    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 through httpClientProvider.httpClientFor(serviceName).
    void
    remove(String serviceName)
    Remove the mock for the given service name, if any.
    void
    Reset the registry back to the mocks declared in TestKit.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 through httpClientProvider.httpClientFor(serviceName).
    • remove

      void remove(String serviceName)
      Remove the mock for the given service name, if any.
    • reset

      void reset()
      Reset the registry back to the mocks declared in TestKit.Settings.