Class AbstractHeaderAssertions<E,R>

java.lang.Object
org.springframework.test.web.support.AbstractHeaderAssertions<E,R>
Type Parameters:
E - the type of the exchange result
R - the type of the response spec
Direct Known Subclasses:
HeaderAssertions, HeaderAssertions

public abstract class AbstractHeaderAssertions<E,R> extends Object
Assertions on headers of the response.
Since:
7.0
Author:
Rob Worsnop, Rossen Stoyanchev
  • Constructor Details

    • AbstractHeaderAssertions

      protected AbstractHeaderAssertions(E exchangeResult, R responseSpec)
  • Method Details

    • getExchangeResult

      protected E getExchangeResult()
      Return the exchange result.
    • getResponseHeaders

      protected abstract HttpHeaders getResponseHeaders()
      Subclasses must implement this to provide access to response headers.
    • assertWithDiagnostics

      protected abstract void assertWithDiagnostics(Runnable assertion)
      Subclasses must implement this to assert with diagnostics.
    • valueEquals

      public R valueEquals(String headerName, String... values)
      Expect a header with the given name to match the specified values.
    • valueEquals

      public R valueEquals(String headerName, long value)
      Expect a header with the given name to match the given long value.
    • valueEqualsDate

      public R valueEqualsDate(String headerName, long value)
      Expect a header with the given name to match the specified long value parsed into a date using the preferred date format described in RFC 7231.

      An AssertionError is thrown if the response does not contain the specified header, or if the supplied value does not match the primary header value.

    • valueMatches

      public R valueMatches(String name, String pattern)
      Match the first value of the response header with a regex.
      Parameters:
      name - the header name
      pattern - the regex pattern
    • valuesMatch

      public R valuesMatch(String name, String... patterns)
      Match all values of the response header with the given regex patterns which are applied to the values of the header in the same order. Note that the number of patterns must match the number of actual values.
      Parameters:
      name - the header name
      patterns - one or more regex patterns, one per expected value
    • value

      public R value(String name, Matcher<? super String> matcher)
      Assert the first value of the response header with a Hamcrest Matcher.
      Parameters:
      name - the header name
      matcher - the matcher to use
    • values

      public R values(String name, Matcher<? super Iterable<String>> matcher)
      Assert all values of the response header with a Hamcrest Matcher.
      Parameters:
      name - the header name
      matcher - the matcher to use
    • value

      public R value(String name, Consumer<String> consumer)
      Consume the first value of the named response header.
      Parameters:
      name - the header name
      consumer - the consumer to use
    • values

      public R values(String name, Consumer<List<String>> consumer)
      Consume all values of the named response header.
      Parameters:
      name - the header name
      consumer - the consumer to use
    • exists

      public R exists(String name)
      Expect that the header with the given name is present.
    • doesNotExist

      public R doesNotExist(String name)
      Expect that the header with the given name is not present.
    • cacheControl

      public R cacheControl(CacheControl cacheControl)
      Expect a "Cache-Control" header with the given value.
    • contentDisposition

      public R contentDisposition(ContentDisposition contentDisposition)
      Expect a "Content-Disposition" header with the given value.
    • contentLength

      public R contentLength(long contentLength)
      Expect a "Content-Length" header with the given value.
    • contentType

      public R contentType(MediaType mediaType)
      Expect a "Content-Type" header with the given value.
    • contentType

      public R contentType(String mediaType)
      Expect a "Content-Type" header with the given value.
    • contentTypeCompatibleWith

      public R contentTypeCompatibleWith(MediaType mediaType)
      Expect a "Content-Type" header compatible with the given value.
    • contentTypeCompatibleWith

      public R contentTypeCompatibleWith(String mediaType)
      Expect a "Content-Type" header compatible with the given value.
    • expires

      public R expires(long expires)
      Expect an "Expires" header with the given value.
    • lastModified

      public R lastModified(long lastModified)
      Expect a "Last-Modified" header with the given value.
    • location

      public R location(String location)
      Expect a "Location" header with the given value.