Class AbstractMockHttpServletResponseAssert<SELF extends AbstractMockHttpServletResponseAssert<SELF,ACTUAL>,ACTUAL>
java.lang.Object
org.assertj.core.api.AbstractAssert<SELF,ACTUAL>
org.assertj.core.api.AbstractObjectAssert<SELF,ACTUAL>
org.springframework.test.web.servlet.assertj.AbstractHttpServletResponseAssert<MockHttpServletResponse,SELF,ACTUAL>
org.springframework.test.web.servlet.assertj.AbstractMockHttpServletResponseAssert<SELF,ACTUAL>
- Type Parameters:
SELF
- the type of assertionsACTUAL
- the type of the object to assert
- All Implemented Interfaces:
org.assertj.core.api.Assert<SELF,
,ACTUAL> org.assertj.core.api.Descriptable<SELF>
,org.assertj.core.api.ExtensionPoints<SELF,
ACTUAL>
- Direct Known Subclasses:
MvcTestResultAssert
public abstract class AbstractMockHttpServletResponseAssert<SELF extends AbstractMockHttpServletResponseAssert<SELF,ACTUAL>,ACTUAL>
extends AbstractHttpServletResponseAssert<MockHttpServletResponse,SELF,ACTUAL>
Extension of
AbstractHttpServletResponseAssert
for
MockHttpServletResponse
.- Since:
- 6.2
- Author:
- Stephane Nicoll
-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractMockHttpServletResponseAssert
(HttpMessageContentConverter contentConverter, ACTUAL actual, Class<?> selfType) -
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.Return a new assertion object that uses the forwarded URL as the object to test.hasBodyTextEqualTo
(String bodyText) Verify that the response body is equal to the given value.hasErrorMessage
(String errorMessage) Verify that theHttpServletResponse.sendError(int, String)
Servlet error message} is equal to the given value.hasForwardedUrl
(String forwardedUrl) Verify that the forwarded URL is equal to the given value.hasRedirectedUrl
(String redirectedUrl) Verify that the redirected URL is equal to the given value.Return a new assertion object that uses the redirected URL as the object to test.Methods inherited from class org.springframework.test.web.servlet.assertj.AbstractHttpServletResponseAssert
containsHeader, contentType, doesNotContainHeader, getResponse, hasContentType, hasContentType, hasContentTypeCompatibleWith, hasContentTypeCompatibleWith, hasHeader, hasStatus, hasStatus, hasStatus1xxInformational, hasStatus2xxSuccessful, hasStatus3xxRedirection, hasStatus4xxClientError, hasStatus5xxServerError, hasStatusOk, headers
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, usingRecursiveComparison
Methods inherited from class org.assertj.core.api.AbstractAssert
areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, 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, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnError
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.assertj.core.api.Descriptable
as, describedAs, describedAs
-
Constructor Details
-
AbstractMockHttpServletResponseAssert
protected AbstractMockHttpServletResponseAssert(@Nullable HttpMessageContentConverter contentConverter, ACTUAL actual, Class<?> selfType)
-
-
Method Details
-
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");
-
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");
-
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:
-
forwardedUrl
Return a new assertion object that uses the forwarded URL as the object to test. If a simple equality check is required, consider usinghasForwardedUrl(String)
instead.Example:
// Check that the forwarded URL starts with "/orders/": assertThat(response).forwardedUrl().matchPattern("/orders/*);
-
redirectedUrl
Return a new assertion object that uses the redirected URL as the object to test. If a simple equality check is required, consider usinghasRedirectedUrl(String)
instead.Example:
// Check that the redirected URL starts with "/orders/": assertThat(response).redirectedUrl().matchPattern("/orders/*);
-
hasBodyTextEqualTo
Verify that the response body is equal to the given value. -
hasForwardedUrl
Verify that the forwarded URL is equal to the given value.- Parameters:
forwardedUrl
- the expected forwarded URL (can be null)
-
hasRedirectedUrl
Verify that the redirected URL is equal to the given value.- Parameters:
redirectedUrl
- the expected redirected URL (can be null)
-
hasErrorMessage
Verify that theHttpServletResponse.sendError(int, String)
Servlet error message} is equal to the given value.- Parameters:
errorMessage
- the expected Servlet error message (can be null)- Since:
- 6.2.1
-