Class AsyncApiControlPlaneImpl

java.lang.Object
org.mockserver.async.controlplane.AsyncApiControlPlaneImpl
All Implemented Interfaces:
AsyncApiControlPlane

public class AsyncApiControlPlaneImpl extends Object implements AsyncApiControlPlane
Implementation of AsyncApiControlPlane that lives in the mockserver-async module and is registered into the core's AsyncApiControlPlaneRegistry at server startup.

Handles:

  • Loading AsyncAPI specs via the REST control-plane
  • Creating publishers and subscribers for each channel
  • Schema validation of generated and consumed messages
  • Returning status including recorded messages
  • Resetting all state on server reset
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a control-plane with no Configuration instance, falling back entirely to the static ConfigurationProperties store for async broker defaults.
    Create a control-plane bound to the server's Configuration instance so that instance-set async broker defaults are honoured.
  • Method Summary

    Modifier and Type
    Method
    Description
    Generate HTTP mock expectations from an AsyncAPI spec so that example messages can be served over plain HTTP (one GET expectation per channel returning a schema-aware example payload), without standing up a live message broker.
    com.fasterxml.jackson.databind.JsonNode
    load(String requestBody)
    Load an AsyncAPI spec and start mocking (publishing and/or subscribing).
    static void
    Register this implementation into the core registry, without a Configuration instance.
    static void
    Register this implementation into the core registry.
    void
    Reset all async mocking state — stop publishers/subscribers, clear recorded messages.
    com.fasterxml.jackson.databind.JsonNode
    Return the current status: loaded spec info, active channels, publishers, subscribers, and recorded messages.
    verify(String verificationJson)
    Verify that recorded messages match the given criteria.

    Methods inherited from class java.lang.Object

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

    • AsyncApiControlPlaneImpl

      public AsyncApiControlPlaneImpl()
      Create a control-plane with no Configuration instance, falling back entirely to the static ConfigurationProperties store for async broker defaults.
    • AsyncApiControlPlaneImpl

      public AsyncApiControlPlaneImpl(Configuration configuration)
      Create a control-plane bound to the server's Configuration instance so that instance-set async broker defaults are honoured.
      Parameters:
      configuration - the server configuration, or null to use only the static store
  • Method Details

    • registerIfAvailable

      public static void registerIfAvailable()
      Register this implementation into the core registry, without a Configuration instance. Prefer registerIfAvailable(Configuration) so that instance-set configuration is honoured.
    • registerIfAvailable

      public static void registerIfAvailable(Configuration configuration)
      Register this implementation into the core registry. Call at server startup (e.g. from MockServerLifeCycle or Main).
      Parameters:
      configuration - the server configuration, or null to use only the static store
    • load

      public com.fasterxml.jackson.databind.JsonNode load(String requestBody)
      Description copied from interface: AsyncApiControlPlane
      Load an AsyncAPI spec and start mocking (publishing and/or subscribing).
      Specified by:
      load in interface AsyncApiControlPlane
      Parameters:
      requestBody - the raw request body — either a plain AsyncAPI spec (JSON/YAML) or a JSON wrapper {"spec": "...", "brokerConfig": {...}}
      Returns:
      a JSON status node describing what was loaded and started
    • status

      public com.fasterxml.jackson.databind.JsonNode status()
      Description copied from interface: AsyncApiControlPlane
      Return the current status: loaded spec info, active channels, publishers, subscribers, and recorded messages.
      Specified by:
      status in interface AsyncApiControlPlane
      Returns:
      a JSON status node
    • verify

      public String verify(String verificationJson)
      Description copied from interface: AsyncApiControlPlane
      Verify that recorded messages match the given criteria.

      The verification request is a JSON string with fields:

      • channel (required) — the channel/topic to check
      • payloadSubstring (optional) — payload must contain this substring
      • payloadJsonPath (optional) — a dot-notation JSON path to extract
      • expectedValue (optional) — the expected value at the JSON path
      • count (optional) — object with atLeast, atMost, or exactly fields; defaults to atLeast: 1
      Specified by:
      verify in interface AsyncApiControlPlane
      Parameters:
      verificationJson - the JSON verification request
      Returns:
      null or empty string if the verification passes; a human-readable failure description if it does not
    • generateHttpExpectations

      public String generateHttpExpectations(String requestBody)
      Description copied from interface: AsyncApiControlPlane
      Generate HTTP mock expectations from an AsyncAPI spec so that example messages can be served over plain HTTP (one GET expectation per channel returning a schema-aware example payload), without standing up a live message broker.

      This is the import analogue of AsyncApiControlPlane.load(String): instead of publishing example messages to a broker, it returns expectations the caller can register on the HTTP mock. Implemented in mockserver-async (which has access to mockserver-core types), the result is returned as a JSON array string in the standard MockServer expectation format, so that HttpState can deserialize and add it without a compile-time dependency on the async module's parser.

      Specified by:
      generateHttpExpectations in interface AsyncApiControlPlane
      Parameters:
      requestBody - the raw request body — a plain AsyncAPI spec (JSON/YAML) or a JSON wrapper {"spec": "...", "channelPathPrefix": "..."}
      Returns:
      a JSON array string of MockServer expectations (one per channel)
    • reset

      public void reset()
      Description copied from interface: AsyncApiControlPlane
      Reset all async mocking state — stop publishers/subscribers, clear recorded messages. Called from HttpState.reset().
      Specified by:
      reset in interface AsyncApiControlPlane