Add tests to cover the exception handling, bringing code coverage back to 100%

git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@495258 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2007-01-11 15:42:57 +00:00
parent 0cad261fb8
commit 2d5f7d6250
2 changed files with 24 additions and 0 deletions

View File

@ -16,10 +16,26 @@ require 'solr'
class TestServer < Test::Unit::TestCase
include Solr
class BadRequest < Request
def initialize
@url_path = "/bogus"
end
def to_http_body
"bogus"
end
end
def setup
@connection = Connection.new("http://localhost:8888")
end
def test_error
assert_raise(Net::HTTPServerException) do
@connection.send(BadRequest.new)
end
end
def test_commit
response = @connection.send(UpdateRequest.new("<commit/>"))
assert_equal "<result status=\"0\"></result>", response.raw_response

View File

@ -39,6 +39,14 @@ class RequestTest < Test::Unit::TestCase
assert_raise(Solr::RequestException) do
new Solr::Response.new("<result status=\"400\">ERROR:</result>")
end
begin
new Solr::Response.new("<result status=\"400\">ERROR:</result>")
rescue Solr::RequestException => exception
assert_equal "ERROR:", exception.message
assert_equal exception.message, exception.to_s
assert_equal "400", exception.code
end
end
end