Class MatchRules

java.lang.Object
com.easypost.easyvcr.MatchRules

public final class MatchRules extends Object
Rule set for matching requests against recorded requests.
  • Constructor Details

    • MatchRules

      public MatchRules()
      Construct a new MatchRules factory.
  • Method Details

    • regular

      public static MatchRules regular()
      Default rule is to match on the method and URL.
      Returns:
      Default MatchRules object.
    • strict

      public static MatchRules strict()
      Default strict rule is to match on the method, URL and body.
      Returns:
      Default strict MatchRules object.
    • byBaseUrl

      public MatchRules byBaseUrl()
      Add a rule to compare the base URLs of the requests.
      Returns:
      This MatchRules factory.
    • byBody

      public MatchRules byBody(List<CensorElement> ignoredElements)
      Add a rule to compare the bodies of the requests.
      Parameters:
      ignoredElements - List of body elements to ignore when comparing the requests.
      Returns:
      This MatchRules factory.
    • byBody

      public MatchRules byBody()
      Add a rule to compare the bodies of the requests.
      Returns:
      This MatchRules factory.
    • byEverything

      public MatchRules byEverything()
      Add a rule to compare the entire requests. Note, this rule is very strict, and will fail if the requests are not identical (including duration). It is highly recommended to use the other rules to compare the requests.
      Returns:
      This MatchRules factory.
    • byFullUrl

      public MatchRules byFullUrl()
      Add a rule to compare the full URLs (including query parameters) of the requests. Default: query parameter order does not matter.
      Returns:
      This MatchRules factory.
    • byFullUrl

      public MatchRules byFullUrl(boolean exact)
      Add a rule to compare the full URLs (including query parameters) of the requests.
      Parameters:
      exact - If true, query parameters must be in the same exact order to match. If false, query parameter order doesn't matter.
      Returns:
      This MatchRules factory.
    • byHeader

      public MatchRules byHeader(String name)
      Add a rule to compare a specific header of the requests.
      Parameters:
      name - Key of the header to compare.
      Returns:
      This MatchRules factory.
    • byHeaders

      public MatchRules byHeaders()
      Add a rule to compare the headers of the requests. Default: headers strictness is set to false.
      Returns:
      This MatchRules factory.
    • byHeaders

      public MatchRules byHeaders(boolean exact)
      Add a rule to compare the headers of the requests.
      Parameters:
      exact - If true, both requests must have the exact same headers. If false, as long as the evaluated request has all the headers of the matching request (and potentially more), the match is considered valid.
      Returns:
      This MatchRules factory.
    • byMethod

      public MatchRules byMethod()
      Add a rule to compare the HTTP methods of the requests.
      Returns:
      This MatchRules factory.
    • requestsMatch

      public boolean requestsMatch(Request receivedRequest, Request recordedRequest)
      Execute rules to determine if the received request matches the recorded request.
      Parameters:
      receivedRequest - Request to find a match for.
      recordedRequest - Request to compare against.
      Returns:
      True if the received request matches the recorded request, false otherwise.