MokksyServer

open class MokksyServer(port: Int = 0, host: String = DEFAULT_HOST, configuration: ServerConfiguration, wait: Boolean = false, configurer: (<Error class: unknown class>) -> Unit = {})

Represents an embedded mock server capable of handling various HTTP requests and responses for testing purposes. Provides functionality to configure request specifications for different HTTP methods and manage request matching.

Parameters

port

The port number on which the server will run. Defaults to 0 (randomly assigned port).

configuration

Server configuration options

wait

Determines whether the server startup process should block the current thread. Defaults to false.

configurer

A lambda function for setting custom configurations for the server's application module.

Constructors

Link copied to clipboard
constructor(port: Int = 0, host: String = DEFAULT_HOST, verbose: Boolean = false, configurer: (<Error class: unknown class>) -> Unit = {})
constructor(port: Int = 0, host: String = DEFAULT_HOST, configuration: ServerConfiguration, wait: Boolean = false, configurer: (<Error class: unknown class>) -> Unit = {})

Initializes the server with the specified parameters and starts it.

Functions

Link copied to clipboard

Checks for any unmatched requests by retrieving all request specifications that have not been matched to incoming requests and verifies that the list of unmatched requests is empty.

Link copied to clipboard

Configures an HTTP DELETE request specification using the provided block and returns a BuildingStep for further customization. This method serves as a convenience shortcut.

fun <P : Any> delete(name: String? = null, requestType: KClass<P>, block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Configures an HTTP DELETE request specification using the provided block and returns a BuildingStep instance for further customization. This method uses the HTTP DELETE method to define the request specification within the provided lambda.

fun <P : Any> delete(configuration: StubConfiguration, requestType: KClass<P>, block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Executes an HTTP DELETE request with the specified configuration and request type.

Link copied to clipboard

Retrieves a list of all request specifications that have not been matched to any incoming requests. A request is considered unmatched if its match count is zero.

Link copied to clipboard

Configures HTTP GET request specification using the provided block and returns a BuildingStep for further customization. This method serves as a convenience shortcut.

fun <P : Any> get(name: String? = null, requestType: KClass<P>, block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>
fun <P : Any> get(configuration: StubConfiguration, requestType: KClass<P>, block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Configures an HTTP GET request specification using the provided block and returns a BuildingStep instance for further customization.

Link copied to clipboard

Configures an HTTP HEAD request specification using the provided block and returns a BuildingStep for further customization. This method serves as a convenience shortcut.

fun <P : Any> head(name: String? = null, requestType: KClass<P>, block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Configures an HTTP HEAD request specification using the provided block and returns a BuildingStep instance for further customization. This method uses the HTTP HEAD method to define the request specification within the provided lambda.

fun <P : Any> head(configuration: StubConfiguration, requestType: KClass<P>, block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Constructs a HEAD HTTP request with the provided configuration, request type, and specification block.

Link copied to clipboard
fun <P : Any> method(name: String? = null, httpMethod: <Error class: unknown class>, requestType: KClass<P>, block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Creates a building step for a stub configuration with the specified parameters.

fun <P : Any> method(configuration: StubConfiguration, httpMethod: <Error class: unknown class>, requestType: KClass<P>, block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Creates a RequestSpecification with the specified HTTP method and additional configuration defined by the given block, and returns a new BuildingStep instance for further customization.

Link copied to clipboard

Configures an HTTP HEAD request specification using the provided block and returns a BuildingStep for further customization. This method serves as a convenience shortcut.

fun <P : Any> options(name: String? = null, requestType: KClass<P>, block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Configures an HTTP OPTIONS request specification using the provided block and returns a BuildingStep instance for further customization. This method uses the HTTP OPTIONS method to define the request specification within the provided lambda.

fun <P : Any> options(configuration: StubConfiguration, requestType: KClass<P>, block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Configures and executes an HTTP OPTIONS request based on the given parameters.

Link copied to clipboard

Configures an HTTP PATCH request specification using the provided block and returns a BuildingStep for further customization. This method serves as a convenience shortcut.

fun <P : Any> patch(name: String? = null, requestType: KClass<P>, block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Configures an HTTP PATCH request specification using the provided block and returns a BuildingStep instance for further customization. This method uses the HTTP PATCH method to define the request specification within the provided lambda.

fun <P : Any> patch(configuration: StubConfiguration, requestType: KClass<P>, block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Builds and returns a BuildingStep for a PATCH HTTP request with the provided configuration, request type, and custom request specification block.

Link copied to clipboard
fun port(): Int

Retrieves the resolved port on which the server is running.

Link copied to clipboard

Configures an HTTP POST request specification using the provided block and returns a BuildingStep for further customization. This method serves as a convenience shortcut.

fun <P : Any> post(name: String? = null, requestType: KClass<P>, block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Configures an HTTP POST request specification using the provided block and returns a BuildingStep instance for further customization. This method uses the HTTP POST method to define the request specification within the provided lambda.

fun <P : Any> post(configuration: StubConfiguration, requestType: KClass<P>, block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Sends a POST request using the provided configuration, request type, and block to define the request specification.

Link copied to clipboard

Configures an HTTP PUT request specification using the provided block and returns a BuildingStep for further customization. This method serves as a convenience shortcut.

fun <P : Any> put(name: String? = null, requestType: KClass<P>, block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Configures an HTTP PUT request specification using the provided block and returns a BuildingStep instance for further customization. This method uses the HTTP PUT method to define the request specification within the provided lambda.

fun <P : Any> put(configuration: StubConfiguration, requestType: KClass<P>, block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Executes an HTTP PUT request with the provided configuration and request specifications.

Link copied to clipboard

Resets the match counts for all mappings in the server. Each mapping's match count is set to zero, effectively clearing any record of previous matches.

Link copied to clipboard
fun shutdown()

Shuts down the server by stopping its execution.