use of com.google.example.library.v1.ListBooksResponse in project gapic-generator-java by googleapis.
the class LibraryServiceClientTest method listBooksTest2.
@Test
public void listBooksTest2() throws Exception {
Book responsesElement = Book.newBuilder().build();
ListBooksResponse expectedResponse = ListBooksResponse.newBuilder().setNextPageToken("").addAllBooks(Arrays.asList(responsesElement)).build();
mockLibraryService.addResponse(expectedResponse);
String parent = "parent-995424086";
ListBooksPagedResponse pagedListResponse = client.listBooks(parent);
List<Book> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getBooksList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockLibraryService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListBooksRequest actualRequest = ((ListBooksRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.example.library.v1.ListBooksResponse in project gapic-generator-java by googleapis.
the class LibraryServiceClientTest method listBooksTest.
@Test
public void listBooksTest() throws Exception {
Book responsesElement = Book.newBuilder().build();
ListBooksResponse expectedResponse = ListBooksResponse.newBuilder().setNextPageToken("").addAllBooks(Arrays.asList(responsesElement)).build();
mockLibraryService.addResponse(expectedResponse);
ShelfName parent = ShelfName.of("[SHELF_ID]");
ListBooksPagedResponse pagedListResponse = client.listBooks(parent);
List<Book> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getBooksList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockLibraryService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListBooksRequest actualRequest = ((ListBooksRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.example.library.v1.ListBooksResponse in project gapic-generator-java by googleapis.
the class AsyncListBooksPaged method asyncListBooksPaged.
public static void asyncListBooksPaged() throws Exception {
// It may require modifications to work in your environment.
try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
ListBooksRequest request = ListBooksRequest.newBuilder().setParent(ShelfName.of("[SHELF_ID]").toString()).setPageSize(883849137).setPageToken("pageToken873572522").build();
while (true) {
ListBooksResponse response = libraryServiceClient.listBooksCallable().call(request);
for (Book element : response.getResponsesList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
}
Aggregations