Class HttpResponseBuilder
-
- All Implemented Interfaces:
public class HttpResponseBuilder extends HttpPartBuilder
Pact HTTP Response builder DSL that supports V4 formatted Pact files
-
-
Constructor Summary
Constructors Constructor Description HttpResponseBuilder(HttpResponse response)
-
Method Summary
Modifier and Type Method Description final HttpResponsebuild()Terminate the builder and return the response object HttpResponseBuilderheader(String key, Object value)Adds a header to the HTTP part. HttpResponseBuilderheaders(String key, String value, String nameValuePairs)Adds all the headers to the HTTP part. HttpResponseBuilderheaders(Pair<String, Object> nameValuePairs)Adds all the headers to the HTTP part. HttpResponseBuilderheaders(Map<String, Object> values)Adds all the headers to the HTTP part. final HttpResponseBuildermatchSetCookie(String cookie, String regex, String example)Match a set cookie header final HttpResponseBuilderstatus(Integer status)Sets the status code of the response final HttpResponseBuilderinformationStatus()Match any HTTP Information response status (100-199) final HttpResponseBuildersuccessStatus()Match any HTTP success response status (200-299) final HttpResponseBuilderredirectStatus()Match any HTTP redirect response status (300-399) final HttpResponseBuilderclientErrorStatus()Match any HTTP client error response status (400-499) final HttpResponseBuilderserverErrorStatus()Match any HTTP server error response status (500-599) final HttpResponseBuildernonErrorStatus()Match any HTTP non-error response status (< 400) final HttpResponseBuildererrorStatus()Match any HTTP error response status (>= 400) final HttpResponseBuilderstatusCodes(List<Integer> statusCodes)Match any HTTP status code in the provided list HttpResponseBuilderbody(String body)Sets the body of the HTTP part as a string value. HttpResponseBuilderbody(String body, String contentTypeString)Sets the body of the HTTP part as a string value. HttpResponseBuilderbody(ByteArray body)Sets the body of the HTTP part as a byte array. HttpResponseBuilderbody(ByteArray body, String contentTypeString)Sets the body of the HTTP part as a string value. HttpResponseBuilderbody(DslPart dslPart)Sets the body, content type and matching rules from a DslPart HttpResponseBuilderbody(BodyBuilder builder)Sets the body, content type and matching rules from a BodyBuilder HttpResponseBuilderbodyMatchingContentType(String contentType, ByteArray exampleContents)Sets up a content type matcher to match any body of the given content type HttpResponseBuilderbodyMatchingContentType(String contentType, String exampleContents)Sets up a content type matcher to match any body of the given content type -
-
Method Detail
-
build
final HttpResponse build()
Terminate the builder and return the response object
-
header
HttpResponseBuilder header(String key, Object value)
Adds a header to the HTTP part. The value will be converted to a string (using the toString() method), unless it is a List. With a List as the value, it will set up a multiple value header. If the value resolves to a single String, and the header key is for a header that has multiple values, the values will be split into a list.
For example:
header("OPTIONS", "GET, POST, PUT")is the same asheader("OPTIONS", List.of("GET", "POST, "PUT"))
-
headers
HttpResponseBuilder headers(String key, String value, String nameValuePairs)
Adds all the headers to the HTTP part. The values will be converted to a string (using the toString() method), and the header key is for a header that has multiple values, the values will be split into a list.
For example:
headers("OPTIONS", "GET, POST, PUT")is the same asheader("OPTIONS", List.of("GET", "POST, "PUT"))
-
headers
HttpResponseBuilder headers(Pair<String, Object> nameValuePairs)
Adds all the headers to the HTTP part. The values will be converted to a string (using the toString() method), and the header key is for a header that has multiple values, the values will be split into a list.
For example:
headers("OPTIONS", "GET, POST, PUT")is the same asheader("OPTIONS", List.of("GET", "POST, "PUT"))
-
headers
HttpResponseBuilder headers(Map<String, Object> values)
Adds all the headers to the HTTP part. You can either pass a Map<String -> String>, and values will be converted to a string (using the toString() method), and the header key is for a header that has multiple values, the values will be split into a list.
For example:
headers(Map<"OPTIONS", "GET, POST, PUT">)is the same asheader(Map<"OPTIONS", List<"GET", "POST, "PUT">>))Or pass in a Map<String -> List<String>> and no conversion will take place.
-
matchSetCookie
final HttpResponseBuilder matchSetCookie(String cookie, String regex, String example)
Match a set cookie header
- Parameters:
cookie- Cookie name to matchregex- Regex to match the cookie value withexample- Example value
-
status
final HttpResponseBuilder status(Integer status)
Sets the status code of the response
-
informationStatus
final HttpResponseBuilder informationStatus()
Match any HTTP Information response status (100-199)
-
successStatus
final HttpResponseBuilder successStatus()
Match any HTTP success response status (200-299)
-
redirectStatus
final HttpResponseBuilder redirectStatus()
Match any HTTP redirect response status (300-399)
-
clientErrorStatus
final HttpResponseBuilder clientErrorStatus()
Match any HTTP client error response status (400-499)
-
serverErrorStatus
final HttpResponseBuilder serverErrorStatus()
Match any HTTP server error response status (500-599)
-
nonErrorStatus
final HttpResponseBuilder nonErrorStatus()
Match any HTTP non-error response status (< 400)
-
errorStatus
final HttpResponseBuilder errorStatus()
Match any HTTP error response status (>= 400)
-
statusCodes
final HttpResponseBuilder statusCodes(List<Integer> statusCodes)
Match any HTTP status code in the provided list
-
body
HttpResponseBuilder body(String body)
Sets the body of the HTTP part as a string value. If the content type is not already set, it will try to detect the content type from the given string, otherwise will default to text/plain.
-
body
HttpResponseBuilder body(String body, String contentTypeString)
Sets the body of the HTTP part as a string value. If the content type is not already set, it will try to detect the content type from the given string, otherwise will default to text/plain.
-
body
HttpResponseBuilder body(ByteArray body)
Sets the body of the HTTP part as a byte array. If the content type is not already set, will default to application/octet-stream.
-
body
HttpResponseBuilder body(ByteArray body, String contentTypeString)
Sets the body of the HTTP part as a string value. If the content type is not provided or already set, will default to application/octet-stream.
-
body
HttpResponseBuilder body(DslPart dslPart)
Sets the body, content type and matching rules from a DslPart
-
body
HttpResponseBuilder body(BodyBuilder builder)
Sets the body, content type and matching rules from a BodyBuilder
-
bodyMatchingContentType
HttpResponseBuilder bodyMatchingContentType(String contentType, ByteArray exampleContents)
Sets up a content type matcher to match any body of the given content type
-
bodyMatchingContentType
HttpResponseBuilder bodyMatchingContentType(String contentType, String exampleContents)
Sets up a content type matcher to match any body of the given content type
-
-
-
-