Enum Class MockMode

java.lang.Object
java.lang.Enum<MockMode>
org.mockserver.mock.MockMode
All Implemented Interfaces:
Serializable, Comparable<MockMode>, Constable

public enum MockMode extends Enum<MockMode>
High-level operating mode for MockServer, packaging the common record / replay / pass-through workflows into a single switch (set via PUT /mockserver/mode). Each mode is a convenience over the existing attemptToProxyIfNoMatchingExpectation configuration plus the event-log recording that MockServer already performs:
  • SIMULATE — match expectations and return mocks; unmatched requests get a 404. This is the default behaviour (proxy-on-no-match disabled).
  • SPY — match expectations and return mocks, but forward unmatched requests to the real upstream (proxy-on-no-match enabled) so they are served live and recorded.
  • CAPTURE — forward and record; with no expectations defined this captures all traffic. Backed by the same proxy-on-no-match behaviour as SPY.

Recorded interactions are available through the existing recording/retrieve endpoints (e.g. retrieving recorded requests as expectations).

  • Enum Constant Details

    • SIMULATE

      public static final MockMode SIMULATE
    • SPY

      public static final MockMode SPY
    • CAPTURE

      public static final MockMode CAPTURE
  • Method Details

    • values

      public static MockMode[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static MockMode valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • proxyUnmatchedRequests

      public boolean proxyUnmatchedRequests()
      Whether, in this mode, a request that matches no expectation should be proxied to its upstream (and thereby recorded) rather than answered with a 404.
    • fromProxyFlag

      public static MockMode fromProxyFlag(boolean attemptToProxyIfNoMatchingExpectation)
      Derives the reported mode from the live attemptToProxyIfNoMatchingExpectation flag. SPY and CAPTURE share the same underlying flag, so an enabled flag reports as SPY.
    • parse

      public static MockMode parse(String value)
      Parses a mode name case-insensitively.
      Throws:
      IllegalArgumentException - if the value is null/blank or not a known mode