WebSocketBackendStub

sttp.client4.testing.WebSocketBackendStub
See theWebSocketBackendStub companion object
class WebSocketBackendStub[F[_]](monad: MonadError[F], matchers: PartialFunction[GenericRequest[_, _], F[Response[_]]], fallback: Option[WebSocketBackend[F]]) extends AbstractBackendStub[F, WebSockets] with WebSocketBackend[F]

A stub backend to use in tests.

The stub can be configured to respond with a given response if the request matches a predicate (see the whenRequestMatches method).

Note however, that this is not type-safe with respect to the type of the response body - the stub doesn't have a way to check if the type of the body in the configured response is the same as the one specified by the request. Some conversions will be attempted (e.g. from a String to a custom mapped type, as specified in the request, see the documentation for more details).

For web socket requests, the stub can be configured to returned both custom sttp.ws.WebSocket implementations, as well as sttp.ws.testing.WebSocketStub instances.

Predicates can match requests basing on the URI or headers. A ClassCastException might occur if for a given request, a response is specified with the incorrect or inconvertible body type.

Attributes

Companion:
object
Graph
Supertypes
trait Backend[F]
class AbstractBackendStub[F, WebSockets]
trait GenericBackend[F, WebSockets]
class Object
trait Matchable
class Any

Members list

Concise view

Type members

Inherited classlikes

class WhenRequest(p: GenericRequest[_, _] => Boolean)

Attributes

Inherited from:
AbstractBackendStub
Graph
Supertypes
class Object
trait Matchable
class Any

Types

Value members

Inherited methods

override def close(): F[Unit]

Close the backend, releasing any resources (such as thread or connection pools) that have been allocated when opening or using the backend.

Close the backend, releasing any resources (such as thread or connection pools) that have been allocated when opening or using the backend.

Attributes

Definition Classes
Inherited from:
AbstractBackendStub
override def send[T](request: GenericRequest[T, WebSockets & Effect[F]]): F[Response[T]]

Send the given request. Should only be used when implementing new backends, or backend wrappers. Client code should instead use the send methods on the request type, e.g. Request.send.

Send the given request. Should only be used when implementing new backends, or backend wrappers. Client code should instead use the send methods on the request type, e.g. Request.send.

Attributes

Definition Classes
Inherited from:
AbstractBackendStub

Specify how the stub backend should respond to any request (catch-all).

Specify how the stub backend should respond to any request (catch-all).

Note that the stubs are immutable, and each new specification that is added yields a new stub instance.

Attributes

Inherited from:
AbstractBackendStub

Specify how the stub backend should respond to requests matching the given predicate.

Specify how the stub backend should respond to requests matching the given predicate.

Note that the stubs are immutable, and each new specification that is added yields a new stub instance.

Attributes

Inherited from:
AbstractBackendStub
def whenRequestMatchesPartial(partial: PartialFunction[GenericRequest[_, _], Response[_]]): Self

Specify how the stub backend should respond to requests using the given partial function.

Specify how the stub backend should respond to requests using the given partial function.

Note that the stubs are immutable, and each new specification that is added yields a new stub instance.

Attributes

Inherited from:
AbstractBackendStub