Search in sources :

Example 51 with ApiException

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

the class LanguageServiceClientTest method analyzeEntitySentimentExceptionTest.

@Test
@SuppressWarnings("all")
public void analyzeEntitySentimentExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLanguageService.addException(exception);
    try {
        Document document = Document.newBuilder().build();
        EncodingType encodingType = EncodingType.NONE;
        client.analyzeEntitySentiment(document, encodingType);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) EncodingType(com.google.cloud.language.v1beta2.EncodingType) Document(com.google.cloud.language.v1beta2.Document) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 52 with ApiException

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

the class LanguageServiceClientTest method analyzeEntitiesExceptionTest.

@Test
@SuppressWarnings("all")
public void analyzeEntitiesExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLanguageService.addException(exception);
    try {
        Document document = Document.newBuilder().build();
        EncodingType encodingType = EncodingType.NONE;
        client.analyzeEntities(document, encodingType);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) EncodingType(com.google.cloud.language.v1.EncodingType) Document(com.google.cloud.language.v1.Document) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 53 with ApiException

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

the class LanguageServiceClientTest method annotateTextExceptionTest.

@Test
@SuppressWarnings("all")
public void annotateTextExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLanguageService.addException(exception);
    try {
        Document document = Document.newBuilder().build();
        AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
        EncodingType encodingType = EncodingType.NONE;
        client.annotateText(document, features, encodingType);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : AnnotateTextRequest(com.google.cloud.language.v1.AnnotateTextRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) EncodingType(com.google.cloud.language.v1.EncodingType) Document(com.google.cloud.language.v1.Document) Features(com.google.cloud.language.v1.AnnotateTextRequest.Features) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 54 with ApiException

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

the class ErrorGroupServiceClientTest method updateGroupExceptionTest.

@Test
@SuppressWarnings("all")
public void updateGroupExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockErrorGroupService.addException(exception);
    try {
        ErrorGroup group = ErrorGroup.newBuilder().build();
        client.updateGroup(group);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : ErrorGroup(com.google.devtools.clouderrorreporting.v1beta1.ErrorGroup) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 55 with ApiException

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

the class ErrorGroupServiceClientTest method getGroupExceptionTest.

@Test
@SuppressWarnings("all")
public void getGroupExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockErrorGroupService.addException(exception);
    try {
        GroupName groupName = GroupName.create("[PROJECT]", "[GROUP]");
        client.getGroup(groupName);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : GroupName(com.google.devtools.clouderrorreporting.v1beta1.GroupName) 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