Class AbstractHeaderAssertions<E,R>
java.lang.Object
org.springframework.test.web.support.AbstractHeaderAssertions<E,R>
- Type Parameters:
E
- the type of the exchange resultR
- the type of the response spec
- Direct Known Subclasses:
HeaderAssertions
,HeaderAssertions
Assertions on headers of the response.
- Since:
- 7.0
- Author:
- Rob Worsnop, Rossen Stoyanchev
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractHeaderAssertions
(E exchangeResult, R responseSpec) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
assertWithDiagnostics
(Runnable assertion) Subclasses must implement this to assert with diagnostics.cacheControl
(CacheControl cacheControl) Expect a "Cache-Control" header with the given value.contentDisposition
(ContentDisposition contentDisposition) Expect a "Content-Disposition" header with the given value.contentLength
(long contentLength) Expect a "Content-Length" header with the given value.contentType
(String mediaType) Expect a "Content-Type" header with the given value.contentType
(MediaType mediaType) Expect a "Content-Type" header with the given value.contentTypeCompatibleWith
(String mediaType) Expect a "Content-Type" header compatible with the given value.contentTypeCompatibleWith
(MediaType mediaType) Expect a "Content-Type" header compatible with the given value.doesNotExist
(String name) Expect that the header with the given name is not present.Expect that the header with the given name is present.expires
(long expires) Expect an "Expires" header with the given value.protected E
Return the exchange result.protected abstract HttpHeaders
Subclasses must implement this to provide access to response headers.lastModified
(long lastModified) Expect a "Last-Modified" header with the given value.Expect a "Location" header with the given value.Consume the first value of the named response header.Assert the first value of the response header with a HamcrestMatcher
.valueEquals
(String headerName, long value) Expect a header with the given name to match the given long value.valueEquals
(String headerName, String... values) Expect a header with the given name to match the specified values.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.valueMatches
(String name, String pattern) Match the first value of the response header with a regex.Consume all values of the named response header.Assert all values of the response header with a HamcrestMatcher
.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.
-
Constructor Details
-
AbstractHeaderAssertions
-
-
Method Details
-
getExchangeResult
Return the exchange result. -
getResponseHeaders
Subclasses must implement this to provide access to response headers. -
assertWithDiagnostics
Subclasses must implement this to assert with diagnostics. -
valueEquals
-
valueEquals
-
valueEqualsDate
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 suppliedvalue
does not match the primary header value. -
valueMatches
-
valuesMatch
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 namepatterns
- one or more regex patterns, one per expected value
-
value
-
values
-
value
-
values
-
exists
-
doesNotExist
-
cacheControl
Expect a "Cache-Control" header with the given value. -
contentDisposition
Expect a "Content-Disposition" header with the given value. -
contentLength
Expect a "Content-Length" header with the given value. -
contentType
-
contentType
-
contentTypeCompatibleWith
-
contentTypeCompatibleWith
-
expires
Expect an "Expires" header with the given value. -
lastModified
Expect a "Last-Modified" header with the given value. -
location
-