Package com.spotify.apollo.test
Class StubClient
- java.lang.Object
-
- com.spotify.apollo.test.StubClient
-
- All Implemented Interfaces:
com.spotify.apollo.Client,Closeable,AutoCloseable
public class StubClient extends Object implements com.spotify.apollo.Client, Closeable
A stub (http://www.martinfowler.com/articles/mocksArentStubs.html) client that allows you to preconfigure responses to certain messages, as well as verify whether expected messages are sent. When evaluating how to respond, request/response mapping rules are evaluated in the order they were added. Use theclear()method to clear previous request/response mappings.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStubClient.NoMatchingResponseFoundExceptionstatic classStubClient.RequestResponsePairclassStubClient.StubbedResponseBuilderImmutable response builder.
-
Constructor Summary
Constructors Constructor Description StubClient()StubClient(ScheduledExecutorService executor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears the previously setup request to response mappings, but not the history of sent messages.voidclearRequests()Clears the requests and responses tracked by this client.voidclose()List<StubClient.RequestResponsePair>requestsAndResponses()Returns all the requests sent to this stub client, together with their associated responses.StubClient.StubbedResponseBuilderrespond(com.spotify.apollo.Response<okio.ByteString> response)Configure a constant (i.e., all matching requests will always result in the same response) response for some request.StubClient.StubbedResponseBuilderrespond(ResponseSource responseSource)Configure a response source for matching requests.CompletionStage<com.spotify.apollo.Response<okio.ByteString>>send(com.spotify.apollo.Request request)List<com.spotify.apollo.Request>sentRequests()Returns all the requests sent to this stub client.
-
-
-
Constructor Detail
-
StubClient
public StubClient()
-
StubClient
public StubClient(ScheduledExecutorService executor)
-
-
Method Detail
-
send
public CompletionStage<com.spotify.apollo.Response<okio.ByteString>> send(com.spotify.apollo.Request request)
- Specified by:
sendin interfacecom.spotify.apollo.Client
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
sentRequests
public List<com.spotify.apollo.Request> sentRequests()
Returns all the requests sent to this stub client.
-
clearRequests
public void clearRequests()
Clears the requests and responses tracked by this client.
-
requestsAndResponses
public List<StubClient.RequestResponsePair> requestsAndResponses()
Returns all the requests sent to this stub client, together with their associated responses.
-
clear
public void clear()
Clears the previously setup request to response mappings, but not the history of sent messages.
-
respond
public StubClient.StubbedResponseBuilder respond(com.spotify.apollo.Response<okio.ByteString> response)
Configure a constant (i.e., all matching requests will always result in the same response) response for some request. The returned builder allows configuration of payload (default no payload) and delay before the response is sent (default 0).
-
respond
public StubClient.StubbedResponseBuilder respond(ResponseSource responseSource)
Configure a response source for matching requests. Each time a request is sent that matches the to-be-specified criteria, the supplied ResponseSource will be invoked and its result returned as a response.
-
-