Package kong.unirest.core
Class MockClient
- java.lang.Object
-
- kong.unirest.core.MockClient
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.function.Supplier<Config>
config
private Invocation
defaultResponse
private SocketSet
remoteSocket
private java.util.List<Routes>
routes
-
Constructor Summary
Constructors Constructor Description MockClient(java.util.function.Supplier<Config> config)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Assert
assertThat(HttpMethod method, java.lang.String path)
Assert a specific method and path were invokedstatic void
clear()
Clears any MockClient from the primary instancestatic void
clear(UnirestInstance unirest)
Clears any MockClient from the instanceprivate Routes
createNewPath(HttpRequest request)
ExpectedResponse
defaultResponse()
return this status for any request that doesn't match a expectationExpectation
expect(HttpMethod method)
Expect ANY call to a path with this methodExpectation
expect(HttpMethod method, java.lang.String path)
Start an expectation chain.private java.util.Optional<Routes>
findByPath(HttpMethod get, Path path)
private Routes
findExpecation(HttpRequest request)
java.lang.Object
getClient()
static MockClient
register()
Creates a new MockClient and registers it on the primary static UnirestInstancestatic MockClient
register(UnirestInstance unirest)
Creates a new MockClient and registers it on the Unirest instance<T> HttpResponse<T>
request(HttpRequest request, java.util.function.Function<RawResponse,HttpResponse<T>> transformer, java.lang.Class<?> resultType)
Make a request<T> java.util.concurrent.CompletableFuture<HttpResponse<T>>
request(HttpRequest request, java.util.function.Function<RawResponse,HttpResponse<T>> transformer, java.util.concurrent.CompletableFuture<HttpResponse<T>> callback, java.lang.Class<?> resultTypes)
Make a Async requestvoid
reset()
Reset all expectationsSocketSet<MockWebSocket,MockListener>
serversSocket()
void
verifyAll()
Verify that all Expectations were invokedWebSocketResponse
websocket(WebSocketRequest request, java.net.http.WebSocket.Listener listener)
Create a websocket connection
-
-
-
Field Detail
-
config
private final java.util.function.Supplier<Config> config
-
routes
private java.util.List<Routes> routes
-
remoteSocket
private SocketSet remoteSocket
-
defaultResponse
private Invocation defaultResponse
-
-
Constructor Detail
-
MockClient
public MockClient(java.util.function.Supplier<Config> config)
-
-
Method Detail
-
register
public static MockClient register()
Creates a new MockClient and registers it on the primary static UnirestInstance- Returns:
- the Mock Client
-
register
public static MockClient register(UnirestInstance unirest)
Creates a new MockClient and registers it on the Unirest instance- Parameters:
unirest
- an instance of Unirest- Returns:
- the Mock Client
-
clear
public static void clear()
Clears any MockClient from the primary instance
-
clear
public static void clear(UnirestInstance unirest)
Clears any MockClient from the instance- Parameters:
unirest
- the instance to clear the mocks from
-
request
public <T> HttpResponse<T> request(HttpRequest request, java.util.function.Function<RawResponse,HttpResponse<T>> transformer, java.lang.Class<?> resultType)
Description copied from interface:Client
Make a request- Specified by:
request
in interfaceClient
- Type Parameters:
T
- The type of the body- Parameters:
request
- the prepared request objecttransformer
- the function to transform the responseresultType
- the final body result type. This is a hint to downstream systems to make up for type erasure.- Returns:
- a HttpResponse with a transformed body
-
findExpecation
private Routes findExpecation(HttpRequest request)
-
createNewPath
private Routes createNewPath(HttpRequest request)
-
request
public <T> java.util.concurrent.CompletableFuture<HttpResponse<T>> request(HttpRequest request, java.util.function.Function<RawResponse,HttpResponse<T>> transformer, java.util.concurrent.CompletableFuture<HttpResponse<T>> callback, java.lang.Class<?> resultTypes)
Description copied from interface:Client
Make a Async request- Specified by:
request
in interfaceClient
- Type Parameters:
T
- The type of the body- Parameters:
request
- the prepared request objecttransformer
- the function to transform the responsecallback
- the CompletableFuture that will handle the eventual responseresultTypes
- the final body result type. This is a hint to downstream systems to make up for type erasure.- Returns:
- a CompletableFuture of a response
-
websocket
public WebSocketResponse websocket(WebSocketRequest request, java.net.http.WebSocket.Listener listener)
Description copied from interface:Client
Create a websocket connection
-
serversSocket
public SocketSet<MockWebSocket,MockListener> serversSocket()
-
getClient
public java.lang.Object getClient()
-
expect
public Expectation expect(HttpMethod method, java.lang.String path)
Start an expectation chain.- Parameters:
method
- the Http methodpath
- the base path- Returns:
- an Expectation which can have additional criteria added to it.
-
expect
public Expectation expect(HttpMethod method)
Expect ANY call to a path with this method- Parameters:
method
- the Http Method- Returns:
- this expectation builder
-
assertThat
public Assert assertThat(HttpMethod method, java.lang.String path)
Assert a specific method and path were invoked- Parameters:
method
- the Http methodpath
- the base path- Returns:
- an Assert object which can have additional criteria chained to it.
-
findByPath
private java.util.Optional<Routes> findByPath(HttpMethod get, Path path)
-
verifyAll
public void verifyAll()
Verify that all Expectations were invoked
-
reset
public void reset()
Reset all expectations
-
defaultResponse
public ExpectedResponse defaultResponse()
return this status for any request that doesn't match a expectation
-
-