Class ResponseMatchers
java.lang.Object
com._4point.testing.matchers.jaxrs.ResponseMatchers
Response Matchers for testing an JAX-RS HTTP Response object.
Based on https://www.planetgeek.ch/2012/03/07/create-your-own-matcher/
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringContent-type string for "application/pdf"static final jakarta.ws.rs.core.MediaTypeJAX-RS MedisType object for "application/pdf" -
Method Summary
Modifier and TypeMethodDescriptionstatic org.hamcrest.Matcher<jakarta.ws.rs.core.Response> Creates a Matcher that validates that a Response does not have an entity..static HtmlFormexpectingHtmlForm(jakarta.ws.rs.core.Response response, URI baseUri) Performs a series of checks on the Response object to validate that it is a response containing HTML and then returns an HtmlForm object for further validation.static PdfexpectingPdf(jakarta.ws.rs.core.Response response) Performs a series of checks on the Response object to validate that it is a response containing a PDF and then returns a Pdf object for further validation.static org.hamcrest.Matcher<jakarta.ws.rs.core.Response> Creates a Matcher that validates that a Response has an entity.static org.hamcrest.Matcher<jakarta.ws.rs.core.Response> hasEntityEqualTo(byte[] bytes) Creates a matcher that compares the Response bytes with a provided bute array to see if they match.static org.hamcrest.Matcher<jakarta.ws.rs.core.Response> hasEntityMatching(org.hamcrest.Matcher<byte[]> byteMatcher) Creates a matcher that allows someone to validate the bytes in the response entity.static org.hamcrest.Matcher<jakarta.ws.rs.core.Response> hasMediaType(jakarta.ws.rs.core.MediaType expectedMediaType) Creates a Matcher that compares a Response object's MediaType to the one provided.static org.hamcrest.Matcher<jakarta.ws.rs.core.Response> hasStringEntityMatching(Charset charset, org.hamcrest.Matcher<String> stringMatcher) Creates a matcher that allows someone to validate the response entity as a Srting.static org.hamcrest.Matcher<jakarta.ws.rs.core.Response> hasStringEntityMatching(org.hamcrest.Matcher<String> stringMatcher) Creates a matcher that allows someone to validate the response entity as a Srting.static org.hamcrest.Matcher<jakarta.ws.rs.core.Response> isStatus(jakarta.ws.rs.core.Response.Status expectedStatus) Creates a Matcher that compares a Response object's status to the one provided.
-
Field Details
-
APPLICATION_PDF
Content-type string for "application/pdf"- See Also:
-
APPLICATION_PDF_TYPE
public static final jakarta.ws.rs.core.MediaType APPLICATION_PDF_TYPEJAX-RS MedisType object for "application/pdf"
-
-
Method Details
-
isStatus
public static org.hamcrest.Matcher<jakarta.ws.rs.core.Response> isStatus(jakarta.ws.rs.core.Response.Status expectedStatus) Creates a Matcher that compares a Response object's status to the one provided.- Parameters:
expectedStatus- the expected Status- Returns:
- The matcher
-
hasMediaType
public static org.hamcrest.Matcher<jakarta.ws.rs.core.Response> hasMediaType(jakarta.ws.rs.core.MediaType expectedMediaType) Creates a Matcher that compares a Response object's MediaType to the one provided.- Parameters:
expectedMediaType- the expected MediaType- Returns:
- the matcher
-
hasEntity
public static org.hamcrest.Matcher<jakarta.ws.rs.core.Response> hasEntity()Creates a Matcher that validates that a Response has an entity.- Returns:
- the matcher
-
doesNotHaveEntity
public static org.hamcrest.Matcher<jakarta.ws.rs.core.Response> doesNotHaveEntity()Creates a Matcher that validates that a Response does not have an entity..- Returns:
- the matcher
-
hasEntityMatching
public static org.hamcrest.Matcher<jakarta.ws.rs.core.Response> hasEntityMatching(org.hamcrest.Matcher<byte[]> byteMatcher) Creates a matcher that allows someone to validate the bytes in the response entity. The matcher fails if the Response has no entity to match against.- Parameters:
byteMatcher- a matcher that validates the bytes in the response enrity- Returns:
- the matcher
-
hasStringEntityMatching
public static org.hamcrest.Matcher<jakarta.ws.rs.core.Response> hasStringEntityMatching(Charset charset, org.hamcrest.Matcher<String> stringMatcher) Creates a matcher that allows someone to validate the response entity as a Srting. The matcher fails if the Response has no entity to match against.- Parameters:
charset- the character set the incoming data should be instringMatcher- a matcher that validates the response entity as a String- Returns:
- the matcher
-
hasStringEntityMatching
public static org.hamcrest.Matcher<jakarta.ws.rs.core.Response> hasStringEntityMatching(org.hamcrest.Matcher<String> stringMatcher) Creates a matcher that allows someone to validate the response entity as a Srting. The matcher fails if the Response has no entity to match against. Current assumes that the incoming data is in UTF-9.- Parameters:
stringMatcher- a matcher that validates the response entity as a String- Returns:
- the matcher
-
hasEntityEqualTo
public static org.hamcrest.Matcher<jakarta.ws.rs.core.Response> hasEntityEqualTo(byte[] bytes) Creates a matcher that compares the Response bytes with a provided bute array to see if they match.- Parameters:
bytes- a byte array to be matched against- Returns:
- the matcher
-
expectingPdf
Performs a series of checks on the Response object to validate that it is a response containing a PDF and then returns a Pdf object for further validation. * it ensures the ContentType header is application/pdf * it ensures the Status is OK * it ensures there is a body in the response * it reads the body into a PDF object which parses the body using a PDF parser.- Parameters:
response- the Response object to be validated- Returns:
- the valid Pdf object
- Throws:
Pdf.PdfException- thrown if there are any I/O or parsing errors when validating the Pdf
-
expectingHtmlForm
Performs a series of checks on the Response object to validate that it is a response containing HTML and then returns an HtmlForm object for further validation. * it ensures the ContentType header is test/html * it ensures the Status is OK * it ensures there is a body in the response * it reads the body into a HtmlForm object which parses the body using an Html parser.- Parameters:
response- the Response object to be validatedbaseUri- base location of the form- Returns:
- the valid HtmlForm object
- Throws:
IllegalStateException- thrown if there are any I/O or parsing errors when validating the Html
-