Search in sources :

Example 1 with ListShelvesResponse

use of com.google.example.library.v1.ListShelvesResponse in project gapic-generator-java by googleapis.

the class AsyncListShelvesPaged method asyncListShelvesPaged.

public static void asyncListShelvesPaged() throws Exception {
    // It may require modifications to work in your environment.
    try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
        ListShelvesRequest request = ListShelvesRequest.newBuilder().setPageSize(883849137).setPageToken("pageToken873572522").build();
        while (true) {
            ListShelvesResponse response = libraryServiceClient.listShelvesCallable().call(request);
            for (Shelf 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) Shelf(com.google.example.library.v1.Shelf) ListShelvesResponse(com.google.example.library.v1.ListShelvesResponse) ListShelvesRequest(com.google.example.library.v1.ListShelvesRequest)

Example 2 with ListShelvesResponse

use of com.google.example.library.v1.ListShelvesResponse in project gapic-generator-java by googleapis.

the class LibraryServiceClientTest method listShelvesTest.

@Test
public void listShelvesTest() throws Exception {
    Shelf responsesElement = Shelf.newBuilder().build();
    ListShelvesResponse expectedResponse = ListShelvesResponse.newBuilder().setNextPageToken("").addAllShelves(Arrays.asList(responsesElement)).build();
    mockLibraryService.addResponse(expectedResponse);
    ListShelvesRequest request = ListShelvesRequest.newBuilder().setPageSize(883849137).setPageToken("pageToken873572522").build();
    ListShelvesPagedResponse pagedListResponse = client.listShelves(request);
    List<Shelf> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getShelvesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockLibraryService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListShelvesRequest actualRequest = ((ListShelvesRequest) actualRequests.get(0));
    Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize());
    Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Shelf(com.google.example.library.v1.Shelf) ListShelvesResponse(com.google.example.library.v1.ListShelvesResponse) ListShelvesRequest(com.google.example.library.v1.ListShelvesRequest) ListShelvesPagedResponse(com.google.cloud.example.library.v1.LibraryServiceClient.ListShelvesPagedResponse) Test(org.junit.Test)

Aggregations

ListShelvesRequest (com.google.example.library.v1.ListShelvesRequest)2 ListShelvesResponse (com.google.example.library.v1.ListShelvesResponse)2 Shelf (com.google.example.library.v1.Shelf)2 LibraryServiceClient (com.google.cloud.example.library.v1.LibraryServiceClient)1 ListShelvesPagedResponse (com.google.cloud.example.library.v1.LibraryServiceClient.ListShelvesPagedResponse)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 Test (org.junit.Test)1