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

git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@494129 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2007-01-08 17:28:36 +00:00
parent 25d727100e
commit c1311749ac
3 changed files with 33 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -18,19 +18,22 @@ class SolrMockBaseTestCase < Test::Unit::TestCase
def setup
Connection.send(:alias_method, :orig_post, :post)
Connection.class_eval %{
def post(request)
"foo"
end
}
end
def teardown
Connection.send(:alias_method, :post, :orig_post)
end
def test_mock
connection = Connection.new("http://localhost:9999")
assert_equal "foo", connection.post(UpdateRequest.new("bogus"))
def set_post_return(value)
Connection.class_eval %{
def post(request)
%q{#{value}}
end
}
end
def test_dummy
# So Test::Unit is happy running this class
end
end