Search in sources :

Example 6 with EncodingType

use of com.google.cloud.language.v1beta2.EncodingType 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.v1beta2.EncodingType) Document(com.google.cloud.language.v1beta2.Document) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 7 with EncodingType

use of com.google.cloud.language.v1beta2.EncodingType in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method analyzeSyntaxExceptionTest.

@Test
@SuppressWarnings("all")
public void analyzeSyntaxExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLanguageService.addException(exception);
    try {
        Document document = Document.newBuilder().build();
        EncodingType encodingType = EncodingType.NONE;
        client.analyzeSyntax(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 8 with EncodingType

use of com.google.cloud.language.v1beta2.EncodingType in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method analyzeEntitiesTest.

@Test
@SuppressWarnings("all")
public void analyzeEntitiesTest() {
    String language = "language-1613589672";
    AnalyzeEntitiesResponse expectedResponse = AnalyzeEntitiesResponse.newBuilder().setLanguage(language).build();
    mockLanguageService.addResponse(expectedResponse);
    Document document = Document.newBuilder().build();
    EncodingType encodingType = EncodingType.NONE;
    AnalyzeEntitiesResponse actualResponse = client.analyzeEntities(document, encodingType);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockLanguageService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    AnalyzeEntitiesRequest actualRequest = (AnalyzeEntitiesRequest) actualRequests.get(0);
    Assert.assertEquals(document, actualRequest.getDocument());
    Assert.assertEquals(encodingType, actualRequest.getEncodingType());
}
Also used : AnalyzeEntitiesRequest(com.google.cloud.language.v1.AnalyzeEntitiesRequest) AnalyzeEntitiesResponse(com.google.cloud.language.v1.AnalyzeEntitiesResponse) EncodingType(com.google.cloud.language.v1.EncodingType) Document(com.google.cloud.language.v1.Document) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 9 with EncodingType

use of com.google.cloud.language.v1beta2.EncodingType in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method annotateTextTest.

@Test
@SuppressWarnings("all")
public void annotateTextTest() {
    String language = "language-1613589672";
    AnnotateTextResponse expectedResponse = AnnotateTextResponse.newBuilder().setLanguage(language).build();
    mockLanguageService.addResponse(expectedResponse);
    Document document = Document.newBuilder().build();
    AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
    EncodingType encodingType = EncodingType.NONE;
    AnnotateTextResponse actualResponse = client.annotateText(document, features, encodingType);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockLanguageService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    AnnotateTextRequest actualRequest = (AnnotateTextRequest) actualRequests.get(0);
    Assert.assertEquals(document, actualRequest.getDocument());
    Assert.assertEquals(features, actualRequest.getFeatures());
    Assert.assertEquals(encodingType, actualRequest.getEncodingType());
}
Also used : AnnotateTextRequest(com.google.cloud.language.v1.AnnotateTextRequest) EncodingType(com.google.cloud.language.v1.EncodingType) AnnotateTextResponse(com.google.cloud.language.v1.AnnotateTextResponse) Document(com.google.cloud.language.v1.Document) Features(com.google.cloud.language.v1.AnnotateTextRequest.Features) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 10 with EncodingType

use of com.google.cloud.language.v1beta2.EncodingType in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method analyzeEntitySentimentTest.

@Test
@SuppressWarnings("all")
public void analyzeEntitySentimentTest() {
    String language = "language-1613589672";
    AnalyzeEntitySentimentResponse expectedResponse = AnalyzeEntitySentimentResponse.newBuilder().setLanguage(language).build();
    mockLanguageService.addResponse(expectedResponse);
    Document document = Document.newBuilder().build();
    EncodingType encodingType = EncodingType.NONE;
    AnalyzeEntitySentimentResponse actualResponse = client.analyzeEntitySentiment(document, encodingType);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockLanguageService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    AnalyzeEntitySentimentRequest actualRequest = (AnalyzeEntitySentimentRequest) actualRequests.get(0);
    Assert.assertEquals(document, actualRequest.getDocument());
    Assert.assertEquals(encodingType, actualRequest.getEncodingType());
}
Also used : AnalyzeEntitySentimentRequest(com.google.cloud.language.v1beta2.AnalyzeEntitySentimentRequest) EncodingType(com.google.cloud.language.v1beta2.EncodingType) Document(com.google.cloud.language.v1beta2.Document) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) AnalyzeEntitySentimentResponse(com.google.cloud.language.v1beta2.AnalyzeEntitySentimentResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 Document (com.google.cloud.language.v1beta2.Document)8 EncodingType (com.google.cloud.language.v1beta2.EncodingType)8 ApiException (com.google.api.gax.grpc.ApiException)7 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)7 StatusRuntimeException (io.grpc.StatusRuntimeException)7 Document (com.google.cloud.language.v1.Document)6 EncodingType (com.google.cloud.language.v1.EncodingType)6 AnnotateTextRequest (com.google.cloud.language.v1.AnnotateTextRequest)2 Features (com.google.cloud.language.v1.AnnotateTextRequest.Features)2 AnnotateTextRequest (com.google.cloud.language.v1beta2.AnnotateTextRequest)2 Features (com.google.cloud.language.v1beta2.AnnotateTextRequest.Features)2 AnalyzeEntitiesRequest (com.google.cloud.language.v1.AnalyzeEntitiesRequest)1 AnalyzeEntitiesResponse (com.google.cloud.language.v1.AnalyzeEntitiesResponse)1 AnalyzeSyntaxRequest (com.google.cloud.language.v1.AnalyzeSyntaxRequest)1 AnalyzeSyntaxResponse (com.google.cloud.language.v1.AnalyzeSyntaxResponse)1 AnnotateTextResponse (com.google.cloud.language.v1.AnnotateTextResponse)1 AnalyzeEntitiesRequest (com.google.cloud.language.v1beta2.AnalyzeEntitiesRequest)1 AnalyzeEntitiesResponse (com.google.cloud.language.v1beta2.AnalyzeEntitiesResponse)1 AnalyzeEntitySentimentRequest (com.google.cloud.language.v1beta2.AnalyzeEntitySentimentRequest)1