Mokksy Server
An embedded mock HTTP server for testing. Registers stubs for any HTTP method and verifies request expectations after the test.
Call start() (on JVM) or startSuspend to begin processing requests after construction.
Example:
val mokksy = Mokksy().apply { start() }
mokksy.get {
path("/ping")
} respondsWith {
body = """{"response":"Pong"}"""
}Author
Konstantin Pavlov
Parameters
The host to bind to. Defaults to 127.0.0.1.
The port to bind to. Defaults to 0 (randomly assigned).
ServerConfiguration options.
Additional Ktor Application configuration applied after the default routing setup.
Constructors
Creates a MokksyServer instance. Call start() (on JVM) or startSuspend to begin processing requests.
Creates a MokksyServer instance using a verbose flag instead of a full ServerConfiguration. Call start() (on JVM) or startSuspend to begin processing requests.
Functions
Suspends until the server has fully started and the port is bound.
Defines a stub for an HTTP DELETE request with a string request body.
Registers a stub for an HTTP DELETE request with the specified configuration and request type.
Defines a stub for an HTTP DELETE request with the specified request type and configuration block.
Returns all HTTP requests that arrived at the server but were not matched by any stub.
Returns all HTTP requests that arrived at the server but were not matched by any stub.
Returns all stub specifications that have not been matched by any incoming request.
Defines a stub for an HTTP GET request with a string body using the provided configuration block.
Defines a stub for an HTTP GET request with the specified configuration and request specification builder.
Registers a stub for an HTTP GET request with the specified configuration and request type.
Defines a stub for an HTTP GET request with the specified request type and configuration block.
Defines a stub for an HTTP HEAD request with a string request body.
Defines a stub for a HEAD HTTP request with the specified configuration and request type.
Defines a stub for an HTTP HEAD request with the specified request type and configuration block.
Creates a RequestSpecification for the given HTTP method and request type, and returns a BuildingStep for further stub configuration.
Defines a stubbed HTTP RequestSpecification for the given method and request type, optionally naming the stub.
Defines an HTTP OPTIONS request stub with a string request body using the provided configuration block.
Defines a stub for an HTTP OPTIONS request with the specified configuration and request type.
Defines a stub for an HTTP OPTIONS request with the specified request type and configuration block.
Defines a PATCH request stub with a string request body using the provided configuration block.
Registers a stub for an HTTP PATCH request with the specified configuration and request type.
Defines a stub for an HTTP PATCH request with the specified request type and configuration block.
Defines a stub for an HTTP POST request with a string request body.
Defines a POST request stub with the specified configuration and request type.
Defines a stub for an HTTP POST request with the specified request type and configuration block.
Defines a stub for an HTTP PUT request with a string request body.
Defines a stub for an HTTP PUT request with the specified configuration and request type.
Defines a stub for an HTTP PUT request with the specified request type and configuration block.
Resets the match count of all registered stubs to zero and clears the request journal.
Stops the Mokksy server, blocking until shutdown is complete.
Stops the Mokksy server on the given dispatcher, blocking until shutdown is complete.
Stops the embedded server and releases its resources with the specified grace period and timeout.
Initiates the server to begin processing requests asynchronously.
Verifies that every request received by the server was matched by a stub.
Verifies that all registered stubs have been matched at least once.