use of com.google.cloud.speech.v1beta1.StreamingRecognizeResponse in project google-cloud-java by GoogleCloudPlatform.
the class SpeechClientTest method streamingRecognizeExceptionTest.
@Test
@SuppressWarnings("all")
public void streamingRecognizeExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockSpeech.addException(exception);
StreamingRecognizeRequest request = StreamingRecognizeRequest.newBuilder().build();
MockStreamObserver<StreamingRecognizeResponse> responseObserver = new MockStreamObserver<>();
StreamingCallable<StreamingRecognizeRequest, StreamingRecognizeResponse> callable = client.streamingRecognizeCallable();
ApiStreamObserver<StreamingRecognizeRequest> requestObserver = callable.bidiStreamingCall(responseObserver);
requestObserver.onNext(request);
try {
List<StreamingRecognizeResponse> actualResponses = responseObserver.future().get();
Assert.fail("No exception thrown");
} catch (ExecutionException e) {
Assert.assertTrue(e.getCause() instanceof StatusRuntimeException);
StatusRuntimeException statusException = (StatusRuntimeException) e.getCause();
Assert.assertEquals(Status.INVALID_ARGUMENT, statusException.getStatus());
}
}
use of com.google.cloud.speech.v1beta1.StreamingRecognizeResponse in project google-cloud-java by GoogleCloudPlatform.
the class SpeechClientTest method streamingRecognizeTest.
@Test
@SuppressWarnings("all")
public void streamingRecognizeTest() throws Exception {
StreamingRecognizeResponse expectedResponse = StreamingRecognizeResponse.newBuilder().build();
mockSpeech.addResponse(expectedResponse);
StreamingRecognizeRequest request = StreamingRecognizeRequest.newBuilder().build();
MockStreamObserver<StreamingRecognizeResponse> responseObserver = new MockStreamObserver<>();
StreamingCallable<StreamingRecognizeRequest, StreamingRecognizeResponse> callable = client.streamingRecognizeCallable();
ApiStreamObserver<StreamingRecognizeRequest> requestObserver = callable.bidiStreamingCall(responseObserver);
requestObserver.onNext(request);
requestObserver.onCompleted();
List<StreamingRecognizeResponse> actualResponses = responseObserver.future().get();
Assert.assertEquals(1, actualResponses.size());
Assert.assertEquals(expectedResponse, actualResponses.get(0));
}
use of com.google.cloud.speech.v1beta1.StreamingRecognizeResponse in project google-cloud-java by GoogleCloudPlatform.
the class SpeechClientTest method streamingRecognizeExceptionTest.
@Test
@SuppressWarnings("all")
public void streamingRecognizeExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockSpeech.addException(exception);
StreamingRecognizeRequest request = StreamingRecognizeRequest.newBuilder().build();
MockStreamObserver<StreamingRecognizeResponse> responseObserver = new MockStreamObserver<>();
StreamingCallable<StreamingRecognizeRequest, StreamingRecognizeResponse> callable = client.streamingRecognizeCallable();
ApiStreamObserver<StreamingRecognizeRequest> requestObserver = callable.bidiStreamingCall(responseObserver);
requestObserver.onNext(request);
try {
List<StreamingRecognizeResponse> actualResponses = responseObserver.future().get();
Assert.fail("No exception thrown");
} catch (ExecutionException e) {
Assert.assertTrue(e.getCause() instanceof StatusRuntimeException);
StatusRuntimeException statusException = (StatusRuntimeException) e.getCause();
Assert.assertEquals(Status.INVALID_ARGUMENT, statusException.getStatus());
}
}
use of com.google.cloud.speech.v1beta1.StreamingRecognizeResponse in project google-cloud-java by GoogleCloudPlatform.
the class SpeechClientTest method streamingRecognizeTest.
@Test
@SuppressWarnings("all")
public void streamingRecognizeTest() throws Exception {
int resultIndex = 520358448;
StreamingRecognizeResponse expectedResponse = StreamingRecognizeResponse.newBuilder().setResultIndex(resultIndex).build();
mockSpeech.addResponse(expectedResponse);
StreamingRecognizeRequest request = StreamingRecognizeRequest.newBuilder().build();
MockStreamObserver<StreamingRecognizeResponse> responseObserver = new MockStreamObserver<>();
StreamingCallable<StreamingRecognizeRequest, StreamingRecognizeResponse> callable = client.streamingRecognizeCallable();
ApiStreamObserver<StreamingRecognizeRequest> requestObserver = callable.bidiStreamingCall(responseObserver);
requestObserver.onNext(request);
requestObserver.onCompleted();
List<StreamingRecognizeResponse> actualResponses = responseObserver.future().get();
Assert.assertEquals(1, actualResponses.size());
Assert.assertEquals(expectedResponse, actualResponses.get(0));
}
Aggregations