Search in sources :

Example 1 with GetBookRequest

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

the class AsyncGetBook method asyncGetBook.

public static void asyncGetBook() throws Exception {
    // It may require modifications to work in your environment.
    try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
        GetBookRequest request = GetBookRequest.newBuilder().setName(BookName.of("[SHELF]", "[BOOK]").toString()).build();
        ApiFuture<Book> future = libraryServiceClient.getBookCallable().futureCall(request);
        // Do something.
        Book response = future.get();
    }
}
Also used : GetBookRequest(com.google.example.library.v1.GetBookRequest) LibraryServiceClient(com.google.cloud.example.library.v1.LibraryServiceClient) Book(com.google.example.library.v1.Book)

Example 2 with GetBookRequest

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

the class SyncGetBook method syncGetBook.

public static void syncGetBook() throws Exception {
    // It may require modifications to work in your environment.
    try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
        GetBookRequest request = GetBookRequest.newBuilder().setName(BookName.of("[SHELF]", "[BOOK]").toString()).build();
        Book response = libraryServiceClient.getBook(request);
    }
}
Also used : GetBookRequest(com.google.example.library.v1.GetBookRequest) LibraryServiceClient(com.google.cloud.example.library.v1.LibraryServiceClient) Book(com.google.example.library.v1.Book)

Example 3 with GetBookRequest

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

the class LibraryServiceClientTest method getBookTest2.

@Test
public void getBookTest2() throws Exception {
    Book expectedResponse = Book.newBuilder().setName(BookName.of("[SHELF]", "[BOOK]").toString()).setAuthor("author-1406328437").setTitle("title110371416").setRead(true).build();
    mockLibraryService.addResponse(expectedResponse);
    String name = "name3373707";
    Book actualResponse = client.getBook(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockLibraryService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetBookRequest actualRequest = ((GetBookRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : GetBookRequest(com.google.example.library.v1.GetBookRequest) AbstractMessage(com.google.protobuf.AbstractMessage) Book(com.google.example.library.v1.Book) Test(org.junit.Test)

Example 4 with GetBookRequest

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

the class LibraryServiceClientTest method getBookTest.

@Test
public void getBookTest() throws Exception {
    Book expectedResponse = Book.newBuilder().setName(BookName.of("[SHELF]", "[BOOK]").toString()).setAuthor("author-1406328437").setTitle("title110371416").setRead(true).build();
    mockLibraryService.addResponse(expectedResponse);
    BookName name = BookName.of("[SHELF]", "[BOOK]");
    Book actualResponse = client.getBook(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockLibraryService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetBookRequest actualRequest = ((GetBookRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : GetBookRequest(com.google.example.library.v1.GetBookRequest) AbstractMessage(com.google.protobuf.AbstractMessage) Book(com.google.example.library.v1.Book) BookName(com.google.example.library.v1.BookName) Test(org.junit.Test)

Aggregations

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