Search in sources :

Example 6 with Shelf

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

Example 7 with Shelf

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

the class LibraryServiceClientTest method moveBookTest2.

@Test
public void moveBookTest2() 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]");
    String otherShelfName = "otherShelfName-1942963547";
    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, 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) Test(org.junit.Test)

Example 8 with Shelf

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

the class LibraryServiceClientTest method mergeShelvesTest2.

@Test
public void mergeShelvesTest2() throws Exception {
    Shelf expectedResponse = Shelf.newBuilder().setName(ShelfName.of("[SHELF_ID]").toString()).setTheme("theme110327241").build();
    mockLibraryService.addResponse(expectedResponse);
    ShelfName name = ShelfName.of("[SHELF_ID]");
    String otherShelf = "otherShelf-193668870";
    Shelf actualResponse = client.mergeShelves(name, otherShelf);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockLibraryService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    MergeShelvesRequest actualRequest = ((MergeShelvesRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(otherShelf, actualRequest.getOtherShelf());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Shelf(com.google.example.library.v1.Shelf) ShelfName(com.google.example.library.v1.ShelfName) MergeShelvesRequest(com.google.example.library.v1.MergeShelvesRequest) Test(org.junit.Test)

Example 9 with Shelf

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

the class SyncMoveBookBooknameShelfname method syncMoveBookBooknameShelfname.

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

Example 10 with Shelf

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

the class SyncMoveBookBooknameString method syncMoveBookBooknameString.

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

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