Class RealtimeMockBuilder
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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionapplyTo(MockServerClient client) build()static RealtimeMockBuilderstatic RealtimeMockBuildergeminiLive(String path) static RealtimeMockBuilderstatic RealtimeMockBuilderopenAiRealtime(String path) respondingWith(String text) respondingWith(RealtimeTurn turn) withModality(RealtimeModality modality) RealtimeModality.AUDIO(default — transcript + audio deltas) orRealtimeModality.TEXT.withSessionId(String sessionId) OpenAI only — the session id echoed insession.created/session.updated.withSubprotocol(String subprotocol) The negotiated WebSocket subprotocol.withTimeToFirstToken(long millis) Extra delay before the first content delta, in milliseconds.withTokensPerSecond(int tokensPerSecond) Streaming rate for content deltas (default 50).
-
Field Details
-
DEFAULT_OPENAI_REALTIME_PATH
Default OpenAI Realtime path.- See Also:
-
DEFAULT_GEMINI_LIVE_PATH
Default Gemini LiveBidiGenerateContentpath.- See Also:
-
-
Method Details
-
openAiRealtime
-
openAiRealtime
-
geminiLive
-
geminiLive
-
withPath
-
withModel
-
withSubprotocol
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
OpenAI only — the session id echoed insession.created/session.updated. -
withModality
RealtimeModality.AUDIO(default — transcript + audio deltas) orRealtimeModality.TEXT. -
withTokensPerSecond
Streaming rate for content deltas (default 50). -
withTimeToFirstToken
Extra delay before the first content delta, in milliseconds. -
respondingWith
-
respondingWith
-
applyTo
-
build
-