WebSocketSyncBackendStub

sttp.client4.testing.WebSocketSyncBackendStub
See theWebSocketSyncBackendStub companion object
class WebSocketSyncBackendStub(matchers: PartialFunction[GenericRequest[_, _], Response[_]], fallback: Option[WebSocketSyncBackend]) extends AbstractBackendStub[Identity, WebSockets], WebSocketSyncBackend

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 SyncBackend
trait Backend[Identity]
class AbstractBackendStub[Identity, WebSockets]
trait GenericBackend[Identity, WebSockets]
class Object
trait Matchable
class Any
Show all
Known subtypes

Members list

Type members

Inherited classlikes

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

Attributes

Inherited from:
AbstractBackendStub
Supertypes
class Object
trait Matchable
class Any

Value members

Inherited methods

override def close(): Identity[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 monad: MonadError[Identity]

A monad instance for the F effect type. Allows writing wrapper backends, which map/`flatMap`` over the return value of send.

A monad instance for the F effect type. Allows writing wrapper backends, which map/`flatMap`` over the return value of send.

Attributes

Definition Classes
Inherited from:
SyncBackend
override def send[T](request: GenericRequest[T, WebSockets & Effect[Identity]]): Identity[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
def whenRequestMatches(p: (GenericRequest[_, _]) => Boolean): WhenRequest

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