use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientTest method testIamPermissionsExceptionTest.
@Test
@SuppressWarnings("all")
public void testIamPermissionsExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockIAMPolicy.addException(exception);
try {
String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
List<String> permissions = new ArrayList<>();
client.testIamPermissions(formattedResource, permissions);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientTest method listTopicSubscriptionsExceptionTest.
@Test
@SuppressWarnings("all")
public void listTopicSubscriptionsExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockPublisher.addException(exception);
try {
TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
client.listTopicSubscriptions(topic);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientTest method getIamPolicyExceptionTest.
@Test
@SuppressWarnings("all")
public void getIamPolicyExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockIAMPolicy.addException(exception);
try {
String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
client.getIamPolicy(formattedResource);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException 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 org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.
the class SpeechClientTest method asyncRecognizeExceptionTest.
@Test
@SuppressWarnings("all")
public void asyncRecognizeExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockSpeech.addException(exception);
try {
RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.FLAC;
int sampleRate = 44100;
RecognitionConfig config = RecognitionConfig.newBuilder().setEncoding(encoding).setSampleRate(sampleRate).build();
String uri = "gs://bucket_name/file_name.flac";
RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(uri).build();
client.asyncRecognizeAsync(config, audio).get();
Assert.fail("No exception raised");
} catch (ExecutionException e) {
Assert.assertEquals(ApiException.class, e.getCause().getClass());
ApiException apiException = (ApiException) e.getCause();
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), apiException.getStatusCode());
}
}
Aggregations