use of com.google.example.library.v1.CreateBookRequest in project gapic-generator-java by googleapis.
the class AsyncCreateBook method asyncCreateBook.
public static void asyncCreateBook() throws Exception {
// It may require modifications to work in your environment.
try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
CreateBookRequest request = CreateBookRequest.newBuilder().setParent(ShelfName.of("[SHELF_ID]").toString()).setBook(Book.newBuilder().build()).build();
ApiFuture<Book> future = libraryServiceClient.createBookCallable().futureCall(request);
// Do something.
Book response = future.get();
}
}
use of com.google.example.library.v1.CreateBookRequest in project gapic-generator-java by googleapis.
the class SyncCreateBook method syncCreateBook.
public static void syncCreateBook() throws Exception {
// It may require modifications to work in your environment.
try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
CreateBookRequest request = CreateBookRequest.newBuilder().setParent(ShelfName.of("[SHELF_ID]").toString()).setBook(Book.newBuilder().build()).build();
Book response = libraryServiceClient.createBook(request);
}
}
use of com.google.example.library.v1.CreateBookRequest in project gapic-generator-java by googleapis.
the class LibraryServiceClientTest method createBookTest.
@Test
public void createBookTest() throws Exception {
Book expectedResponse = Book.newBuilder().setName(BookName.of("[SHELF]", "[BOOK]").toString()).setAuthor("author-1406328437").setTitle("title110371416").setRead(true).build();
mockLibraryService.addResponse(expectedResponse);
ShelfName parent = ShelfName.of("[SHELF_ID]");
Book book = Book.newBuilder().build();
Book actualResponse = client.createBook(parent, book);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockLibraryService.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateBookRequest actualRequest = ((CreateBookRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(book, actualRequest.getBook());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.example.library.v1.CreateBookRequest in project gapic-generator-java by googleapis.
the class LibraryServiceClientTest method createBookTest2.
@Test
public void createBookTest2() throws Exception {
Book expectedResponse = Book.newBuilder().setName(BookName.of("[SHELF]", "[BOOK]").toString()).setAuthor("author-1406328437").setTitle("title110371416").setRead(true).build();
mockLibraryService.addResponse(expectedResponse);
String parent = "parent-995424086";
Book book = Book.newBuilder().build();
Book actualResponse = client.createBook(parent, book);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockLibraryService.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateBookRequest actualRequest = ((CreateBookRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertEquals(book, actualRequest.getBook());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations