public class MockServerClient extends AbstractClient<MockServerClient>
contextPath, expectationSerializer, host, httpRequestSerializer, logger, nettyHttpClient, port, portBindingSerializer, verificationSequenceSerializer, verificationSerializer
Constructor and Description |
---|
MockServerClient(String host,
int port)
Start the client communicating to a MockServer at the specified host and port
for example:
|
MockServerClient(String host,
int port,
String contextPath)
Start the client communicating to a MockServer at the specified host and port
and contextPath for example:
|
Modifier and Type | Method and Description |
---|---|
Expectation[] |
retrieveActiveExpectations(HttpRequest httpRequest)
Retrieve the active expectations match the httpRequest parameter, use null for the parameter to retrieve all expectations
|
String |
retrieveActiveExpectations(HttpRequest httpRequest,
Format format)
Retrieve the active expectations match the httpRequest parameter, use null for the parameter to retrieve all expectations
|
ForwardChainExpectation |
when(HttpRequest httpRequest)
Specify an unlimited expectation that will respond regardless of the number of matching http
for example:
|
ForwardChainExpectation |
when(HttpRequest httpRequest,
Times times)
Specify an limited expectation that will respond a specified number of times when the http is matched
for example:
|
ForwardChainExpectation |
when(HttpRequest httpRequest,
Times times,
TimeToLive timeToLive)
Specify an limited expectation that will respond a specified number of times when the http is matched
for example:
|
bind, calculatePath, clear, clear, close, contextPath, formatErrorMessage, isRunning, isRunning, remoteAddress, reset, retrieveLogMessages, retrieveLogMessagesArray, retrieveRecordedExpectations, retrieveRecordedExpectations, retrieveRecordedRequests, retrieveRecordedRequests, sendRequest, stop, stop, verify, verify, verifyZeroInteractions
public MockServerClient(String host, int port)
MockServerClient mockServerClient = new MockServerClient("localhost", 1080);
host
- the host for the MockServer to communicate withport
- the port for the MockServer to communicate withpublic MockServerClient(String host, int port, String contextPath)
MockServerClient mockServerClient = new MockServerClient("localhost", 1080, "/mockserver");
host
- the host for the MockServer to communicate withport
- the port for the MockServer to communicate withcontextPath
- the context path that the MockServer war is deployed topublic ForwardChainExpectation when(HttpRequest httpRequest)
mockServerClient .when(request().withPath("/some_path").withBody("some_request_body")) .respond(response().withBody("some_response_body").withHeader("responseName", "responseValue"))
httpRequest
- the http request that must be matched for this expectation to respondpublic ForwardChainExpectation when(HttpRequest httpRequest, Times times)
mockServerClient .when(request().withPath("/some_path").withBody("some_request_body"), Times.exactly(5)) .respond(response().withBody("some_response_body").withHeader("responseName", "responseValue"))
httpRequest
- the http request that must be matched for this expectation to respondtimes
- the number of times to respond when this http is matchedpublic ForwardChainExpectation when(HttpRequest httpRequest, Times times, TimeToLive timeToLive)
mockServerClient .when(request().withPath("/some_path").withBody("some_request_body"), Times.exactly(5), TimeToLive.exactly(TimeUnit.SECONDS, 120)) .respond(response().withBody("some_response_body").withHeader("responseName", "responseValue"))
httpRequest
- the http request that must be matched for this expectation to respondtimes
- the number of times to respond when this http is matchedtimeToLive
- the length of time from when the server receives the expectation that the expectation should be activepublic Expectation[] retrieveActiveExpectations(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 retrieveActiveExpectations(HttpRequest httpRequest, Format format)
httpRequest
- the http request that is matched against when deciding whether to return each expectation, use null for the parameter to retrieve for all requestsformat
- the format to retrieve the expectations, either JAVA or JSONCopyright © 2018. All rights reserved.