use of okhttp3.internal.ws.WebSocketRecorder in project java-sdk by watson-developer-cloud.
the class SpeechToTextTest method testClosingInputStreamClosesWebSocket.
@Test
public void testClosingInputStreamClosesWebSocket() throws Exception {
TestRecognizeCallback callback = new TestRecognizeCallback();
WebSocketRecorder webSocketRecorder = new WebSocketRecorder("server");
PipedOutputStream outputStream = new PipedOutputStream();
InputStream inputStream = new PipedInputStream(outputStream);
server.enqueue(new MockResponse().withWebSocketUpgrade(webSocketRecorder));
String customizationId = "id";
String version = "version";
Double customizationWeight = 0.1;
RecognizeOptions options = new RecognizeOptions.Builder().audio(inputStream).contentType(HttpMediaType.createAudioRaw(44000)).customizationId(customizationId).version(version).customizationWeight(customizationWeight).build();
service.recognizeUsingWebSocket(options, callback);
WebSocket serverSocket = webSocketRecorder.assertOpen();
serverSocket.send("{\"state\": {}}");
outputStream.write(ByteString.encodeUtf8("test").toByteArray());
outputStream.close();
webSocketRecorder.assertTextMessage("{\"content-type\":\"audio/l16; rate=44000\"," + "\"action\":\"start\"}");
webSocketRecorder.assertBinaryMessage(ByteString.encodeUtf8("test"));
webSocketRecorder.assertTextMessage("{\"action\":\"stop\"}");
webSocketRecorder.assertExhausted();
serverSocket.close(1000, null);
callback.assertConnected();
callback.assertDisconnected();
callback.assertNoErrors();
callback.assertOnTranscriptionComplete();
}
Aggregations