Class AbstractHttpServletResponseAssert<R extends HttpServletResponse,SELF extends AbstractHttpServletResponseAssert<R,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<R,SELF,ACTUAL>
Type Parameters:
R - the type of HttpServletResponse
SELF - the type of assertions
ACTUAL - 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:
AbstractMockHttpServletResponseAssert

public abstract class AbstractHttpServletResponseAssert<R extends HttpServletResponse,SELF extends AbstractHttpServletResponseAssert<R,SELF,ACTUAL>,ACTUAL> extends org.assertj.core.api.AbstractObjectAssert<SELF,ACTUAL>
Base AssertJ assertions that can be applied to any object that provides an HttpServletResponse. This provides direct access to response assertions while also providing access to a different top-level object.
Since:
6.2
Author:
Stephane Nicoll
  • Field Summary

    Fields inherited from class org.assertj.core.api.AbstractAssert

    actual, info, myself, objects, throwUnsupportedExceptionOnEquals
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Verify that the response contains a header with the given name.
    Return a new assertion object that uses the response's content type as the object to test.
    Verify that the response does not contain a header with the given name.
    protected abstract R
    Provide the response to use if it is available.
    hasContentType(String contentType)
    Verify that the response's Content-Type is equal to the given string representation.
    Verify that the response's Content-Type is equal to the given value.
    Verify that the response's Content-Type is compatible with the given string representation.
    Verify that the response's Content-Type is compatible with the given value.
    hasHeader(String name, String value)
    Verify that the response contains a header with the given name and primary value.
    hasStatus(int status)
    Verify that the HTTP status is equal to the specified status code.
    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 to HttpStatus.OK.
    Return a new assertion object that uses HttpHeaders as 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, 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

    • AbstractHttpServletResponseAssert

      protected AbstractHttpServletResponseAssert(ACTUAL actual, Class<?> selfType)
  • Method Details

    • getResponse

      protected abstract R getResponse()
      Provide the response to use if it is available.

      Throws an AssertionError if the request has failed to process, and the response is not available.

      Returns:
      the response to use
    • contentType

      public MediaTypeAssert contentType()
      Return a new assertion object that uses the response's content type as the object to test.
    • headers

      public HttpHeadersAssert headers()
      Return a new assertion object that uses HttpHeaders as 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);
       
    • hasContentType

      public SELF hasContentType(MediaType contentType)
      Verify that the response's Content-Type is equal to the given value.
      Parameters:
      contentType - the expected content type
    • hasContentType

      public SELF hasContentType(String contentType)
      Verify that the response's Content-Type is equal to the given string representation.
      Parameters:
      contentType - the expected content type
    • hasContentTypeCompatibleWith

      public SELF hasContentTypeCompatibleWith(MediaType contentType)
      Verify that the response's Content-Type is compatible with the given value.
      Parameters:
      contentType - the expected compatible content type
    • hasContentTypeCompatibleWith

      public SELF hasContentTypeCompatibleWith(String contentType)
      Verify that the response's Content-Type is compatible with the given string representation.
      Parameters:
      contentType - the expected compatible content type
    • containsHeader

      public SELF containsHeader(String name)
      Verify that the response contains a header with the given name.
      Parameters:
      name - the name of an expected HTTP header
    • doesNotContainHeader

      public SELF doesNotContainHeader(String name)
      Verify that the response does not contain a header with the given name.
      Parameters:
      name - the name of an HTTP header that should not be present
    • hasHeader

      public SELF hasHeader(String name, String value)
      Verify that the response contains a header with the given name and primary value.
      Parameters:
      name - the name of an expected HTTP header
      value - the expected value of the header
    • hasStatus

      public SELF hasStatus(int status)
      Verify that the HTTP status is equal to the specified status code.
      Parameters:
      status - the expected HTTP status code
    • hasStatus

      public SELF hasStatus(HttpStatus status)
      Verify that the HTTP status is equal to the specified status.
      Parameters:
      status - the expected HTTP status code
    • hasStatusOk

      public SELF hasStatusOk()
      Verify that the HTTP status is equal to HttpStatus.OK.
      See Also:
    • hasStatus1xxInformational

      public SELF hasStatus1xxInformational()
      Verify that the HTTP status code is in the 1xx range.
      See Also:
    • hasStatus2xxSuccessful

      public SELF hasStatus2xxSuccessful()
      Verify that the HTTP status code is in the 2xx range.
      See Also:
    • hasStatus3xxRedirection

      public SELF hasStatus3xxRedirection()
      Verify that the HTTP status code is in the 3xx range.
      See Also:
    • hasStatus4xxClientError

      public SELF hasStatus4xxClientError()
      Verify that the HTTP status code is in the 4xx range.
      See Also:
    • hasStatus5xxServerError

      public SELF hasStatus5xxServerError()
      Verify that the HTTP status code is in the 5xx range.
      See Also: