Start the client communicating to a MockServer at the specified host and port
for example:
MockServerClient mockServerClient = new MockServerClient("localhost", 8080);
Start the client communicating to a MockServer at the specified host and port
and contextPath for example:
MockServerClient mockServerClient = new MockServerClient("localhost", 8080, "/mockserver");
O
once() -
Static method in class org.mockserver.client.proxy.Times
Start the client communicating to the proxy at the specified host and port
for example:
ProxyClient mockServerClient = new ProxyClient("localhost", 1080);
Verify a request has been sent for example:
mockServerClient
.verify(
request()
.withPath("/some_path")
.withBody("some_request_body"),
Times.exactly(3)
);
Times 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
Verify a request has been sent for example:
mockServerClient
.verify(
request()
.withPath("/some_path")
.withBody("some_request_body"),
Times.exactly(3)
);
Times 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
Verify a request has been sent for a specific expected response example:
mockServerClient
.verify(
request()
.withPath("/some_path")
.withBody("some_request_body"),
Times.exactly(3)
);
This version is useful if multiple requests have been configured with different
responses the needs to confirm that an exact response has been received.
Specify an unlimited expectation that will respond regardless of the number of matching http
for example:
mockServerClient
.when(
request()
.withPath("/some_path")
.withBody("some_request_body")
)
.respond(
response()
.withBody("some_response_body")
.withHeaders(
new Header("responseName", "responseValue")
)
);
Specify an limited expectation that will respond a specified number of times when the http 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")
)
);