Skip to content

Apache Lucene open-source search software

Add more test coverage, with the currently only uncovered code being the mocked Connection#post method

Erik Hatcherc1311749ac43
diff --git a/client/ruby/solrb/test/unit/connection_test.rb b/client/ruby/solrb/test/unit/connection_test.rb
index 04d2b57fb3a..15752a2e48e 100755
--- a/client/ruby/solrb/test/unit/connection_test.rb
+++ b/client/ruby/solrb/test/unit/connection_test.rb
@@ -15,10 +15,30 @@ require 'solr'
require 'solr_mock_base'
class ConnectionTest < SolrMockBaseTestCase
+ def test_mock
+ connection = Connection.new("http://localhost:9999")
+ set_post_return("foo")
+ assert_equal "foo", connection.post(UpdateRequest.new("bogus"))
+ end
+
def test_connection_initialize
request = Solr::UpdateRequest.new("<commit/>")
connection = Solr::Connection.new("http://localhost:8983")
assert_equal("localhost", connection.url.host)
assert_equal(8983, connection.url.port)
end
+
+ def test_xml_response
+ connection = Connection.new("http://localhost:9999")
+ set_post_return "<bogus/>"
+ response = connection.send(UpdateRequest.new("bogus"))
+ assert_equal "<bogus/>", response.raw_response
+ end
+
+ def test_ruby_response
+ connection = Connection.new("http://localhost:9999")
+ set_post_return "{}"
+ response = connection.send(StandardRequest.new)
+ assert_equal "{}", response.raw_response
+ end
end
diff --git a/client/ruby/solrb/test/unit/request_test.rb b/client/ruby/solrb/test/unit/request_test.rb
index 336d190d2de..cbcbe53b291 100755
--- a/client/ruby/solrb/test/unit/request_test.rb
+++ b/client/ruby/solrb/test/unit/request_test.rb
@@ -20,6 +20,8 @@ class RequestTest < Test::Unit::TestCase
request.query = "term"
assert_equal "term", request.to_hash[:q]
+
+ assert_equal "q=term&wt=ruby", request.to_http_body
end
def test_update_request
diff --git a/client/ruby/solrb/test/unit/solr_mock_base.rb b/client/ruby/solrb/test/unit/solr_mock_base.rb
index dc26c9b6e07..b39c6184761 100755
--- a/client/ruby/solrb/test/unit/solr_mock_base.rb
+++ b/client/ruby/solrb/test/unit/solr_mock_base.rb
@@ -18,19 +18,22 @@ class SolrMockBaseTestCase < Test::Unit::TestCase
def setup
Connection.send(:alias_method, :orig_post, :post)
+ end
+
+ def teardown
+ Connection.send(:alias_method, :post, :orig_post)
+ end
+
+ def set_post_return(value)
Connection.class_eval %{
def post(request)
- "foo"
+ %q{#{value}}
end
}
end
- def teardown
- Connection.send(:alias_method, :post, :orig_post)
+ def test_dummy
+ # So Test::Unit is happy running this class
end
- def test_mock
- connection = Connection.new("http://localhost:9999")
- assert_equal "foo", connection.post(UpdateRequest.new("bogus"))
- end
end