Class HttpClientMockBuilder
- java.lang.Object
-
- com.github.paweladamski.httpclientmock.HttpClientMockBuilder
-
public class HttpClientMockBuilder extends Object
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description HttpClientResponseBuilderdoAction(Action action)Adds custom action.HttpClientResponseBuilderdoReturn(int statusCode, String response)Adds action which returns provided response and status in UTF-8.HttpClientResponseBuilderdoReturn(int statusCode, String response, Charset charset)Adds action which returns provided response in provided charset and status.HttpClientResponseBuilderdoReturn(String response)Adds action which returns provided response in UTF-8 and status 200.HttpClientResponseBuilderdoReturn(String response, Charset charset)Adds action which returns provided response in provided charset and status 200.HttpClientResponseBuilderdoReturn(String response, org.apache.hc.core5.http.ContentType contentType)Adds action which returns provided response in provided charset, content-type and status 200.HttpClientResponseBuilderdoReturnFormParams(Collection<org.apache.hc.core5.http.NameValuePair> parameters)Adds action which returns provided URL-encoded parameter response in UTF-8 and status 200.HttpClientResponseBuilderdoReturnFormParams(Collection<org.apache.hc.core5.http.NameValuePair> parameters, Charset charset)Adds action which returns provided URL-encoded parameter response in provided charset and status 200.HttpClientResponseBuilderdoReturnJSON(String response)Adds action which returns provided JSON in UTF-8 and status 200.HttpClientResponseBuilderdoReturnJSON(String response, Charset charset)Adds action which returns provided JSON in provided charset and status 200.HttpClientResponseBuilderdoReturnStatus(int statusCode)Deprecated.use doReturnWithStatus insteadHttpClientResponseBuilderdoReturnWithStatus(int statusCode)Adds action which returns provided status and null entity.HttpClientResponseBuilderdoReturnWithStatus(int statusCode, String reason)Adds action which returns provided status with reason and null entity.HttpClientResponseBuilderdoReturnXML(String response)Adds action which returns provided XML in UTF-8 and status 200.HttpClientResponseBuilderdoReturnXML(String response, Charset charset)Adds action which returns provided XML in provided charset and status 200.HttpClientResponseBuilderdoThrowException(IOException exception)Adds action which throws provided exception.HttpClientMockBuilderwith(Condition condition)Adds custom conditions.HttpClientMockBuilderwithBody(org.hamcrest.Matcher<String> matcher)Adds body condition.HttpClientMockBuilderwithExtraFormParameters()Allows extra parameters (not defined in condition) in form.HttpClientMockBuilderwithExtraParameters()Allows extra parameters (not defined in condition) in query.HttpClientMockBuilderwithFormParameter(String name, String value)Request body must contain the given URL-encoded form parameter (typically found in POST requests).HttpClientMockBuilderwithFormParameter(String name, org.hamcrest.Matcher<String> matcher)Request body must contain the given URL-encoded form parameter (typically found in POST requests).HttpClientMockBuilderwithFormParameters(ParametersMatcher parameters)Request body must contain the given URL-encoded form parameters (typically used in POST requests).HttpClientMockBuilderwithHeader(String header, String value)Adds header condition.HttpClientMockBuilderwithHeader(String header, org.hamcrest.Matcher<String> matcher)Adds header condition.HttpClientMockBuilderwithHost(String host)Adds host condition.HttpClientMockBuilderwithoutExtraFormParameters()Disallows extra parameters (not defined in condition) in form.HttpClientMockBuilderwithoutExtraParameters()Disallows extra parameters (not defined in condition) in query.HttpClientMockBuilderwithParameter(String name, String value)Adds parameter condition.HttpClientMockBuilderwithParameter(String name, org.hamcrest.Matcher<String> matcher)Adds parameter condition.HttpClientMockBuilderwithPath(String path)Adds path condition.HttpClientMockBuilderwithPath(org.hamcrest.Matcher<String> matcher)Adds path condition.
-
-
-
Method Detail
-
withHeader
public HttpClientMockBuilder withHeader(String header, String value)
Adds header condition. Header must be equal to provided value.- Parameters:
header- header namevalue- expected value- Returns:
- condition builder
-
withHeader
public HttpClientMockBuilder withHeader(String header, org.hamcrest.Matcher<String> matcher)
Adds header condition. Header must be equal to provided value.- Parameters:
header- header namematcher- header value matcher- Returns:
- condition builder
-
withParameter
public HttpClientMockBuilder withParameter(String name, String value)
Adds parameter condition. Parameter must be equal to provided value.- Parameters:
name- parameter namevalue- expected parameter value- Returns:
- condition builder
-
withParameter
public HttpClientMockBuilder withParameter(String name, org.hamcrest.Matcher<String> matcher)
Adds parameter condition. Parameter value must match.- Parameters:
name- parameter namematcher- parameter value matcher- Returns:
- condition builder
-
withFormParameter
public HttpClientMockBuilder withFormParameter(String name, String value)
Request body must contain the given URL-encoded form parameter (typically found in POST requests). Alternatively, parameters may be specified all at once usingwithFormParameters(ParametersMatcher).- Parameters:
name- parameter namevalue- expected parameter value- Returns:
- condition builder
-
withFormParameter
public HttpClientMockBuilder withFormParameter(String name, org.hamcrest.Matcher<String> matcher)
Request body must contain the given URL-encoded form parameter (typically found in POST requests). Alternatively, parameters may be specified all at once usingwithFormParameters(ParametersMatcher).- Parameters:
name- parameter namematcher- parameter value matcher- Returns:
- condition builder
-
withFormParameters
public HttpClientMockBuilder withFormParameters(ParametersMatcher parameters)
Request body must contain the given URL-encoded form parameters (typically used in POST requests). Alternatively, parameters may be specified individually usingwithFormParameter(String, Matcher).- Parameters:
parameters- the parameters- Returns:
- condition builder
-
with
public HttpClientMockBuilder with(Condition condition)
Adds custom conditions.- Parameters:
condition- custom condition- Returns:
- condition builder
-
withBody
public HttpClientMockBuilder withBody(org.hamcrest.Matcher<String> matcher)
Adds body condition. Request body must match provided matcher.- Parameters:
matcher- custom condition- Returns:
- condition builder
-
withHost
public HttpClientMockBuilder withHost(String host)
Adds host condition. Request host must be equal to provided value.- Parameters:
host- expected host- Returns:
- condition builder
-
withPath
public HttpClientMockBuilder withPath(String path)
Adds path condition. Request path must be equal to provided value.- Parameters:
path- expected path- Returns:
- condition builder
-
withPath
public HttpClientMockBuilder withPath(org.hamcrest.Matcher<String> matcher)
Adds path condition. Request path must match.- Parameters:
matcher- path matcher- Returns:
- condition builder
-
withExtraParameters
public HttpClientMockBuilder withExtraParameters()
Allows extra parameters (not defined in condition) in query.- Returns:
- condition builder
-
withoutExtraParameters
public HttpClientMockBuilder withoutExtraParameters()
Disallows extra parameters (not defined in condition) in query.- Returns:
- condition builder
-
withExtraFormParameters
public HttpClientMockBuilder withExtraFormParameters()
Allows extra parameters (not defined in condition) in form.- Returns:
- condition builder
-
withoutExtraFormParameters
public HttpClientMockBuilder withoutExtraFormParameters()
Disallows extra parameters (not defined in condition) in form.- Returns:
- condition builder
-
doAction
public HttpClientResponseBuilder doAction(Action action)
Adds custom action.- Parameters:
action- custom action- Returns:
- response builder
-
doReturn
public HttpClientResponseBuilder doReturn(String response)
Adds action which returns provided response in UTF-8 and status 200.- Parameters:
response- response to return- Returns:
- response builder
-
doReturnWithStatus
public HttpClientResponseBuilder doReturnWithStatus(int statusCode)
Adds action which returns provided status and null entity.- Parameters:
statusCode- status to return- Returns:
- response builder
-
doReturnWithStatus
public HttpClientResponseBuilder doReturnWithStatus(int statusCode, String reason)
Adds action which returns provided status with reason and null entity.- Parameters:
statusCode- status to returnreason- reason to return- Returns:
- response builder
-
doReturn
public HttpClientResponseBuilder doReturn(int statusCode, String response)
Adds action which returns provided response and status in UTF-8.- Parameters:
statusCode- status to returnresponse- response to return- Returns:
- response builder
-
doReturn
public HttpClientResponseBuilder doReturn(String response, Charset charset)
Adds action which returns provided response in provided charset and status 200.- Parameters:
response- response to returncharset- charset to return- Returns:
- response builder
-
doReturn
public HttpClientResponseBuilder doReturn(int statusCode, String response, Charset charset)
Adds action which returns provided response in provided charset and status.- Parameters:
statusCode- status to returnresponse- response to returncharset- the charset- Returns:
- response builder
-
doReturn
public HttpClientResponseBuilder doReturn(String response, org.apache.hc.core5.http.ContentType contentType)
Adds action which returns provided response in provided charset, content-type and status 200.- Parameters:
response- response to returncontentType- response content-type- Returns:
- response builder
-
doReturnStatus
@Deprecated public HttpClientResponseBuilder doReturnStatus(int statusCode)
Deprecated.use doReturnWithStatus insteadAdds action which returns empty message and provided status.- Parameters:
statusCode- status to return- Returns:
- response builder
-
doThrowException
public HttpClientResponseBuilder doThrowException(IOException exception)
Adds action which throws provided exception.- Parameters:
exception- exception to be thrown- Returns:
- response builder
-
doReturnJSON
public HttpClientResponseBuilder doReturnJSON(String response)
Adds action which returns provided JSON in UTF-8 and status 200. Additionally it sets "Content-type" header to "application/json".- Parameters:
response- JSON to return- Returns:
- response builder
-
doReturnJSON
public HttpClientResponseBuilder doReturnJSON(String response, Charset charset)
Adds action which returns provided JSON in provided charset and status 200. Additionally it sets "Content-type" header to "application/json".- Parameters:
response- JSON to returncharset- response charset- Returns:
- response builder
-
doReturnXML
public HttpClientResponseBuilder doReturnXML(String response)
Adds action which returns provided XML in UTF-8 and status 200. Additionally it sets "Content-type" header to "application/xml".- Parameters:
response- JSON to return- Returns:
- response builder
-
doReturnXML
public HttpClientResponseBuilder doReturnXML(String response, Charset charset)
Adds action which returns provided XML in provided charset and status 200. Additionally it sets "Content-type" header to "application/xml".- Parameters:
response- JSON to returncharset- response charset- Returns:
- response builder
-
doReturnFormParams
public HttpClientResponseBuilder doReturnFormParams(Collection<org.apache.hc.core5.http.NameValuePair> parameters)
Adds action which returns provided URL-encoded parameter response in UTF-8 and status 200. Additionally it sets "Content-type" header to "application/x-www-form-urlencoded".- Parameters:
parameters- parameters to return- Returns:
- response builder
-
doReturnFormParams
public HttpClientResponseBuilder doReturnFormParams(Collection<org.apache.hc.core5.http.NameValuePair> parameters, Charset charset)
Adds action which returns provided URL-encoded parameter response in provided charset and status 200. Additionally it sets "Content-type" header to "application/x-www-form-urlencoded".- Parameters:
parameters- parameters to returncharset- response charset- Returns:
- response builder
-
-