Search in sources :

Example 36 with Shelf

use of com.google.example.library.v1.Shelf 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 37 with Shelf

use of com.google.example.library.v1.Shelf 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()) {
 *   String name = BookName.of("[SHELF]", "[BOOK]").toString();
 *   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(String name) {
    DeleteBookRequest request = DeleteBookRequest.newBuilder().setName(name).build();
    deleteBook(request);
}
Also used : DeleteBookRequest(com.google.example.library.v1.DeleteBookRequest)

Example 38 with Shelf

use of com.google.example.library.v1.Shelf 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 39 with Shelf

use of com.google.example.library.v1.Shelf 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 40 with Shelf

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

the class LibraryServiceClientTest method listShelvesTest.

@Test
public void listShelvesTest() throws Exception {
    Shelf responsesElement = Shelf.newBuilder().build();
    ListShelvesResponse expectedResponse = ListShelvesResponse.newBuilder().setNextPageToken("").addAllShelves(Arrays.asList(responsesElement)).build();
    mockLibraryService.addResponse(expectedResponse);
    ListShelvesRequest request = ListShelvesRequest.newBuilder().setPageSize(883849137).setPageToken("pageToken873572522").build();
    ListShelvesPagedResponse pagedListResponse = client.listShelves(request);
    List<Shelf> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getShelvesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockLibraryService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListShelvesRequest actualRequest = ((ListShelvesRequest) actualRequests.get(0));
    Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize());
    Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Shelf(com.google.example.library.v1.Shelf) ListShelvesResponse(com.google.example.library.v1.ListShelvesResponse) ListShelvesRequest(com.google.example.library.v1.ListShelvesRequest) ListShelvesPagedResponse(com.google.cloud.example.library.v1.LibraryServiceClient.ListShelvesPagedResponse) Test(org.junit.Test)

Aggregations

LibraryServiceClient (com.google.cloud.example.library.v1.LibraryServiceClient)27 Shelf (com.google.example.library.v1.Shelf)23 Test (org.junit.Test)23 Book (com.google.example.library.v1.Book)19 AbstractMessage (com.google.protobuf.AbstractMessage)18 ShelfName (com.google.example.library.v1.ShelfName)14 BookName (com.google.example.library.v1.BookName)12 MergeShelvesRequest (com.google.example.library.v1.MergeShelvesRequest)6 MoveBookRequest (com.google.example.library.v1.MoveBookRequest)6 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)5 DeleteBookRequest (com.google.example.library.v1.DeleteBookRequest)5 StatusRuntimeException (io.grpc.StatusRuntimeException)5 GetBookRequest (com.google.example.library.v1.GetBookRequest)4 GetShelfRequest (com.google.example.library.v1.GetShelfRequest)4 ListShelvesRequest (com.google.example.library.v1.ListShelvesRequest)3 CreateBookRequest (com.google.example.library.v1.CreateBookRequest)2 CreateShelfRequest (com.google.example.library.v1.CreateShelfRequest)2 DeleteShelfRequest (com.google.example.library.v1.DeleteShelfRequest)2 ListShelvesResponse (com.google.example.library.v1.ListShelvesResponse)2 Empty (com.google.protobuf.Empty)2