Search in sources :

Example 1 with ListBooksResponse

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Book(com.google.example.library.v1.Book) ListBooksResponse(com.google.example.library.v1.ListBooksResponse) ListBooksPagedResponse(com.google.cloud.example.library.v1.LibraryServiceClient.ListBooksPagedResponse) ListBooksRequest(com.google.example.library.v1.ListBooksRequest) Test(org.junit.Test)

Example 2 with ListBooksResponse

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Book(com.google.example.library.v1.Book) ListBooksResponse(com.google.example.library.v1.ListBooksResponse) ListBooksPagedResponse(com.google.cloud.example.library.v1.LibraryServiceClient.ListBooksPagedResponse) ListBooksRequest(com.google.example.library.v1.ListBooksRequest) ShelfName(com.google.example.library.v1.ShelfName) Test(org.junit.Test)

Example 3 with ListBooksResponse

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;
            }
        }
    }
}
Also used : LibraryServiceClient(com.google.cloud.example.library.v1.LibraryServiceClient) ListBooksResponse(com.google.example.library.v1.ListBooksResponse) Book(com.google.example.library.v1.Book) ListBooksRequest(com.google.example.library.v1.ListBooksRequest)

Aggregations

Book (com.google.example.library.v1.Book)3 ListBooksRequest (com.google.example.library.v1.ListBooksRequest)3 ListBooksResponse (com.google.example.library.v1.ListBooksResponse)3 ListBooksPagedResponse (com.google.cloud.example.library.v1.LibraryServiceClient.ListBooksPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Test (org.junit.Test)2 LibraryServiceClient (com.google.cloud.example.library.v1.LibraryServiceClient)1 ShelfName (com.google.example.library.v1.ShelfName)1