public class ProxyClient extends AbstractClient implements Closeable
contextPath, expectationSerializer, host, httpRequestSerializer, logger, nettyHttpClient, port, verificationSequenceSerializer, verificationSerializer
Constructor and Description |
---|
ProxyClient(String host,
int port)
Start the client communicating to a the proxy at the specified host and port
for example:
ProxyClient mockServerClient = new ProxyClient("localhost", 1080);
|
ProxyClient(String host,
int port,
String contextPath)
Start the client communicating to the proxy at the specified host and port
and contextPath for example:
ProxyClient mockServerClient = new ProxyClient("localhost", 1080, "/proxy");
|
Modifier and Type | Method and Description |
---|---|
ProxyClient |
clear(HttpRequest httpRequest)
Clear all recorded requests that match the httpRequest parameter
|
void |
close() |
ProxyClient |
dumpToLogAsJava()
Output Java code for creating all requests / responses as Expectations to the log.
|
ProxyClient |
dumpToLogAsJava(HttpRequest httpRequest)
Output Java code for creating matching requests and their responses as Expectations to the log.
|
ProxyClient |
dumpToLogAsJSON()
Pretty-print the json for all requests / responses as Expectations to the log.
|
ProxyClient |
dumpToLogAsJSON(HttpRequest httpRequest)
Pretty-print the json for matching requests and their responses as Expectations to the log.
|
boolean |
isRunning()
Returns whether the proxy is running
|
boolean |
isRunning(int attempts,
long timeout,
TimeUnit timeUnit)
Returns whether the proxy is running, by polling the MockServer a configurable amount of times
|
ProxyClient |
reset()
Reset the proxy by clearing recorded requests
|
Expectation[] |
retrieveAsExpectations(HttpRequest httpRequest)
Retrieve the recorded requests that match the httpRequest parameter as expectations, use null for the parameter to retrieve all requests
|
String |
retrieveAsJSON(HttpRequest httpRequest)
Retrieve the recorded requests that match the httpRequest parameter as a JSON array, use null for the parameter to retrieve all requests
|
ProxyClient |
stop()
Stop the proxy gracefully (only support for Netty and Vert.X versions, not supported for WAR version)
|
ProxyClient |
stop(boolean ignoreFailure) |
ProxyClient |
verify(HttpRequest... httpRequests)
Verify a list of requests have been sent in the order specified for example:
mockServerClient
.verify(
request()
.withPath("/first_request")
.withBody("some_request_body"),
request()
.withPath("/second_request")
.withBody("some_request_body")
);
|
ProxyClient |
verify(HttpRequest httpRequest,
VerificationTimes times)
Verify a request has been sent for example:
mockServerClient
.verify(
request()
.withPath("/some_path")
.withBody("some_request_body"),
VerificationTimes.exactly(3)
);
VerificationTimes supports multiple static factory methods:
once() - verify the request was only received once
exactly(n) - verify the request was only received exactly n times
atLeast(n) - verify the request was only received at least n times
|
calculatePath, contextPath, formatErrorMessage, remoteAddress, sendRequest
public ProxyClient(String host, int port)
host
- the host for the MockServer to communicate withport
- the port for the MockServer to communicate withpublic ProxyClient(String host, int port, String contextPath)
host
- the host for the proxy to communicate withport
- the port for the proxy to communicate withcontextPath
- the context path that the proxy war is deployed topublic ProxyClient dumpToLogAsJSON()
public ProxyClient dumpToLogAsJSON(HttpRequest httpRequest)
httpRequest
- the http request that is matched against when deciding what to log if null all requests are loggedpublic ProxyClient dumpToLogAsJava()
public ProxyClient dumpToLogAsJava(HttpRequest httpRequest)
httpRequest
- the http request that is matched against when deciding what to log if null all requests are loggedpublic boolean isRunning()
public boolean isRunning(int attempts, long timeout, TimeUnit timeUnit)
public ProxyClient stop()
public ProxyClient stop(boolean ignoreFailure)
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public ProxyClient reset()
public ProxyClient clear(HttpRequest httpRequest)
httpRequest
- the http request that is matched against when deciding whether to clear recorded requestspublic ProxyClient verify(HttpRequest... httpRequests) throws AssertionError
httpRequests
- the http requests that must be matched for this verification to passAssertionError
- if the request has not been foundpublic ProxyClient verify(HttpRequest httpRequest, VerificationTimes times) throws AssertionError
httpRequest
- the http request that must be matched for this verification to passtimes
- the number of times this request must be matchedAssertionError
- if the request has not been foundpublic Expectation[] retrieveAsExpectations(HttpRequest httpRequest)
httpRequest
- the http request that is matched against when deciding whether to return each expectation, use null for the parameter to retrieve for all requestspublic String retrieveAsJSON(HttpRequest httpRequest)
httpRequest
- the http request that is matched against when deciding whether to return each expectation, use null for the parameter to retrieve for all requestsCopyright © 2018. All rights reserved.