Class RealtimeMockBuilder

java.lang.Object
org.mockserver.client.RealtimeMockBuilder

public class RealtimeMockBuilder extends Object
Fluent builder that stands MockServer up as a mock realtime voice API — either the OpenAI Realtime API or the Google Gemini Live API — over a WebSocket, so an application/agent using those SDKs can be tested offline.

It produces a single httpWebSocketResponse expectation that reuses the generic WebSocket mock primitive: an initial pushed frame (OpenAI session.created) plus per-incoming-frame matchers that reply to the client's control messages with the provider-correct scripted event sequence generated by OpenAiRealtimeCodec / GeminiLiveCodec. No new action type, DTO, or JSON schema is required — exactly as A2A streaming reuses httpSseResponse.

OpenAI Realtime (wss://.../v1/realtime): the mock pushes session.created on connect, acknowledges session.update → session.updated and conversation.item.create → conversation.item.created, and answers each response.create with the scripted response event sequence (…deltas… → response.done with usage).

Gemini Live (BidiGenerateContent): the mock answers setup → setupComplete and each clientContent turn with the scripted serverContent chunk stream + turnComplete.

The same script answers every matching frame, so a client that sends response.create / clientContent N times receives the scripted turn N times.

 RealtimeMockBuilder.openAiRealtime()
     .withModel("gpt-realtime")
     .respondingWith("The capital of France is Paris.")
     .applyTo(mockServerClient);
 
  • Field Details

    • DEFAULT_OPENAI_REALTIME_PATH

      public static final String DEFAULT_OPENAI_REALTIME_PATH
      Default OpenAI Realtime path.
      See Also:
    • DEFAULT_GEMINI_LIVE_PATH

      public static final String DEFAULT_GEMINI_LIVE_PATH
      Default Gemini Live BidiGenerateContent path.
      See Also:
  • Method Details

    • openAiRealtime

      public static RealtimeMockBuilder openAiRealtime()
    • openAiRealtime

      public static RealtimeMockBuilder openAiRealtime(String path)
    • geminiLive

      public static RealtimeMockBuilder geminiLive()
    • geminiLive

      public static RealtimeMockBuilder geminiLive(String path)
    • withPath

      public RealtimeMockBuilder withPath(String path)
    • withModel

      public RealtimeMockBuilder withModel(String model)
    • withSubprotocol

      public RealtimeMockBuilder withSubprotocol(String subprotocol)
      The negotiated WebSocket subprotocol. Left unset by default so the handshake accepts whatever the client offers (OpenAI clients carry auth in the subprotocol list, which an offline mock ignores).
    • withSessionId

      public RealtimeMockBuilder withSessionId(String sessionId)
      OpenAI only — the session id echoed in session.created / session.updated.
    • withModality

      public RealtimeMockBuilder withModality(org.mockserver.llm.realtime.RealtimeModality modality)
      RealtimeModality.AUDIO (default — transcript + audio deltas) or RealtimeModality.TEXT.
    • withTokensPerSecond

      public RealtimeMockBuilder withTokensPerSecond(int tokensPerSecond)
      Streaming rate for content deltas (default 50).
    • withTimeToFirstToken

      public RealtimeMockBuilder withTimeToFirstToken(long millis)
      Extra delay before the first content delta, in milliseconds.
    • respondingWith

      public RealtimeMockBuilder respondingWith(org.mockserver.llm.realtime.RealtimeTurn turn)
    • respondingWith

      public RealtimeMockBuilder respondingWith(String text)
    • applyTo

      public org.mockserver.mock.Expectation[] applyTo(MockServerClient client)
    • build

      public org.mockserver.mock.Expectation build()