use of com.google.example.library.v1.Book 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()));
}
use of com.google.example.library.v1.Book 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.
}
}
use of com.google.example.library.v1.Book in project gapic-generator-java by googleapis.
the class LibraryServiceClientTest method createBookExceptionTest2.
@Test
public void createBookExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockLibraryService.addException(exception);
try {
String parent = "parent-995424086";
Book book = Book.newBuilder().build();
client.createBook(parent, book);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.example.library.v1.Book 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()));
}
use of com.google.example.library.v1.Book in project gapic-generator-java by googleapis.
the class LibraryServiceClientTest method updateBookExceptionTest.
@Test
public void updateBookExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockLibraryService.addException(exception);
try {
Book book = Book.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
client.updateBook(book, updateMask);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
Aggregations