Search in sources :

Example 6 with ShelfName

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

the class LibraryServiceClientTest method createBookExceptionTest.

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

Example 7 with ShelfName

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

the class LibraryServiceClientTest method listBooksExceptionTest.

@Test
public void listBooksExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockLibraryService.addException(exception);
    try {
        ShelfName parent = ShelfName.of("[SHELF_ID]");
        client.listBooks(parent);
        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 8 with ShelfName

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

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

the class LibraryServiceClientTest method listBooksTest.

@Test
public void listBooksTest() throws Exception {
    Book responsesElement = Book.newBuilder().build();
    ListBooksResponse expectedResponse = ListBooksResponse.newBuilder().setNextPageToken("").addAllBooks(Arrays.asList(responsesElement)).build();
    mockLibraryService.addResponse(expectedResponse);
    ShelfName parent = ShelfName.of("[SHELF_ID]");
    ListBooksPagedResponse pagedListResponse = client.listBooks(parent);
    List<Book> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getBooksList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockLibraryService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListBooksRequest actualRequest = ((ListBooksRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Book(com.google.example.library.v1.Book) ListBooksResponse(com.google.example.library.v1.ListBooksResponse) ListBooksPagedResponse(com.google.cloud.example.library.v1.LibraryServiceClient.ListBooksPagedResponse) ListBooksRequest(com.google.example.library.v1.ListBooksRequest) ShelfName(com.google.example.library.v1.ShelfName) Test(org.junit.Test)

Example 10 with ShelfName

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

the class LibraryServiceClientTest method deleteShelfExceptionTest.

@Test
public void deleteShelfExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockLibraryService.addException(exception);
    try {
        ShelfName name = ShelfName.of("[SHELF_ID]");
        client.deleteShelf(name);
        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)

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