Search in sources :

Example 1 with ListGlossariesRequest

use of com.google.cloud.translate.v3.ListGlossariesRequest 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 2 with ListGlossariesRequest

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

the class ListGlossaries method listGlossaries.

// List all the glossaries in a specified location
public static void listGlossaries(String projectId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (TranslationServiceClient client = TranslationServiceClient.create()) {
        // Supported Locations: `global`, [glossary location], or [model location]
        // Glossaries must be hosted in `us-central1`
        // Custom Models must use the same location as your model. (us-central1)
        LocationName parent = LocationName.of(projectId, "us-central1");
        ListGlossariesRequest request = ListGlossariesRequest.newBuilder().setParent(parent.toString()).build();
        for (Glossary responseItem : client.listGlossaries(request).iterateAll()) {
            System.out.printf("Glossary name: %s\n", responseItem.getName());
            System.out.printf("Entry count: %s\n", responseItem.getEntryCount());
            System.out.printf("Input URI: %s\n", responseItem.getInputConfig().getGcsSource().getInputUri());
        }
    }
}
Also used : TranslationServiceClient(com.google.cloud.translate.v3.TranslationServiceClient) Glossary(com.google.cloud.translate.v3.Glossary) LocationName(com.google.cloud.translate.v3.LocationName) ListGlossariesRequest(com.google.cloud.translate.v3.ListGlossariesRequest)

Example 3 with ListGlossariesRequest

use of com.google.cloud.translate.v3.ListGlossariesRequest 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.v3.TranslationServiceClient.ListGlossariesPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Test (org.junit.Test)2 Glossary (com.google.cloud.translate.v3.Glossary)1 ListGlossariesRequest (com.google.cloud.translate.v3.ListGlossariesRequest)1 LocationName (com.google.cloud.translate.v3.LocationName)1 TranslationServiceClient (com.google.cloud.translate.v3.TranslationServiceClient)1