Search in sources :

Example 11 with ApiException

use of com.google.api.gax.grpc.ApiException in project google-cloud-java by GoogleCloudPlatform.

the class SubscriptionAdminClientTest method modifyAckDeadlineExceptionTest.

@Test
@SuppressWarnings("all")
public void modifyAckDeadlineExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockSubscriber.addException(exception);
    try {
        SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
        List<String> ackIds = new ArrayList<>();
        int ackDeadlineSeconds = 2135351438;
        client.modifyAckDeadline(subscription, ackIds, ackDeadlineSeconds);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) ArrayList(java.util.ArrayList) SubscriptionName(com.google.pubsub.v1.SubscriptionName) ByteString(com.google.protobuf.ByteString) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 12 with ApiException

use of com.google.api.gax.grpc.ApiException in project google-cloud-java by GoogleCloudPlatform.

the class TopicAdminClientTest method setIamPolicyExceptionTest.

@Test
@SuppressWarnings("all")
public void setIamPolicyExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockIAMPolicy.addException(exception);
    try {
        String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
        Policy policy = Policy.newBuilder().build();
        client.setIamPolicy(formattedResource, policy);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : Policy(com.google.iam.v1.Policy) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 13 with ApiException

use of com.google.api.gax.grpc.ApiException 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());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 14 with ApiException

use of com.google.api.gax.grpc.ApiException 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());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) TopicName(com.google.pubsub.v1.TopicName) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 15 with ApiException

use of com.google.api.gax.grpc.ApiException 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());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Aggregations

ApiException (com.google.api.gax.grpc.ApiException)75 Test (org.junit.Test)75 StatusRuntimeException (io.grpc.StatusRuntimeException)74 ByteString (com.google.protobuf.ByteString)9 ArrayList (java.util.ArrayList)9 SubscriptionName (com.google.pubsub.v1.SubscriptionName)8 ProjectName (com.google.monitoring.v3.ProjectName)6 TopicName (com.google.pubsub.v1.TopicName)6 Document (com.google.cloud.language.v1beta2.Document)5 ParentNameOneof (com.google.logging.v2.ParentNameOneof)5 Document (com.google.cloud.language.v1.Document)4 EncodingType (com.google.cloud.language.v1beta2.EncodingType)4 ProjectName (com.google.devtools.clouderrorreporting.v1beta1.ProjectName)4 EncodingType (com.google.cloud.language.v1.EncodingType)3 MetricNameOneof (com.google.logging.v2.MetricNameOneof)3 SinkNameOneof (com.google.logging.v2.SinkNameOneof)3 GroupName (com.google.monitoring.v3.GroupName)3 ProjectName (com.google.pubsub.v1.ProjectName)3 ExecutionException (java.util.concurrent.ExecutionException)3 RecognitionAudio (com.google.cloud.speech.v1.RecognitionAudio)2