Class LoadScenarioRegistry

java.lang.Object
org.mockserver.mock.action.http.LoadScenarioRegistry

public class LoadScenarioRegistry extends Object
Persisted, named registry of load scenario definitions.

A scenario is loaded (registered) here under its name — the unique registry key — by PUT /mockserver/loadScenario. Loading stores the definition but does not run anything; an explicit PUT /mockserver/loadScenario/start triggers one or more registered scenarios to run. This mirrors the saved-chaos-profile library (ChaosProfileLibrary): a template store, not the active-run store.

Storage: definitions live in the StateBackend's crudEntities("load-scenarios") key-value store, keyed by scenario name. This gives:

  • Survives resetHttpState.reset() stops active runs but does not clear the registry, so loaded scenarios outlive a reset and can be re-triggered.
  • Cluster-correct — when the backend is clustered, loads/deletes replicate across the fleet via the same CRUD-entity replication used by the chaos registries.
  • Preloadable — startup preloading writes definitions here so a node can boot with scenarios staged in the LOADED state, ready to trigger.

Each stored value is the scenario's JSON ObjectNode (the same shape accepted by the PUT endpoint); the registry key (the store key) overrides any name inside the body so the loaded-under name wins. Loading the same name replaces the prior definition.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    CRUD-entity namespace under which loaded scenario definitions are stored.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes all registered scenarios.
    boolean
    True if a scenario is registered under name.
    boolean
    delete(String name)
    Removes the registered scenario name.
    Optional<com.fasterxml.jackson.databind.node.ObjectNode>
    get(String name)
    Returns the loaded scenario definition for name, or Optional.empty() if no such scenario is registered.
    Returns the names of all registered scenarios, in ascending name order.
    void
    load(String name, com.fasterxml.jackson.databind.JsonNode definition)
    Loads (or replaces) a scenario definition under name.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BACKEND_NAMESPACE

      public static final String BACKEND_NAMESPACE
      CRUD-entity namespace under which loaded scenario definitions are stored.
      See Also:
  • Constructor Details

    • LoadScenarioRegistry

      public LoadScenarioRegistry(StateBackend backend)
  • Method Details

    • load

      public void load(String name, com.fasterxml.jackson.databind.JsonNode definition)
      Loads (or replaces) a scenario definition under name. The definition is the scenario JSON — the same shape accepted by PUT /mockserver/loadScenario. The stored copy's name field is normalised to name so the loaded-under name wins.
      Throws:
      IllegalArgumentException - if the name is blank or the definition is not a JSON object
    • get

      public Optional<com.fasterxml.jackson.databind.node.ObjectNode> get(String name)
      Returns the loaded scenario definition for name, or Optional.empty() if no such scenario is registered.
    • list

      public List<String> list()
      Returns the names of all registered scenarios, in ascending name order.
    • contains

      public boolean contains(String name)
      True if a scenario is registered under name.
    • delete

      public boolean delete(String name)
      Removes the registered scenario name. Returns true if a scenario was present and removed, false if no such scenario existed.
    • clear

      public void clear()
      Removes all registered scenarios.