Apache Solr open-source search software
first attempt at making a mock Solr::Connection base test case
Erik Hatcher0b3fc2da6be4
diff --git a/client/ruby/solrb/lib/solr/connection.rb b/client/ruby/solrb/lib/solr/connection.rbindex be5fa139a76..f16e5d192dd 100755--- a/client/ruby/solrb/lib/solr/connection.rb+++ b/client/ruby/solrb/lib/solr/connection.rb@@ -21,13 +21,19 @@ module Solrenddef send(request)+ data = post(request)+ return request.response_format == :ruby ? RubyResponse.new(data) : XmlResponse.new(data)+ end++ def post(request)post = Net::HTTP::Post.new(request.url_path)post.body = request.to_http_bodypost.content_type = 'application/x-www-form-urlencoded; charset=utf-8'response = Net::HTTP.start(@url.host, @url.port) do |http|http.request(post)end- return request.response_format == :ruby ? RubyResponse.new(response.body) : XmlResponse.new(response.body)++ return response.bodyendendenddiff --git a/client/ruby/solrb/test/connection_test.rb b/client/ruby/solrb/test/connection_test.rbindex dd764535571..9420911a55e 100755--- a/client/ruby/solrb/test/connection_test.rb+++ b/client/ruby/solrb/test/connection_test.rb@@ -13,7 +13,22 @@require 'test/unit'require 'solr'-class ConnectionTest < Test::Unit::TestCase+module Solr+ class Connection+ def post(request)+ "foo"+ end+ end++ class MockSolrBaseTest < Test::Unit::TestCase+ def test_mock+ connection = Connection.new("http://localhost:9999")+ assert_equal "foo", connection.post(UpdateRequest.new("bogus"))+ end+ end+end++class ConnectionTest < Solr::MockSolrBaseTestdef test_connection_initializerequest = Solr::UpdateRequest.new("<commit/>")connection = Solr::Connection.new("http://localhost:8983")diff --git a/client/ruby/solrb/test/test_helper.rb b/client/ruby/solrb/test/test_helper.rbindex 5ae15ce1ae9..e6912b362c8 100644--- a/client/ruby/solrb/test/test_helper.rb+++ b/client/ruby/solrb/test/test_helper.rb@@ -10,6 +10,8 @@# See the License for the specific language governing permissions and# limitations under the License.+require 'test/unit'+def start_solr_serverDir.chdir(File.dirname(__FILE__) + '/../solr') doputs "starting solr server"@@ -32,3 +34,4 @@ def stop_solr_serverputs "stopping solr server"Process.kill('TERM', $SOLR_PID)end+