Class RestTestClientResponseAssert
java.lang.Object
org.assertj.core.api.AbstractAssert<RestTestClientResponseAssert, RestTestClientResponse>
org.assertj.core.api.AbstractObjectAssert<RestTestClientResponseAssert, RestTestClientResponse>
org.springframework.test.web.servlet.client.assertj.RestTestClientResponseAssert
- All Implemented Interfaces:
org.assertj.core.api.Assert<RestTestClientResponseAssert, RestTestClientResponse>, org.assertj.core.api.Descriptable<RestTestClientResponseAssert>, org.assertj.core.api.ExtensionPoints<RestTestClientResponseAssert, RestTestClientResponse>
public class RestTestClientResponseAssert
extends org.assertj.core.api.AbstractObjectAssert<RestTestClientResponseAssert, RestTestClientResponse>
AssertJ assertions for the result from a
RestTestClient exchange.- Since:
- 7.0
- Author:
- Rossen Stoyanchev
-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals -
Method Summary
Modifier and TypeMethodDescriptionorg.assertj.core.api.AbstractByteArrayAssert<?> body()Return a new assertion object that uses the response body as the object to test.bodyJson()Return a new assertion object that uses the response body converted to text as the object to test.org.assertj.core.api.AbstractStringAssert<?> bodyText()Return a new assertion object that uses the response body converted to text as the object to test.containsHeader(String name) Verify that the response contains a header with the givenname.Return a new assertion object that uses the response's content type as the object to test.cookies()Return a new assertion object that uses the response's cookies as the object to test.doesNotContainHeader(String name) Verify that the response does not contain a header with the givenname.hasBodyTextEqualTo(String bodyText) Verify that the response body is equal to the given value.hasContentType(String contentType) Verify that the response'sContent-Typeis equal to the given string representation.hasContentType(MediaType contentType) Verify that the response'sContent-Typeis equal to the given value.hasContentTypeCompatibleWith(String contentType) Verify that the response'sContent-Typeis compatible with the given string representation.hasContentTypeCompatibleWith(MediaType contentType) Verify that the response'sContent-Typeis compatible with the given value.Verify that the response contains a header with the givennameand primaryvalue.hasStatus(int status) Verify that the HTTP status is equal to the specified status code.hasStatus(HttpStatus status) Verify that the HTTP status is equal to the specified status.Verify that the HTTP status code is in the 1xx range.Verify that the HTTP status code is in the 2xx range.Verify that the HTTP status code is in the 3xx range.Verify that the HTTP status code is in the 4xx range.Verify that the HTTP status code is in the 5xx range.Verify that the HTTP status is equal toHttpStatus.OK.headers()Return a new assertion object that usesHttpHeadersas the object to test.Methods inherited from class org.assertj.core.api.AbstractObjectAssert
as, as, doesNotReturn, extracting, extracting, extracting, extracting, extracting, extracting, extractingForProxy, getComparatorsByType, hasAllNullFieldsOrProperties, hasAllNullFieldsOrPropertiesExcept, hasFieldOrProperty, hasFieldOrPropertyWithValue, hasNoNullFieldsOrProperties, hasNoNullFieldsOrPropertiesExcept, hasOnlyFields, isEqualToComparingFieldByField, isEqualToComparingFieldByFieldRecursively, isEqualToComparingOnlyGivenFields, isEqualToIgnoringGivenFields, isEqualToIgnoringNullFields, newObjectAssert, returns, usingComparatorForFields, usingComparatorForType, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparisonMethods inherited from class org.assertj.core.api.AbstractAssert
actual, areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, doesNotMatch, doesNotMatch, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingEquals, usingEquals, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnErrorMethods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.assertj.core.api.Descriptable
as, describedAs, describedAs
-
Method Details
-
hasStatus
Verify that the HTTP status is equal to the specified status code.- Parameters:
status- the expected HTTP status code
-
hasStatus
Verify that the HTTP status is equal to the specified status.- Parameters:
status- the expected HTTP status code
-
hasStatusOk
Verify that the HTTP status is equal toHttpStatus.OK.- See Also:
-
hasStatus1xxInformational
Verify that the HTTP status code is in the 1xx range.- See Also:
-
hasStatus2xxSuccessful
Verify that the HTTP status code is in the 2xx range.- See Also:
-
hasStatus3xxRedirection
Verify that the HTTP status code is in the 3xx range.- See Also:
-
hasStatus4xxClientError
Verify that the HTTP status code is in the 4xx range.- See Also:
-
hasStatus5xxServerError
Verify that the HTTP status code is in the 5xx range.- See Also:
-
headers
Return a new assertion object that usesHttpHeadersas the object to test. The returned assertion object provides all the regular map assertions, with headers mapped by header name. Examples:// Check for the presence of the Accept header: assertThat(response).headers().containsHeader(HttpHeaders.ACCEPT); // Check for the absence of the Content-Length header: assertThat(response).headers().doesNotContainsHeader(HttpHeaders.CONTENT_LENGTH); -
containsHeader
Verify that the response contains a header with the givenname.- Parameters:
name- the name of an expected HTTP header
-
doesNotContainHeader
Verify that the response does not contain a header with the givenname.- Parameters:
name- the name of an HTTP header that should not be present
-
hasHeader
Verify that the response contains a header with the givennameand primaryvalue.- Parameters:
name- the name of an expected HTTP headervalue- the expected value of the header
-
contentType
Return a new assertion object that uses the response's content type as the object to test. -
hasContentType
Verify that the response'sContent-Typeis equal to the given value.- Parameters:
contentType- the expected content type
-
hasContentType
Verify that the response'sContent-Typeis equal to the given string representation.- Parameters:
contentType- the expected content type
-
hasContentTypeCompatibleWith
Verify that the response'sContent-Typeis compatible with the given value.- Parameters:
contentType- the expected compatible content type
-
hasContentTypeCompatibleWith
Verify that the response'sContent-Typeis compatible with the given string representation.- Parameters:
contentType- the expected compatible content type
-
cookies
Return a new assertion object that uses the response's cookies as the object to test. -
body
public org.assertj.core.api.AbstractByteArrayAssert<?> body()Return a new assertion object that uses the response body as the object to test.- See Also:
-
bodyText
public org.assertj.core.api.AbstractStringAssert<?> bodyText()Return a new assertion object that uses the response body converted to text as the object to test.Examples:
// Check that the response body is equal to "Hello World": assertThat(response).bodyText().isEqualTo("Hello World"); -
hasBodyTextEqualTo
Verify that the response body is equal to the given value. -
bodyJson
Return a new assertion object that uses the response body converted to text as the object to test. Compared tobodyText(), the assertion object provides dedicated JSON support.Examples:
The returned assert object also supports JSON path expressions.// Check that the response body is strictly equal to the content of // "/com/acme/sample/person-created.json": assertThat(response).bodyJson() .isStrictlyEqualToJson("/com/acme/sample/person-created.json"); // Check that the response is strictly equal to the content of the // specified file located in the same package as the PersonController: assertThat(response).bodyJson().withResourceLoadClass(PersonController.class) .isStrictlyEqualToJson("person-created.json");Examples:
// Check that the JSON document does not have an "error" element assertThat(response).bodyJson().doesNotHavePath("$.error"); // Check that the JSON document as a top level "message" element assertThat(response).bodyJson() .extractingPath("$.message").asString().isEqualTo("hello");
-