Class AbstractCookiesSnippet

java.lang.Object
org.springframework.restdocs.snippet.TemplatedSnippet
org.springframework.restdocs.cookies.AbstractCookiesSnippet
All Implemented Interfaces:
Snippet
Direct Known Subclasses:
RequestCookiesSnippet, ResponseCookiesSnippet

public abstract class AbstractCookiesSnippet extends TemplatedSnippet
Abstract TemplatedSnippet subclass that provides a base for snippets that document a RESTful resource's request or response cookies.
Since:
3.0
Author:
Clyde Stubbs, Andy Wilkinson
  • Constructor Details

    • AbstractCookiesSnippet

      protected AbstractCookiesSnippet(String type, List<CookieDescriptor> descriptors, Map<String,Object> attributes, boolean ignoreUndocumentedCookies)
      Creates a new AbstractCookiesSnippet that will produce a snippet named <type>-cookies. The cookies will be documented using the given descriptors and the given attributes will be included in the model during template rendering.
      Parameters:
      type - the type of the cookies
      descriptors - the cookie descriptors
      attributes - the additional attributes
      ignoreUndocumentedCookies - whether undocumented cookies should be ignored
  • Method Details

    • createModel

      protected Map<String,Object> createModel(Operation operation)
      Description copied from class: TemplatedSnippet
      Create the model that should be used during template rendering to document the given operation. Any additional attributes that were supplied when this TemplatedSnippet were created will be automatically added to the model prior to rendering.
      Specified by:
      createModel in class TemplatedSnippet
      Parameters:
      operation - the operation
      Returns:
      the model
    • extractActualCookies

      protected abstract Set<String> extractActualCookies(Operation operation)
      Extracts the names of the cookies from the request or response of the given operation.
      Parameters:
      operation - the operation
      Returns:
      the cookie names
    • verificationFailed

      protected abstract void verificationFailed(Set<String> undocumentedCookies, Set<String> missingCookies)
      Called when the documented cookies do not match the actual cookies.
      Parameters:
      undocumentedCookies - the cookies that were found in the operation but were not documented
      missingCookies - the cookies that were documented but were not found in the operation
    • getCookieDescriptors

      protected final Map<String,CookieDescriptor> getCookieDescriptors()
      Returns the list of CookieDescriptors that will be used to generate the documentation.
      Returns:
      the cookie descriptors
    • isIgnoreUndocumentedCookies

      protected final boolean isIgnoreUndocumentedCookies()
      Returns whether or not this snippet ignores undocumented cookies.
      Returns:
      true if undocumented cookies are ignored, otherwise false
    • createModelForDescriptor

      protected Map<String,Object> createModelForDescriptor(CookieDescriptor descriptor)
      Returns a model for the given descriptor.
      Parameters:
      descriptor - the descriptor
      Returns:
      the model