Search in sources :

Example 31 with ApiException

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

the class ConfigClientTest method deleteSinkExceptionTest.

@Test
@SuppressWarnings("all")
public void deleteSinkExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockConfigServiceV2.addException(exception);
    try {
        SinkNameOneof sinkName = SinkNameOneof.from(SinkName.create("[PROJECT]", "[SINK]"));
        client.deleteSink(sinkName);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : SinkNameOneof(com.google.logging.v2.SinkNameOneof) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 32 with ApiException

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

the class ConfigClientTest method createSinkExceptionTest.

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

Example 33 with ApiException

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

the class LoggingClientTest method writeLogEntriesExceptionTest.

@Test
@SuppressWarnings("all")
public void writeLogEntriesExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLoggingServiceV2.addException(exception);
    try {
        LogNameOneof logName = LogNameOneof.from(LogName.create("[PROJECT]", "[LOG]"));
        MonitoredResource resource = MonitoredResource.newBuilder().build();
        Map<String, String> labels = new HashMap<>();
        List<LogEntry> entries = new ArrayList<>();
        client.writeLogEntries(logName, resource, labels, entries);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : LogNameOneof(com.google.logging.v2.LogNameOneof) HashMap(java.util.HashMap) StatusRuntimeException(io.grpc.StatusRuntimeException) ArrayList(java.util.ArrayList) MonitoredResource(com.google.api.MonitoredResource) LogEntry(com.google.logging.v2.LogEntry) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 34 with ApiException

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

the class MetricsClientTest method listLogMetricsExceptionTest.

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

Example 35 with ApiException

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

the class TraceServiceClientTest method getTraceExceptionTest.

@Test
@SuppressWarnings("all")
public void getTraceExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockTraceService.addException(exception);
    try {
        String projectId = "projectId-1969970175";
        String traceId = "traceId1270300245";
        client.getTrace(projectId, traceId);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) 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