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()));
}
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());
}
}
}
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()));
}
Aggregations