Search in sources :

Example 1 with ListBooksPagedResponse

use of com.google.cloud.example.library.v1.LibraryServiceClient.ListBooksPagedResponse 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 ListBooksPagedResponse

use of com.google.cloud.example.library.v1.LibraryServiceClient.ListBooksPagedResponse 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)

Aggregations

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