Search in sources :

Example 6 with Book

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()));
}
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 7 with Book

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.
    }
}
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 8 with Book

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.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) Book(com.google.example.library.v1.Book) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 9 with Book

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()));
}
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 Book

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.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) Book(com.google.example.library.v1.Book) StatusRuntimeException(io.grpc.StatusRuntimeException) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Aggregations

Book (com.google.example.library.v1.Book)33 Test (org.junit.Test)25 LibraryServiceClient (com.google.cloud.example.library.v1.LibraryServiceClient)22 Book (student_arturs_melnikovs.lesson_10.level_02.Book)16 BookName (com.google.example.library.v1.BookName)12 AbstractMessage (com.google.protobuf.AbstractMessage)12 ShelfName (com.google.example.library.v1.ShelfName)9 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)7 StatusRuntimeException (io.grpc.StatusRuntimeException)7 MoveBookRequest (com.google.example.library.v1.MoveBookRequest)6 DeleteBookRequest (com.google.example.library.v1.DeleteBookRequest)5 Scanner (java.util.Scanner)5 CreateBookRequest (com.google.example.library.v1.CreateBookRequest)4 GetBookRequest (com.google.example.library.v1.GetBookRequest)4 Page (org.apache.wicket.Page)4 Book (org.apache.wicket.core.util.tester.apps_1.Book)4 WebPage (org.apache.wicket.markup.html.WebPage)4 AccessDeniedPage (org.apache.wicket.markup.html.pages.AccessDeniedPage)4 DummyPage (org.apache.wicket.resource.DummyPage)4 Book (org.apache.wicket.util.tester.apps_1.Book)4