Search in sources :

Example 1 with ListShelvesRequest

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

the class LibraryServiceClientTest method listShelvesExceptionTest.

@Test
public void listShelvesExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockLibraryService.addException(exception);
    try {
        ListShelvesRequest request = ListShelvesRequest.newBuilder().setPageSize(883849137).setPageToken("pageToken873572522").build();
        client.listShelves(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) ListShelvesRequest(com.google.example.library.v1.ListShelvesRequest) Test(org.junit.Test)

Example 2 with ListShelvesRequest

use of com.google.example.library.v1.ListShelvesRequest 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 3 with ListShelvesRequest

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

the class AsyncListShelves method asyncListShelves.

public static void asyncListShelves() 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();
        ApiFuture<Shelf> future = libraryServiceClient.listShelvesPagedCallable().futureCall(request);
        // Do something.
        for (Shelf element : future.get().iterateAll()) {
        // doThingsWith(element);
        }
    }
}
Also used : LibraryServiceClient(com.google.cloud.example.library.v1.LibraryServiceClient) Shelf(com.google.example.library.v1.Shelf) ListShelvesRequest(com.google.example.library.v1.ListShelvesRequest)

Example 4 with ListShelvesRequest

use of com.google.example.library.v1.ListShelvesRequest 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)4 Shelf (com.google.example.library.v1.Shelf)3 LibraryServiceClient (com.google.cloud.example.library.v1.LibraryServiceClient)2 ListShelvesResponse (com.google.example.library.v1.ListShelvesResponse)2 Test (org.junit.Test)2 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 ListShelvesPagedResponse (com.google.cloud.example.library.v1.LibraryServiceClient.ListShelvesPagedResponse)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1