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().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 DELETE stub with a String request body.
Defines a DELETE stub with a String request body and a full StubConfiguration.
Defines a DELETE stub that matches a typed request body of type P using a full StubConfiguration.
Defines a DELETE stub that matches a typed request body of type P.
Reified shortcut for MokksyServer.delete with a StubConfiguration. Infers P from the call site.
Reified shortcut for MokksyServer.delete with an optional stub name. Infers P from the call site.
Returns all HTTP requests that were successfully matched by a stub. Only populated when ServerConfiguration.journalMode is JournalMode.FULL.
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 GET stub with a String request body.
Defines a GET stub with a String request body and a full StubConfiguration.
Defines a GET stub that matches a typed request body of type P using a full StubConfiguration.
Defines a GET stub that matches a typed request body of type P.
Reified shortcut for MokksyServer.get with a StubConfiguration. Infers P from the call site.
Reified shortcut for MokksyServer.get with an optional stub name. Infers P from the call site.
Dispatches an incoming request to the appropriate stub and writes the response.
Defines a HEAD stub with a String request body.
Defines a HEAD stub with a String request body and a full StubConfiguration.
Defines a HEAD stub that matches a typed request body of type P using a full StubConfiguration.
Defines a HEAD stub that matches a typed request body of type P.
Reified shortcut for MokksyServer.head with a StubConfiguration. Infers P from the call site.
Reified shortcut for MokksyServer.head with an optional stub name. Infers P from the call site.
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.
Reified shortcut for MokksyServer.method with a StubConfiguration. Infers P from the call site.
Reified shortcut for MokksyServer.method with an optional stub name. Infers P from the call site.
Defines an OPTIONS stub with a String request body.
Defines an OPTIONS stub with a String request body and a full StubConfiguration.
Defines an OPTIONS stub that matches a typed request body of type P using a full StubConfiguration.
Defines an OPTIONS stub that matches a typed request body of type P.
Reified shortcut for MokksyServer.options with a StubConfiguration. Infers P from the call site.
Reified shortcut for MokksyServer.options with an optional stub name. Infers P from the call site.
Defines a PATCH stub with a String request body.
Defines a PATCH stub with a String request body and a full StubConfiguration.
Defines a PATCH stub that matches a typed request body of type P using a full StubConfiguration.
Defines a PATCH stub that matches a typed request body of type P.
Reified shortcut for MokksyServer.patch with a StubConfiguration. Infers P from the call site.
Reified shortcut for MokksyServer.patch with an optional stub name. Infers P from the call site.
Defines a POST stub with a String request body.
Defines a POST stub with a String request body and a full StubConfiguration.
Defines a POST stub that matches a typed request body of type P using a full StubConfiguration.
Defines a POST stub that matches a typed request body of type P.
Reified shortcut for MokksyServer.post with a StubConfiguration. Infers P from the call site.
Reified shortcut for MokksyServer.post with an optional stub name. Infers P from the call site.
Defines a PUT stub with a String request body.
Defines a PUT stub with a String request body and a full StubConfiguration.
Defines a PUT stub that matches a typed request body of type P using a full StubConfiguration.
Defines a PUT stub that matches a typed request body of type P.
Reified shortcut for MokksyServer.put with a StubConfiguration. Infers P from the call site.
Reified shortcut for MokksyServer.put with an optional stub name. Infers P from the call site.
Resets the match state of all currently registered stubs to unmatched, and clears the request journal.
Resets the match state of all currently registered stubs to unmatched, 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.
Starts the Mokksy server and blocks until the port is bound and ready to accept requests.
Starts the Mokksy server on the given dispatcher, blocking until the port is bound.
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.