public class MockServerClient extends Object
| Constructor and Description |
|---|
MockServerClient(String host,
int port)
Start the client communicating to a MockServer at the specified host and port
for example:
MockServerClient mockServerClient = new MockServerClient("localhost", 8080);
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear(HttpRequest httpRequest)
Clear all expectations that match the request
|
void |
dumpToLog()
Pretty-print the json for all expectations already setup to the log.
|
void |
reset()
Reset MockServer by clearing all expectations
|
protected void |
sendExpectation(Expectation expectation) |
ForwardChainExpectation |
when(HttpRequest httpRequest)
Specify an unlimited expectation that will respond regardless of the number of matching request
for example:
mockServerClient
.when(
new HttpRequest()
.withPath("/some_path")
.withBody("some_request_body")
)
.respond(
new HttpResponse()
.withBody("some_response_body")
.withHeaders(
new Header("responseName", "responseValue")
)
);
|
ForwardChainExpectation |
when(HttpRequest httpRequest,
Times times)
Specify an limited expectation that will respond a specified number of times when the request is matched
for example:
mockServerClient
.when(
new HttpRequest()
.withPath("/some_path")
.withBody("some_request_body"),
Times.exactly(5)
)
.respond(
new HttpResponse()
.withBody("some_response_body")
.withHeaders(
new Header("responseName", "responseValue")
)
);
|
public MockServerClient(String host, int port)
host - the host for the MockServer to communicate withport - the port for the MockServer to communicate withpublic ForwardChainExpectation when(HttpRequest httpRequest)
httpRequest - the request that must be matched for this expectation to respondpublic ForwardChainExpectation when(HttpRequest httpRequest, Times times)
httpRequest - the request that must be matched for this expectation to respondtimes - the number of times to respond when this request is matchedpublic void dumpToLog()
public void reset()
public void clear(HttpRequest httpRequest)
httpRequest - the request that is matched against when deciding whether to clear each expectationprotected void sendExpectation(Expectation expectation)
Copyright © 2013. All Rights Reserved.