Search in sources :

Example 1 with ShelfName

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

the class LibraryServiceClient method deleteShelf.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Deletes a shelf. Returns NOT_FOUND if the shelf 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()) {
 *   ShelfName name = ShelfName.of("[SHELF_ID]");
 *   libraryServiceClient.deleteShelf(name);
 * }
 * }</pre>
 *
 * @param name The name of the shelf to delete.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteShelf(ShelfName name) {
    DeleteShelfRequest request = DeleteShelfRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteShelf(request);
}
Also used : DeleteShelfRequest(com.google.example.library.v1.DeleteShelfRequest)

Example 2 with ShelfName

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

the class LibraryServiceClientTest method mergeShelvesExceptionTest.

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

Example 3 with ShelfName

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

the class LibraryServiceClientTest method moveBookExceptionTest3.

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

Example 4 with ShelfName

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

the class LibraryServiceClientTest method moveBookTest.

@Test
public void moveBookTest() 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]");
    ShelfName otherShelfName = ShelfName.of("[SHELF_ID]");
    Book actualResponse = client.moveBook(name, otherShelfName);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockLibraryService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    MoveBookRequest actualRequest = ((MoveBookRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(otherShelfName.toString(), actualRequest.getOtherShelfName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : MoveBookRequest(com.google.example.library.v1.MoveBookRequest) AbstractMessage(com.google.protobuf.AbstractMessage) Book(com.google.example.library.v1.Book) BookName(com.google.example.library.v1.BookName) ShelfName(com.google.example.library.v1.ShelfName) Test(org.junit.Test)

Example 5 with ShelfName

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

the class LibraryServiceClientTest method moveBookExceptionTest.

@Test
public void moveBookExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockLibraryService.addException(exception);
    try {
        BookName name = BookName.of("[SHELF]", "[BOOK]");
        ShelfName otherShelfName = ShelfName.of("[SHELF_ID]");
        client.moveBook(name, otherShelfName);
        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) ShelfName(com.google.example.library.v1.ShelfName) Test(org.junit.Test)

Aggregations

ShelfName (com.google.example.library.v1.ShelfName)26 Test (org.junit.Test)18 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)9 AbstractMessage (com.google.protobuf.AbstractMessage)9 StatusRuntimeException (io.grpc.StatusRuntimeException)9 LibraryServiceClient (com.google.cloud.example.library.v1.LibraryServiceClient)8 Book (com.google.example.library.v1.Book)8 Shelf (com.google.example.library.v1.Shelf)8 BookName (com.google.example.library.v1.BookName)3 MergeShelvesRequest (com.google.example.library.v1.MergeShelvesRequest)3 DeleteShelfRequest (com.google.example.library.v1.DeleteShelfRequest)2 MoveBookRequest (com.google.example.library.v1.MoveBookRequest)2 ListBooksPagedResponse (com.google.cloud.example.library.v1.LibraryServiceClient.ListBooksPagedResponse)1 CreateBookRequest (com.google.example.library.v1.CreateBookRequest)1 GetShelfRequest (com.google.example.library.v1.GetShelfRequest)1 ListBooksRequest (com.google.example.library.v1.ListBooksRequest)1 ListBooksResponse (com.google.example.library.v1.ListBooksResponse)1 Empty (com.google.protobuf.Empty)1