WebserviceMock

class WebserviceMock

Handles requests for a web service mock instance based on a given config.

To be able to mock online services, a WebserviceMock instance can be used. A WebserviceMock instance is created by the WebserviceMockServer for each registered WebserviceMockConfig.

The WebserviceMock assumes that requests and responses of the online web service are considered a black box from the test point of view. In other words: the SUT may perform any request and receive any response content to and from this web service mock. For the test it only matters that:

  • The SUT is tested in isolation from the online service: online service availability should not affect the test result.

  • The SUT is tested in a deterministic way: the response data is always the same.

  • Optionally the response can be changed.

For the above use case, it is required that when the SUT changes (for instance, new functionality is added), the replay data of the WebserviceMock can be re-created without a lot of effort. To allow this, the WebserviceMock can forward all requests to a WebserviceMockConfig.forwardBaseUri server and capture all responses into a captures.db.

Replay responses are obtained from the replay.db either when WebserviceMockConfig.requestResponseMode is set to RequestResponseMode.REPLAY_ONLY or set to RequestResponseMode.REPLAY_WHEN_AVAILABLE. Requests are forwarded to the WebserviceMockConfig.forwardBaseUri server when WebserviceMockConfig.requestResponseMode is set to RequestResponseMode.FORWARD or when set to RequestResponseMode.REPLAY_WHEN_AVAILABLE and the request was not found in the replay.db.

Types

Link copied to clipboard
interface WebserviceMockEventListener : TraceEventListener

Properties

Link copied to clipboard
val config: WebserviceMockConfig
Link copied to clipboard
var started: Boolean = false