Search in sources :

Example 1 with CreateBookRequest

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

Example 2 with CreateBookRequest

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

Example 3 with CreateBookRequest

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

Example 4 with CreateBookRequest

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

Aggregations

Book (com.google.example.library.v1.Book)4 CreateBookRequest (com.google.example.library.v1.CreateBookRequest)4 LibraryServiceClient (com.google.cloud.example.library.v1.LibraryServiceClient)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Test (org.junit.Test)2 ShelfName (com.google.example.library.v1.ShelfName)1