From 40b402574baa85ad952e5d7bbd9cf7e068b38b4e Mon Sep 17 00:00:00 2001 From: Ernest Landrito Date: Fri, 12 May 2017 15:51:59 -0700 Subject: [PATCH] Ruby: Allow doc gapic generation to generate tests. --- .../gapic/MainGapicProviderFactory.java | 2 +- .../ruby_doc_smoke_test_library.baseline | 41 + .../testdata/ruby_doc_test_library.baseline | 2023 +++++++++++++++++ 3 files changed, 2065 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/google/api/codegen/testdata/ruby_doc_smoke_test_library.baseline create mode 100644 src/test/java/com/google/api/codegen/testdata/ruby_doc_test_library.baseline diff --git a/src/main/java/com/google/api/codegen/gapic/MainGapicProviderFactory.java b/src/main/java/com/google/api/codegen/gapic/MainGapicProviderFactory.java index d22eed6b83..92e072a759 100644 --- a/src/main/java/com/google/api/codegen/gapic/MainGapicProviderFactory.java +++ b/src/main/java/com/google/api/codegen/gapic/MainGapicProviderFactory.java @@ -431,7 +431,7 @@ public static List> defaultCreate( providers.add(messageProvider); } } - if (generatorConfig.enableTestGenerator() && id.equals(RUBY)) { + if (generatorConfig.enableTestGenerator()) { GapicCodePathMapper rubyTestPathMapper = CommonGapicCodePathMapper.newBuilder() .setPrefix("test") diff --git a/src/test/java/com/google/api/codegen/testdata/ruby_doc_smoke_test_library.baseline b/src/test/java/com/google/api/codegen/testdata/ruby_doc_smoke_test_library.baseline new file mode 100644 index 0000000000..188d0335c8 --- /dev/null +++ b/src/test/java/com/google/api/codegen/testdata/ruby_doc_smoke_test_library.baseline @@ -0,0 +1,41 @@ +============== file: test/library/v1/library_service_smoke_test.rb ============== +# Copyright 2017, Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# AUTO GENERATED BY GAPIC + +require "minitest/autorun" +require "minitest/spec" +require "library/v1/library_service_client" + +describe "LibraryServiceSmokeTest" do + it "runs one smoke test with update_book" do + unless ENV["SMOKE_TEST_PROJECT"] + fail "Usage: SMOKE_TEST_PROJECT= ruby #{$0}" + end + project_id = ENV["SMOKE_TEST_PROJECT"].freeze + + Book = Google::Example::Library::V1::Book + FieldMask = Google::Protobuf::FieldMask + LibraryServiceClient = Library::V1::LibraryServiceClient + Rating = Google::Example::Library::V1::Book::Rating + UpdateBookRequest = Google::Example::Library::V1::UpdateBookRequest + + library_service_client = LibraryServiceClient.new + formatted_name = LibraryServiceClient.book_path("testShelf-" + Time.new.to_i.to_s, project_id) + rating = Rating::GOOD + book = Book.new(rating: rating) + response = library_service_client.update_book(formatted_name, book) + end +end diff --git a/src/test/java/com/google/api/codegen/testdata/ruby_doc_test_library.baseline b/src/test/java/com/google/api/codegen/testdata/ruby_doc_test_library.baseline new file mode 100644 index 0000000000..4f372ef2b3 --- /dev/null +++ b/src/test/java/com/google/api/codegen/testdata/ruby_doc_test_library.baseline @@ -0,0 +1,2023 @@ +============== file: test/library/v1/library_service_client_test.rb ============== +# Copyright 2017, Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require "minitest/autorun" +require "minitest/spec" + +require "google/gax" + +require "library/v1/library_service_client" +require "library_services_pb" +require "tagger_services_pb" +require "google/longrunning/operations_pb" + +class CustomTestError < StandardError; end + +# Mock for the GRPC::ClientStub class. +class MockGrpcClientStub + + # @param expected_symbol [Symbol] the symbol of the grpc method to be mocked. + # @param mock_method [Proc] The method that is being mocked. + def initialize(expected_symbol, mock_method) + @expected_symbol = expected_symbol + @mock_method = mock_method + end + + # This overrides the Object#method method to return the mocked method when the mocked method + # is being requested. For methods that aren't being tested, this method returns a proc that + # will raise an error when called. This is to assure that only the mocked grpc method is being + # called. + # + # @param symbol [Symbol] The symbol of the method being requested. + # @return [Proc] The proc of the requested method. If the requested method is not being mocked + # the proc returned will raise when called. + def method(symbol) + return @mock_method if symbol == @expected_symbol + + # The requested method is not being tested, raise if it called. + proc do + raise "The method #{symbol} was unexpectedly called during the " \ + "test for #{@expected_symbol}." + end + end +end + +describe Library::V1::LibraryServiceClient do + + describe 'create_shelf' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#create_shelf." + + LibraryServiceClient = Library::V1::LibraryServiceClient + Shelf = Google::Example::Library::V1::Shelf + + it 'invokes create_shelf without error' do + # Create request parameters + shelf = Shelf.new + + # Create expected grpc response + name = "name3373707" + theme = "theme110327241" + internal_theme = "internalTheme792518087" + expected_response = Shelf.new( + name: name, + theme: theme, + internal_theme: internal_theme + ) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(shelf, request.shelf) + expected_response + end + mock_stub = MockGrpcClientStub.new(:create_shelf, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.create_shelf(shelf) + + # Verify the response + assert_equal(expected_response, response) + end + end + + it 'invokes create_shelf with error' do + # Create request parameters + shelf = Shelf.new + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(shelf, request.shelf) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:create_shelf, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.create_shelf(shelf) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'get_shelf' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#get_shelf." + + LibraryServiceClient = Library::V1::LibraryServiceClient + Shelf = Google::Example::Library::V1::Shelf + + it 'invokes get_shelf without error' do + # Create request parameters + formatted_name = LibraryServiceClient.shelf_path("[SHELF_ID]") + options_ = '' + + # Create expected grpc response + name_2 = "name2-1052831874" + theme = "theme110327241" + internal_theme = "internalTheme792518087" + expected_response = Shelf.new( + name: name_2, + theme: theme, + internal_theme: internal_theme + ) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + assert_equal(options_, request.options) + expected_response + end + mock_stub = MockGrpcClientStub.new(:get_shelf, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.get_shelf(formatted_name, options_) + + # Verify the response + assert_equal(expected_response, response) + end + end + + it 'invokes get_shelf with error' do + # Create request parameters + formatted_name = LibraryServiceClient.shelf_path("[SHELF_ID]") + options_ = '' + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + assert_equal(options_, request.options) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:get_shelf, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.get_shelf(formatted_name, options_) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'list_shelves' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#list_shelves." + + LibraryServiceClient = Library::V1::LibraryServiceClient + ListShelvesResponse = Google::Example::Library::V1::ListShelvesResponse + Shelf = Google::Example::Library::V1::Shelf + + it 'invokes list_shelves without error' do + # Create expected grpc response + next_page_token = "" + shelves_element = Shelf.new + shelves = [shelves_element] + expected_response = ListShelvesResponse.new(next_page_token: next_page_token, shelves: shelves) + + # Mock Grpc layer + mock_method = proc do + expected_response + end + mock_stub = MockGrpcClientStub.new(:list_shelves, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.list_shelves + + # Verify the response + assert(response.instance_of?(Google::Gax::PagedEnumerable)) + assert_equal(expected_response, response.page.response) + assert_nil(response.next_page) + assert_equal(expected_response.shelves.to_a, response.to_a) + end + end + + it 'invokes list_shelves with error' do + # Mock Grpc layer + mock_method = proc do + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:list_shelves, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.list_shelves + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'delete_shelf' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#delete_shelf." + + Empty = Google::Protobuf::Empty + LibraryServiceClient = Library::V1::LibraryServiceClient + + it 'invokes delete_shelf without error' do + # Create request parameters + formatted_name = LibraryServiceClient.shelf_path("[SHELF_ID]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + nil + end + mock_stub = MockGrpcClientStub.new(:delete_shelf, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.delete_shelf(formatted_name) + + # Verify the response + assert_nil(response) + end + end + + it 'invokes delete_shelf with error' do + # Create request parameters + formatted_name = LibraryServiceClient.shelf_path("[SHELF_ID]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:delete_shelf, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.delete_shelf(formatted_name) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'merge_shelves' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#merge_shelves." + + LibraryServiceClient = Library::V1::LibraryServiceClient + Shelf = Google::Example::Library::V1::Shelf + + it 'invokes merge_shelves without error' do + # Create request parameters + formatted_name = LibraryServiceClient.shelf_path("[SHELF_ID]") + formatted_other_shelf_name = LibraryServiceClient.shelf_path("[SHELF_ID]") + + # Create expected grpc response + name_2 = "name2-1052831874" + theme = "theme110327241" + internal_theme = "internalTheme792518087" + expected_response = Shelf.new( + name: name_2, + theme: theme, + internal_theme: internal_theme + ) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + assert_equal(formatted_other_shelf_name, request.other_shelf_name) + expected_response + end + mock_stub = MockGrpcClientStub.new(:merge_shelves, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.merge_shelves(formatted_name, formatted_other_shelf_name) + + # Verify the response + assert_equal(expected_response, response) + end + end + + it 'invokes merge_shelves with error' do + # Create request parameters + formatted_name = LibraryServiceClient.shelf_path("[SHELF_ID]") + formatted_other_shelf_name = LibraryServiceClient.shelf_path("[SHELF_ID]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + assert_equal(formatted_other_shelf_name, request.other_shelf_name) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:merge_shelves, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.merge_shelves(formatted_name, formatted_other_shelf_name) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'create_book' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#create_book." + + Book = Google::Example::Library::V1::Book + LibraryServiceClient = Library::V1::LibraryServiceClient + + it 'invokes create_book without error' do + # Create request parameters + formatted_name = LibraryServiceClient.shelf_path("[SHELF_ID]") + book = Book.new + + # Create expected grpc response + name_2 = "name2-1052831874" + author = "author-1406328437" + title = "title110371416" + read = true + expected_response = Book.new( + name: name_2, + author: author, + title: title, + read: read + ) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + assert_equal(book, request.book) + expected_response + end + mock_stub = MockGrpcClientStub.new(:create_book, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.create_book(formatted_name, book) + + # Verify the response + assert_equal(expected_response, response) + end + end + + it 'invokes create_book with error' do + # Create request parameters + formatted_name = LibraryServiceClient.shelf_path("[SHELF_ID]") + book = Book.new + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + assert_equal(book, request.book) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:create_book, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.create_book(formatted_name, book) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'publish_series' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#publish_series." + + LibraryServiceClient = Library::V1::LibraryServiceClient + PublishSeriesResponse = Google::Example::Library::V1::PublishSeriesResponse + SeriesUuid = Google::Example::Library::V1::SeriesUuid + Shelf = Google::Example::Library::V1::Shelf + + it 'invokes publish_series without error' do + # Create request parameters + shelf = Shelf.new + books = [] + series_string = "foobar" + series_uuid = SeriesUuid.new(series_string: series_string) + + # Create expected grpc response + book_names_element = "bookNamesElement1491670575" + book_names = [book_names_element] + expected_response = PublishSeriesResponse.new(book_names: book_names) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(shelf, request.shelf) + assert_equal(books, request.books) + assert_equal(series_uuid, request.series_uuid) + expected_response + end + mock_stub = MockGrpcClientStub.new(:publish_series, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.publish_series( + shelf, + books, + series_uuid + ) + + # Verify the response + assert_equal(expected_response, response) + end + end + + it 'invokes publish_series with error' do + # Create request parameters + shelf = Shelf.new + books = [] + series_string = "foobar" + series_uuid = SeriesUuid.new(series_string: series_string) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(shelf, request.shelf) + assert_equal(books, request.books) + assert_equal(series_uuid, request.series_uuid) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:publish_series, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.publish_series( + shelf, + books, + series_uuid + ) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'get_book' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#get_book." + + Book = Google::Example::Library::V1::Book + LibraryServiceClient = Library::V1::LibraryServiceClient + + it 'invokes get_book without error' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + + # Create expected grpc response + name_2 = "name2-1052831874" + author = "author-1406328437" + title = "title110371416" + read = true + expected_response = Book.new( + name: name_2, + author: author, + title: title, + read: read + ) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + expected_response + end + mock_stub = MockGrpcClientStub.new(:get_book, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.get_book(formatted_name) + + # Verify the response + assert_equal(expected_response, response) + end + end + + it 'invokes get_book with error' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:get_book, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.get_book(formatted_name) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'list_books' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#list_books." + + Book = Google::Example::Library::V1::Book + LibraryServiceClient = Library::V1::LibraryServiceClient + ListBooksResponse = Google::Example::Library::V1::ListBooksResponse + + it 'invokes list_books without error' do + # Create request parameters + formatted_name = LibraryServiceClient.shelf_path("[SHELF_ID]") + + # Create expected grpc response + next_page_token = "" + books_element = Book.new + books = [books_element] + expected_response = ListBooksResponse.new(next_page_token: next_page_token, books: books) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + expected_response + end + mock_stub = MockGrpcClientStub.new(:list_books, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.list_books(formatted_name) + + # Verify the response + assert(response.instance_of?(Google::Gax::PagedEnumerable)) + assert_equal(expected_response, response.page.response) + assert_nil(response.next_page) + assert_equal(expected_response.books.to_a, response.to_a) + end + end + + it 'invokes list_books with error' do + # Create request parameters + formatted_name = LibraryServiceClient.shelf_path("[SHELF_ID]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:list_books, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.list_books(formatted_name) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'delete_book' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#delete_book." + + Empty = Google::Protobuf::Empty + LibraryServiceClient = Library::V1::LibraryServiceClient + + it 'invokes delete_book without error' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + nil + end + mock_stub = MockGrpcClientStub.new(:delete_book, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.delete_book(formatted_name) + + # Verify the response + assert_nil(response) + end + end + + it 'invokes delete_book with error' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:delete_book, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.delete_book(formatted_name) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'update_book' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#update_book." + + Book = Google::Example::Library::V1::Book + LibraryServiceClient = Library::V1::LibraryServiceClient + + it 'invokes update_book without error' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + book = Book.new + + # Create expected grpc response + name_2 = "name2-1052831874" + author = "author-1406328437" + title = "title110371416" + read = true + expected_response = Book.new( + name: name_2, + author: author, + title: title, + read: read + ) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + assert_equal(book, request.book) + expected_response + end + mock_stub = MockGrpcClientStub.new(:update_book, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.update_book(formatted_name, book) + + # Verify the response + assert_equal(expected_response, response) + end + end + + it 'invokes update_book with error' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + book = Book.new + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + assert_equal(book, request.book) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:update_book, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.update_book(formatted_name, book) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'move_book' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#move_book." + + Book = Google::Example::Library::V1::Book + LibraryServiceClient = Library::V1::LibraryServiceClient + + it 'invokes move_book without error' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + formatted_other_shelf_name = LibraryServiceClient.shelf_path("[SHELF_ID]") + + # Create expected grpc response + name_2 = "name2-1052831874" + author = "author-1406328437" + title = "title110371416" + read = true + expected_response = Book.new( + name: name_2, + author: author, + title: title, + read: read + ) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + assert_equal(formatted_other_shelf_name, request.other_shelf_name) + expected_response + end + mock_stub = MockGrpcClientStub.new(:move_book, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.move_book(formatted_name, formatted_other_shelf_name) + + # Verify the response + assert_equal(expected_response, response) + end + end + + it 'invokes move_book with error' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + formatted_other_shelf_name = LibraryServiceClient.shelf_path("[SHELF_ID]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + assert_equal(formatted_other_shelf_name, request.other_shelf_name) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:move_book, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.move_book(formatted_name, formatted_other_shelf_name) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'list_strings' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#list_strings." + + LibraryServiceClient = Library::V1::LibraryServiceClient + ListStringsResponse = Google::Example::Library::V1::ListStringsResponse + + it 'invokes list_strings without error' do + # Create expected grpc response + next_page_token = "" + strings_element = "stringsElement474465855" + strings = [strings_element] + expected_response = ListStringsResponse.new(next_page_token: next_page_token, strings: strings) + + # Mock Grpc layer + mock_method = proc do + expected_response + end + mock_stub = MockGrpcClientStub.new(:list_strings, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.list_strings + + # Verify the response + assert(response.instance_of?(Google::Gax::PagedEnumerable)) + assert_equal(expected_response, response.page.response) + assert_nil(response.next_page) + assert_equal(expected_response.strings.to_a, response.to_a) + end + end + + it 'invokes list_strings with error' do + # Mock Grpc layer + mock_method = proc do + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:list_strings, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.list_strings + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'add_comments' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#add_comments." + + Alignment = Google::Example::Library::V1::SomeMessage2::SomeMessage3::Alignment + Comment = Google::Example::Library::V1::Comment + Empty = Google::Protobuf::Empty + LibraryServiceClient = Library::V1::LibraryServiceClient + Stage = Google::Example::Library::V1::Comment::Stage + + it 'invokes add_comments without error' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + comment = '' + stage = Stage::UNSET + alignment = Alignment::CHAR + comments_element = Comment.new( + comment: comment, + stage: stage, + alignment: alignment + ) + comments = [comments_element] + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + assert_equal(comments, request.comments) + nil + end + mock_stub = MockGrpcClientStub.new(:add_comments, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.add_comments(formatted_name, comments) + + # Verify the response + assert_nil(response) + end + end + + it 'invokes add_comments with error' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + comment = '' + stage = Stage::UNSET + alignment = Alignment::CHAR + comments_element = Comment.new( + comment: comment, + stage: stage, + alignment: alignment + ) + comments = [comments_element] + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + assert_equal(comments, request.comments) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:add_comments, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.add_comments(formatted_name, comments) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'get_book_from_archive' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#get_book_from_archive." + + BookFromArchive = Google::Example::Library::V1::BookFromArchive + LibraryServiceClient = Library::V1::LibraryServiceClient + + it 'invokes get_book_from_archive without error' do + # Create request parameters + formatted_name = LibraryServiceClient.archived_book_path("[ARCHIVE_PATH]", "[BOOK_ID]") + + # Create expected grpc response + name_2 = "name2-1052831874" + author = "author-1406328437" + title = "title110371416" + read = true + expected_response = BookFromArchive.new( + name: name_2, + author: author, + title: title, + read: read + ) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + expected_response + end + mock_stub = MockGrpcClientStub.new(:get_book_from_archive, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.get_book_from_archive(formatted_name) + + # Verify the response + assert_equal(expected_response, response) + end + end + + it 'invokes get_book_from_archive with error' do + # Create request parameters + formatted_name = LibraryServiceClient.archived_book_path("[ARCHIVE_PATH]", "[BOOK_ID]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:get_book_from_archive, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.get_book_from_archive(formatted_name) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'get_book_from_anywhere' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#get_book_from_anywhere." + + BookFromAnywhere = Google::Example::Library::V1::BookFromAnywhere + LibraryServiceClient = Library::V1::LibraryServiceClient + + it 'invokes get_book_from_anywhere without error' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + formatted_alt_book_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + + # Create expected grpc response + name_2 = "name2-1052831874" + author = "author-1406328437" + title = "title110371416" + read = true + expected_response = BookFromAnywhere.new( + name: name_2, + author: author, + title: title, + read: read + ) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + assert_equal(formatted_alt_book_name, request.alt_book_name) + expected_response + end + mock_stub = MockGrpcClientStub.new(:get_book_from_anywhere, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.get_book_from_anywhere(formatted_name, formatted_alt_book_name) + + # Verify the response + assert_equal(expected_response, response) + end + end + + it 'invokes get_book_from_anywhere with error' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + formatted_alt_book_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + assert_equal(formatted_alt_book_name, request.alt_book_name) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:get_book_from_anywhere, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.get_book_from_anywhere(formatted_name, formatted_alt_book_name) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'update_book_index' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#update_book_index." + + Empty = Google::Protobuf::Empty + LibraryServiceClient = Library::V1::LibraryServiceClient + + it 'invokes update_book_index without error' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + index_name = "default index" + index_map_item = '' + index_map = { "default_key" => index_map_item } + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + assert_equal(index_name, request.index_name) + assert_equal(index_map, request.index_map) + nil + end + mock_stub = MockGrpcClientStub.new(:update_book_index, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.update_book_index( + formatted_name, + index_name, + index_map + ) + + # Verify the response + assert_nil(response) + end + end + + it 'invokes update_book_index with error' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + index_name = "default index" + index_map_item = '' + index_map = { "default_key" => index_map_item } + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + assert_equal(index_name, request.index_name) + assert_equal(index_map, request.index_map) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:update_book_index, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.update_book_index( + formatted_name, + index_name, + index_map + ) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'stream_shelves' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#stream_shelves." + + LibraryServiceClient = Library::V1::LibraryServiceClient + StreamShelvesRequest = Google::Example::Library::V1::StreamShelvesRequest + StreamShelvesResponse = Google::Example::Library::V1::StreamShelvesResponse + + it 'invokes stream_shelves without error' do + # Create request parameters + request = StreamShelvesRequest.new + + # Create expected grpc response + expected_response = StreamShelvesResponse.new + + # Mock Grpc layer + mock_method = proc do |request| + [expected_response] + end + mock_stub = MockGrpcClientStub.new(:stream_shelves, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.stream_shelves(request) + + # Verify the response + assert_equal(1, response.count) + assert_equal(expected_response, response.first) + end + end + + it 'invokes stream_shelves with error' do + # Create request parameters + request = StreamShelvesRequest.new + + # Mock Grpc layer + mock_method = proc do |request| + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:stream_shelves, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.stream_shelves(request) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'stream_books' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#stream_books." + + Book = Google::Example::Library::V1::Book + LibraryServiceClient = Library::V1::LibraryServiceClient + StreamBooksRequest = Google::Example::Library::V1::StreamBooksRequest + + it 'invokes stream_books without error' do + # Create request parameters + name = '' + request = StreamBooksRequest.new(name: name) + + # Create expected grpc response + name_2 = "name2-1052831874" + author = "author-1406328437" + title = "title110371416" + read = true + expected_response = Book.new( + name: name_2, + author: author, + title: title, + read: read + ) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(name, request.name) + [expected_response] + end + mock_stub = MockGrpcClientStub.new(:stream_books, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.stream_books(request) + + # Verify the response + assert_equal(1, response.count) + assert_equal(expected_response, response.first) + end + end + + it 'invokes stream_books with error' do + # Create request parameters + name = '' + request = StreamBooksRequest.new(name: name) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(name, request.name) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:stream_books, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.stream_books(request) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'discuss_book' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#discuss_book." + + Comment = Google::Example::Library::V1::Comment + DiscussBookRequest = Google::Example::Library::V1::DiscussBookRequest + LibraryServiceClient = Library::V1::LibraryServiceClient + + it 'invokes discuss_book without error' do + # Create request parameters + name = '' + request = DiscussBookRequest.new(name: name) + + # Create expected grpc response + user_name = "userName339340927" + comment = "95" + expected_response = Comment.new(user_name: user_name, comment: comment) + + # Mock Grpc layer + mock_method = proc do |requests| + request = requests.first + assert_equal(name, request.name) + [expected_response] + end + mock_stub = MockGrpcClientStub.new(:discuss_book, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.discuss_book([request]) + + # Verify the response + assert_equal(1, response.count) + assert_equal(expected_response, response.first) + end + end + + it 'invokes discuss_book with error' do + # Create request parameters + name = '' + request = DiscussBookRequest.new(name: name) + + # Mock Grpc layer + mock_method = proc do |requests| + request = requests.first + assert_equal(name, request.name) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:discuss_book, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.discuss_book([request]) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'monolog_about_book' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#monolog_about_book." + + Comment = Google::Example::Library::V1::Comment + DiscussBookRequest = Google::Example::Library::V1::DiscussBookRequest + LibraryServiceClient = Library::V1::LibraryServiceClient + + it 'invokes monolog_about_book without error' do + # Create request parameters + name = '' + request = DiscussBookRequest.new(name: name) + + # Create expected grpc response + user_name = "userName339340927" + comment = "95" + expected_response = Comment.new(user_name: user_name, comment: comment) + + # Mock Grpc layer + mock_method = proc do |requests| + request = requests.first + assert_equal(name, request.name) + expected_response + end + mock_stub = MockGrpcClientStub.new(:monolog_about_book, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.monolog_about_book([request]) + + # Verify the response + assert_equal(expected_response, response) + end + end + + it 'invokes monolog_about_book with error' do + # Create request parameters + name = '' + request = DiscussBookRequest.new(name: name) + + # Mock Grpc layer + mock_method = proc do |requests| + request = requests.first + assert_equal(name, request.name) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:monolog_about_book, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.monolog_about_book([request]) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'find_related_books' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#find_related_books." + + FindRelatedBooksResponse = Google::Example::Library::V1::FindRelatedBooksResponse + LibraryServiceClient = Library::V1::LibraryServiceClient + + it 'invokes find_related_books without error' do + # Create request parameters + names_element = '' + names = [names_element] + shelves = [] + + # Create expected grpc response + next_page_token = "" + names_element_2 = "namesElement21120252792" + names_2 = [names_element_2] + expected_response = FindRelatedBooksResponse.new(next_page_token: next_page_token, names: names_2) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(names, request.names) + assert_equal(shelves, request.shelves) + expected_response + end + mock_stub = MockGrpcClientStub.new(:find_related_books, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.find_related_books(names, shelves) + + # Verify the response + assert(response.instance_of?(Google::Gax::PagedEnumerable)) + assert_equal(expected_response, response.page.response) + assert_nil(response.next_page) + assert_equal(expected_response.names.to_a, response.to_a) + end + end + + it 'invokes find_related_books with error' do + # Create request parameters + names_element = '' + names = [names_element] + shelves = [] + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(names, request.names) + assert_equal(shelves, request.shelves) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:find_related_books, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.find_related_books(names, shelves) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'add_tag' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#add_tag." + + AddTagResponse = Google::Tagger::V1::AddTagResponse + LibraryServiceClient = Library::V1::LibraryServiceClient + + it 'invokes add_tag without error' do + # Create request parameters + formatted_resource = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + tag = '' + + # Create expected grpc response + expected_response = AddTagResponse.new + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_resource, request.resource) + assert_equal(tag, request.tag) + expected_response + end + mock_stub = MockGrpcClientStub.new(:add_tag, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.add_tag(formatted_resource, tag) + + # Verify the response + assert_equal(expected_response, response) + end + end + + it 'invokes add_tag with error' do + # Create request parameters + formatted_resource = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + tag = '' + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_resource, request.resource) + assert_equal(tag, request.tag) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:add_tag, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.add_tag(formatted_resource, tag) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'add_label' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#add_label." + + AddLabelResponse = Google::Tagger::V1::AddLabelResponse + LibraryServiceClient = Library::V1::LibraryServiceClient + + it 'invokes add_label without error' do + # Create request parameters + formatted_resource = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + label = '' + + # Create expected grpc response + expected_response = AddLabelResponse.new + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_resource, request.resource) + assert_equal(label, request.label) + expected_response + end + mock_stub = MockGrpcClientStub.new(:add_label, mock_method) + + Google::Tagger::V1::Labeler::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.add_label(formatted_resource, label) + + # Verify the response + assert_equal(expected_response, response) + end + end + + it 'invokes add_label with error' do + # Create request parameters + formatted_resource = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + label = '' + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_resource, request.resource) + assert_equal(label, request.label) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:add_label, mock_method) + + Google::Tagger::V1::Labeler::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.add_label(formatted_resource, label) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'get_big_book' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#get_big_book." + + Book = Google::Example::Library::V1::Book + LibraryServiceClient = Library::V1::LibraryServiceClient + + it 'invokes get_big_book without error' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + + # Create expected grpc response + name_2 = "name2-1052831874" + author = "author-1406328437" + title = "title110371416" + read = true + expected_response = Book.new( + name: name_2, + author: author, + title: title, + read: read + ) + result = Google::Protobuf::Any.new + result.pack(expected_response) + operation = Google::Longrunning::Operation.new( + name: 'operations/get_big_book_test', + done: true, + response: result + ) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + operation + end + mock_stub = MockGrpcClientStub.new(:get_big_book, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.get_big_book(formatted_name) + + # Verify the response + assert_equal(expected_response, response.response) + end + end + + it 'invokes get_big_book and returns an operation error.' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + + # Create expected grpc response + operation_error = Google::Rpc::Status.new( + message: 'Operation error for LibraryServiceClient#get_big_book.' + ) + operation = Google::Longrunning::Operation.new( + name: 'operations/get_big_book_test', + done: true, + error: operation_error + ) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + operation + end + mock_stub = MockGrpcClientStub.new(:get_big_book, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.get_big_book(formatted_name) + + # Verify the response + assert(response.error?) + assert_equal(operation_error, response.error) + end + end + + it 'invokes get_big_book with error' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:get_big_book, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.get_big_book(formatted_name) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'get_big_nothing' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#get_big_nothing." + + Empty = Google::Protobuf::Empty + LibraryServiceClient = Library::V1::LibraryServiceClient + + it 'invokes get_big_nothing without error' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + + # Create expected grpc response + expected_response = Empty.new + result = Google::Protobuf::Any.new + result.pack(expected_response) + operation = Google::Longrunning::Operation.new( + name: 'operations/get_big_nothing_test', + done: true, + response: result + ) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + operation + end + mock_stub = MockGrpcClientStub.new(:get_big_nothing, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.get_big_nothing(formatted_name) + + # Verify the response + assert_equal(expected_response, response.response) + end + end + + it 'invokes get_big_nothing and returns an operation error.' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + + # Create expected grpc response + operation_error = Google::Rpc::Status.new( + message: 'Operation error for LibraryServiceClient#get_big_nothing.' + ) + operation = Google::Longrunning::Operation.new( + name: 'operations/get_big_nothing_test', + done: true, + error: operation_error + ) + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + operation + end + mock_stub = MockGrpcClientStub.new(:get_big_nothing, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.get_big_nothing(formatted_name) + + # Verify the response + assert(response.error?) + assert_equal(operation_error, response.error) + end + end + + it 'invokes get_big_nothing with error' do + # Create request parameters + formatted_name = LibraryServiceClient.book_path("[SHELF_ID]", "[BOOK_ID]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(formatted_name, request.name) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:get_big_nothing, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.get_big_nothing(formatted_name) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + + describe 'test_optional_required_flattening_params' do + custom_error = CustomTestError.new "Custom test error for LibraryServiceClient#test_optional_required_flattening_params." + + InnerEnum = Google::Example::Library::V1::TestOptionalRequiredFlatteningParamsRequest::InnerEnum + InnerMessage = Google::Example::Library::V1::TestOptionalRequiredFlatteningParamsRequest::InnerMessage + LibraryServiceClient = Library::V1::LibraryServiceClient + TestOptionalRequiredFlatteningParamsResponse = Google::Example::Library::V1::TestOptionalRequiredFlatteningParamsResponse + + it 'invokes test_optional_required_flattening_params without error' do + # Create request parameters + required_singular_int32 = 0 + required_singular_int64 = 0 + required_singular_float = 0.0 + required_singular_double = 0.0 + required_singular_bool = false + required_singular_enum = InnerEnum::ZERO + required_singular_string = '' + required_singular_bytes = '' + required_singular_message = InnerMessage.new + required_singular_resource_name = '' + required_singular_resource_name_oneof = '' + required_singular_fixed32 = 0 + required_singular_fixed64 = 0 + required_repeated_int32 = [] + required_repeated_int64 = [] + required_repeated_float = [] + required_repeated_double = [] + required_repeated_bool = [] + required_repeated_enum = [] + required_repeated_string = [] + required_repeated_bytes = [] + required_repeated_message = [] + formatted_required_repeated_resource_name = [] + formatted_required_repeated_resource_name_oneof = [] + required_repeated_fixed32 = [] + required_repeated_fixed64 = [] + required_map = {} + + # Create expected grpc response + expected_response = TestOptionalRequiredFlatteningParamsResponse.new + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(required_singular_int32, request.required_singular_int32) + assert_equal(required_singular_int64, request.required_singular_int64) + assert_equal(required_singular_float, request.required_singular_float) + assert_equal(required_singular_double, request.required_singular_double) + assert_equal(required_singular_bool, request.required_singular_bool) + assert_equal(InnerEnum.lookup(required_singular_enum), request.required_singular_enum) + assert_equal(required_singular_string, request.required_singular_string) + assert_equal(required_singular_bytes, request.required_singular_bytes) + assert_equal(required_singular_message, request.required_singular_message) + assert_equal(required_singular_resource_name, request.required_singular_resource_name) + assert_equal(required_singular_resource_name_oneof, request.required_singular_resource_name_oneof) + assert_equal(required_singular_fixed32, request.required_singular_fixed32) + assert_equal(required_singular_fixed64, request.required_singular_fixed64) + assert_equal(required_repeated_int32, request.required_repeated_int32) + assert_equal(required_repeated_int64, request.required_repeated_int64) + assert_equal(required_repeated_float, request.required_repeated_float) + assert_equal(required_repeated_double, request.required_repeated_double) + assert_equal(required_repeated_bool, request.required_repeated_bool) + assert_equal(required_repeated_enum, request.required_repeated_enum) + assert_equal(required_repeated_string, request.required_repeated_string) + assert_equal(required_repeated_bytes, request.required_repeated_bytes) + assert_equal(required_repeated_message, request.required_repeated_message) + assert_equal(formatted_required_repeated_resource_name, request.required_repeated_resource_name) + assert_equal(formatted_required_repeated_resource_name_oneof, request.required_repeated_resource_name_oneof) + assert_equal(required_repeated_fixed32, request.required_repeated_fixed32) + assert_equal(required_repeated_fixed64, request.required_repeated_fixed64) + assert_equal(required_map, request.required_map) + expected_response + end + mock_stub = MockGrpcClientStub.new(:test_optional_required_flattening_params, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + response = client.test_optional_required_flattening_params( + required_singular_int32, + required_singular_int64, + required_singular_float, + required_singular_double, + required_singular_bool, + required_singular_enum, + required_singular_string, + required_singular_bytes, + required_singular_message, + required_singular_resource_name, + required_singular_resource_name_oneof, + required_singular_fixed32, + required_singular_fixed64, + required_repeated_int32, + required_repeated_int64, + required_repeated_float, + required_repeated_double, + required_repeated_bool, + required_repeated_enum, + required_repeated_string, + required_repeated_bytes, + required_repeated_message, + formatted_required_repeated_resource_name, + formatted_required_repeated_resource_name_oneof, + required_repeated_fixed32, + required_repeated_fixed64, + required_map + ) + + # Verify the response + assert_equal(expected_response, response) + end + end + + it 'invokes test_optional_required_flattening_params with error' do + # Create request parameters + required_singular_int32 = 0 + required_singular_int64 = 0 + required_singular_float = 0.0 + required_singular_double = 0.0 + required_singular_bool = false + required_singular_enum = InnerEnum::ZERO + required_singular_string = '' + required_singular_bytes = '' + required_singular_message = InnerMessage.new + required_singular_resource_name = '' + required_singular_resource_name_oneof = '' + required_singular_fixed32 = 0 + required_singular_fixed64 = 0 + required_repeated_int32 = [] + required_repeated_int64 = [] + required_repeated_float = [] + required_repeated_double = [] + required_repeated_bool = [] + required_repeated_enum = [] + required_repeated_string = [] + required_repeated_bytes = [] + required_repeated_message = [] + formatted_required_repeated_resource_name = [] + formatted_required_repeated_resource_name_oneof = [] + required_repeated_fixed32 = [] + required_repeated_fixed64 = [] + required_map = {} + + # Mock Grpc layer + mock_method = proc do |request| + assert_equal(required_singular_int32, request.required_singular_int32) + assert_equal(required_singular_int64, request.required_singular_int64) + assert_equal(required_singular_float, request.required_singular_float) + assert_equal(required_singular_double, request.required_singular_double) + assert_equal(required_singular_bool, request.required_singular_bool) + assert_equal(InnerEnum.lookup(required_singular_enum), request.required_singular_enum) + assert_equal(required_singular_string, request.required_singular_string) + assert_equal(required_singular_bytes, request.required_singular_bytes) + assert_equal(required_singular_message, request.required_singular_message) + assert_equal(required_singular_resource_name, request.required_singular_resource_name) + assert_equal(required_singular_resource_name_oneof, request.required_singular_resource_name_oneof) + assert_equal(required_singular_fixed32, request.required_singular_fixed32) + assert_equal(required_singular_fixed64, request.required_singular_fixed64) + assert_equal(required_repeated_int32, request.required_repeated_int32) + assert_equal(required_repeated_int64, request.required_repeated_int64) + assert_equal(required_repeated_float, request.required_repeated_float) + assert_equal(required_repeated_double, request.required_repeated_double) + assert_equal(required_repeated_bool, request.required_repeated_bool) + assert_equal(required_repeated_enum, request.required_repeated_enum) + assert_equal(required_repeated_string, request.required_repeated_string) + assert_equal(required_repeated_bytes, request.required_repeated_bytes) + assert_equal(required_repeated_message, request.required_repeated_message) + assert_equal(formatted_required_repeated_resource_name, request.required_repeated_resource_name) + assert_equal(formatted_required_repeated_resource_name_oneof, request.required_repeated_resource_name_oneof) + assert_equal(required_repeated_fixed32, request.required_repeated_fixed32) + assert_equal(required_repeated_fixed64, request.required_repeated_fixed64) + assert_equal(required_map, request.required_map) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:test_optional_required_flattening_params, mock_method) + + Google::Example::Library::V1::LibraryService::Stub.stub(:new, mock_stub) do + client = LibraryServiceClient.new + + # Call method + err = assert_raises Google::Gax::GaxError do + client.test_optional_required_flattening_params( + required_singular_int32, + required_singular_int64, + required_singular_float, + required_singular_double, + required_singular_bool, + required_singular_enum, + required_singular_string, + required_singular_bytes, + required_singular_message, + required_singular_resource_name, + required_singular_resource_name_oneof, + required_singular_fixed32, + required_singular_fixed64, + required_repeated_int32, + required_repeated_int64, + required_repeated_float, + required_repeated_double, + required_repeated_bool, + required_repeated_enum, + required_repeated_string, + required_repeated_bytes, + required_repeated_message, + formatted_required_repeated_resource_name, + formatted_required_repeated_resource_name_oneof, + required_repeated_fixed32, + required_repeated_fixed64, + required_map + ) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end +end