Search in sources :

Example 86 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class MetricsClientTest method createLogMetricExceptionTest.

@Test
@SuppressWarnings("all")
public void createLogMetricExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockMetricsServiceV2.addException(exception);
    try {
        ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
        LogMetric metric = LogMetric.newBuilder().build();
        client.createLogMetric(parent, metric);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : LogMetric(com.google.logging.v2.LogMetric) ParentNameOneof(com.google.logging.v2.ParentNameOneof) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 87 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class MetricsClientTest method deleteLogMetricExceptionTest.

@Test
@SuppressWarnings("all")
public void deleteLogMetricExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockMetricsServiceV2.addException(exception);
    try {
        MetricNameOneof metricName = MetricNameOneof.from(MetricName.create("[PROJECT]", "[METRIC]"));
        client.deleteLogMetric(metricName);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : MetricNameOneof(com.google.logging.v2.MetricNameOneof) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 88 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class MetricsClientTest method getLogMetricExceptionTest.

@Test
@SuppressWarnings("all")
public void getLogMetricExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockMetricsServiceV2.addException(exception);
    try {
        MetricNameOneof metricName = MetricNameOneof.from(MetricName.create("[PROJECT]", "[METRIC]"));
        client.getLogMetric(metricName);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : MetricNameOneof(com.google.logging.v2.MetricNameOneof) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 89 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class MetricServiceClientTest method getMetricDescriptorExceptionTest.

@Test
@SuppressWarnings("all")
public void getMetricDescriptorExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockMetricService.addException(exception);
    try {
        MetricDescriptorName name = MetricDescriptorName.create("[PROJECT]", "[METRIC_DESCRIPTOR]");
        client.getMetricDescriptor(name);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : MetricDescriptorName(com.google.monitoring.v3.MetricDescriptorName) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 90 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class MetricServiceClientTest method deleteMetricDescriptorExceptionTest.

@Test
@SuppressWarnings("all")
public void deleteMetricDescriptorExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockMetricService.addException(exception);
    try {
        MetricDescriptorName name = MetricDescriptorName.create("[PROJECT]", "[METRIC_DESCRIPTOR]");
        client.deleteMetricDescriptor(name);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : MetricDescriptorName(com.google.monitoring.v3.MetricDescriptorName) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Aggregations

StatusRuntimeException (io.grpc.StatusRuntimeException)131 Test (org.junit.Test)110 ApiException (com.google.api.gax.grpc.ApiException)74 ByteString (com.google.protobuf.ByteString)12 Status (io.grpc.Status)12 ArrayList (java.util.ArrayList)11 Metadata (io.grpc.Metadata)10 SubscriptionName (com.google.pubsub.v1.SubscriptionName)9 ProjectName (com.google.monitoring.v3.ProjectName)6 TopicName (com.google.pubsub.v1.TopicName)6 StreamObserver (io.grpc.stub.StreamObserver)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Document (com.google.cloud.language.v1beta2.Document)5 ParentNameOneof (com.google.logging.v2.ParentNameOneof)5 IOException (java.io.IOException)5 ExecutionException (java.util.concurrent.ExecutionException)5 Document (com.google.cloud.language.v1.Document)4 EncodingType (com.google.cloud.language.v1beta2.EncodingType)4 HelloReply (io.grpc.examples.helloworld.HelloReply)4 HelloRequest (io.grpc.examples.helloworld.HelloRequest)4