Search in sources :

Example 1 with ListGlossariesPagedResponse

use of com.google.cloud.translate.v3.TranslationServiceClient.ListGlossariesPagedResponse in project google-cloud-java by GoogleCloudPlatform.

the class TranslateSnippetsBeta method listGlossary.

// [END translate_create_glossary_beta]
/**
 * Lists all the glossaries for a given project.
 *
 * @param projectId - Id of the project.
 * @param location - location name.
 * @param filter - criteria for listing glossaries.
 */
// [START translate_list_glossary_beta]
static ListGlossariesPagedResponse listGlossary(String projectId, String location, String filter) {
    try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
        LocationName locationName = LocationName.newBuilder().setProject(projectId).setLocation(location).build();
        ListGlossariesPagedResponse response = translationServiceClient.listGlossaries(locationName.toString(), filter);
        // Call the API
        for (Glossary element : response.iterateAll()) {
            System.out.format("Name: %s\n", element.getName());
            System.out.format("Language Codes Set:\n");
            System.out.format("Source Language Code: %s\n", element.getLanguageCodesSet().getLanguageCodesList().get(0));
            System.out.format("Target Language Code: %s\n", element.getLanguageCodesSet().getLanguageCodesList().get(1));
            System.out.format("Input Uri: %s\n", element.getInputConfig().getGcsSource());
        }
        return response;
    } catch (Exception e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : TranslationServiceClient(com.google.cloud.translate.v3beta1.TranslationServiceClient) Glossary(com.google.cloud.translate.v3beta1.Glossary) ListGlossariesPagedResponse(com.google.cloud.translate.v3beta1.TranslationServiceClient.ListGlossariesPagedResponse) LocationName(com.google.cloud.translate.v3beta1.LocationName)

Example 2 with ListGlossariesPagedResponse

use of com.google.cloud.translate.v3.TranslationServiceClient.ListGlossariesPagedResponse in project java-translate by googleapis.

the class TranslationServiceClientTest method listGlossariesTest2.

@Test
public void listGlossariesTest2() throws Exception {
    Glossary responsesElement = Glossary.newBuilder().build();
    ListGlossariesResponse expectedResponse = ListGlossariesResponse.newBuilder().setNextPageToken("").addAllGlossaries(Arrays.asList(responsesElement)).build();
    mockTranslationService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListGlossariesPagedResponse pagedListResponse = client.listGlossaries(parent);
    List<Glossary> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getGlossariesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockTranslationService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListGlossariesRequest actualRequest = ((ListGlossariesRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListGlossariesPagedResponse(com.google.cloud.translate.v3.TranslationServiceClient.ListGlossariesPagedResponse) Test(org.junit.Test)

Example 3 with ListGlossariesPagedResponse

use of com.google.cloud.translate.v3.TranslationServiceClient.ListGlossariesPagedResponse in project java-translate by googleapis.

the class TranslationServiceClientTest method listGlossariesTest.

@Test
public void listGlossariesTest() throws Exception {
    Glossary responsesElement = Glossary.newBuilder().build();
    ListGlossariesResponse expectedResponse = ListGlossariesResponse.newBuilder().setNextPageToken("").addAllGlossaries(Arrays.asList(responsesElement)).build();
    mockTranslationService.addResponse(expectedResponse);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    String filter = "filter-1274492040";
    ListGlossariesPagedResponse pagedListResponse = client.listGlossaries(parent, filter);
    List<Glossary> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getGlossariesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockTranslationService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListGlossariesRequest actualRequest = ((ListGlossariesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(filter, actualRequest.getFilter());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListGlossariesPagedResponse(com.google.cloud.translate.v3beta1.TranslationServiceClient.ListGlossariesPagedResponse) Test(org.junit.Test)

Example 4 with ListGlossariesPagedResponse

use of com.google.cloud.translate.v3.TranslationServiceClient.ListGlossariesPagedResponse in project java-translate by googleapis.

the class TranslationServiceClientTest method listGlossariesTest2.

@Test
public void listGlossariesTest2() throws Exception {
    Glossary responsesElement = Glossary.newBuilder().build();
    ListGlossariesResponse expectedResponse = ListGlossariesResponse.newBuilder().setNextPageToken("").addAllGlossaries(Arrays.asList(responsesElement)).build();
    mockTranslationService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    String filter = "filter-1274492040";
    ListGlossariesPagedResponse pagedListResponse = client.listGlossaries(parent, filter);
    List<Glossary> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getGlossariesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockTranslationService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListGlossariesRequest actualRequest = ((ListGlossariesRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertEquals(filter, actualRequest.getFilter());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListGlossariesPagedResponse(com.google.cloud.translate.v3beta1.TranslationServiceClient.ListGlossariesPagedResponse) Test(org.junit.Test)

Example 5 with ListGlossariesPagedResponse

use of com.google.cloud.translate.v3.TranslationServiceClient.ListGlossariesPagedResponse in project java-translate by googleapis.

the class TranslationServiceClientTest method listGlossariesTest.

@Test
public void listGlossariesTest() throws Exception {
    Glossary responsesElement = Glossary.newBuilder().build();
    ListGlossariesResponse expectedResponse = ListGlossariesResponse.newBuilder().setNextPageToken("").addAllGlossaries(Arrays.asList(responsesElement)).build();
    mockTranslationService.addResponse(expectedResponse);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    ListGlossariesPagedResponse pagedListResponse = client.listGlossaries(parent);
    List<Glossary> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getGlossariesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockTranslationService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListGlossariesRequest actualRequest = ((ListGlossariesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListGlossariesPagedResponse(com.google.cloud.translate.v3.TranslationServiceClient.ListGlossariesPagedResponse) Test(org.junit.Test)

Aggregations

ListGlossariesPagedResponse (com.google.cloud.translate.v3beta1.TranslationServiceClient.ListGlossariesPagedResponse)4 AbstractMessage (com.google.protobuf.AbstractMessage)4 Test (org.junit.Test)4 ListGlossariesPagedResponse (com.google.cloud.translate.v3.TranslationServiceClient.ListGlossariesPagedResponse)2 Glossary (com.google.cloud.translate.v3beta1.Glossary)2 LocationName (com.google.cloud.translate.v3beta1.LocationName)2 TranslationServiceClient (com.google.cloud.translate.v3beta1.TranslationServiceClient)2