Search in sources :

Example 6 with BookName

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

the class SyncDeleteBookBookname method syncDeleteBookBookname.

public static void syncDeleteBookBookname() throws Exception {
    // It may require modifications to work in your environment.
    try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
        BookName name = BookName.of("[SHELF]", "[BOOK]");
        libraryServiceClient.deleteBook(name);
    }
}
Also used : LibraryServiceClient(com.google.cloud.example.library.v1.LibraryServiceClient) BookName(com.google.example.library.v1.BookName)

Example 7 with BookName

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

the class SyncGetBookBookname method syncGetBookBookname.

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

Example 8 with BookName

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

the class LibraryServiceClient method deleteBook.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Deletes a book. Returns NOT_FOUND if the book does not exist.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * // This snippet has been automatically generated for illustrative purposes only.
 * // It may require modifications to work in your environment.
 * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
 *   BookName name = BookName.of("[SHELF]", "[BOOK]");
 *   libraryServiceClient.deleteBook(name);
 * }
 * }</pre>
 *
 * @param name The name of the book to delete.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteBook(BookName name) {
    DeleteBookRequest request = DeleteBookRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteBook(request);
}
Also used : DeleteBookRequest(com.google.example.library.v1.DeleteBookRequest)

Example 9 with BookName

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

the class LibraryServiceClientTest method getBookExceptionTest.

@Test
public void getBookExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockLibraryService.addException(exception);
    try {
        BookName name = BookName.of("[SHELF]", "[BOOK]");
        client.getBook(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) BookName(com.google.example.library.v1.BookName) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 10 with BookName

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

the class LibraryServiceClientTest method deleteBookTest.

@Test
public void deleteBookTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockLibraryService.addResponse(expectedResponse);
    BookName name = BookName.of("[SHELF]", "[BOOK]");
    client.deleteBook(name);
    List<AbstractMessage> actualRequests = mockLibraryService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteBookRequest actualRequest = ((DeleteBookRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) BookName(com.google.example.library.v1.BookName) DeleteBookRequest(com.google.example.library.v1.DeleteBookRequest) Test(org.junit.Test)

Aggregations

BookName (com.google.example.library.v1.BookName)12 Test (org.junit.Test)8 Book (com.google.example.library.v1.Book)6 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)4 LibraryServiceClient (com.google.cloud.example.library.v1.LibraryServiceClient)4 AbstractMessage (com.google.protobuf.AbstractMessage)4 StatusRuntimeException (io.grpc.StatusRuntimeException)4 ShelfName (com.google.example.library.v1.ShelfName)3 DeleteBookRequest (com.google.example.library.v1.DeleteBookRequest)2 MoveBookRequest (com.google.example.library.v1.MoveBookRequest)2 GetBookRequest (com.google.example.library.v1.GetBookRequest)1 Empty (com.google.protobuf.Empty)1