mirror of https://github.com/apache/lucene.git
add tests to bring coverage back to 100%
git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@495836 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
56c1269ff5
commit
01c454c9a2
|
@ -13,6 +13,12 @@
|
|||
require 'test/unit'
|
||||
require 'solr'
|
||||
|
||||
class BadRequest < Solr::Request::Select
|
||||
def response_format
|
||||
:invalid
|
||||
end
|
||||
end
|
||||
|
||||
class ServerTest < Test::Unit::TestCase
|
||||
include Solr
|
||||
|
||||
|
@ -20,10 +26,17 @@ class ServerTest < Test::Unit::TestCase
|
|||
@connection = Connection.new("http://localhost:8888/solr")
|
||||
end
|
||||
|
||||
def test_error
|
||||
conn = Solr::Connection.new 'http://localhost:9999/poopville'
|
||||
assert_raise(Net::HTTPFatalError) do
|
||||
@connection.send(Solr::Request::Ping.new)
|
||||
def test_bad_connection
|
||||
conn = Solr::Connection.new 'http://localhost:9999/invalid'
|
||||
assert_raise(Errno::ECONNREFUSED) do
|
||||
conn.send(Solr::Request::Ping.new)
|
||||
end
|
||||
end
|
||||
|
||||
def test_bad_url
|
||||
conn = Solr::Connection.new 'http://localhost:8888/invalid'
|
||||
assert_raise(Net::HTTPServerException) do
|
||||
conn.send(Solr::Request::Ping.new)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -32,6 +45,18 @@ class ServerTest < Test::Unit::TestCase
|
|||
assert_equal "<result status=\"0\"></result>", response.raw_response
|
||||
end
|
||||
|
||||
def test_ping
|
||||
response = @connection.ping
|
||||
assert_match /ping/, response.raw_response
|
||||
end
|
||||
|
||||
def test_invalid_response_format
|
||||
request = BadRequest.new("invalid")
|
||||
assert_raise(RuntimeError) do
|
||||
@connection.send(request)
|
||||
end
|
||||
end
|
||||
|
||||
def test_escaping
|
||||
doc = Solr::Document.new :id => 47, :ruby_t => 'puts "ouch!"'
|
||||
@connection.send(Solr::Request::AddDocument.new(doc))
|
||||
|
|
|
@ -30,12 +30,26 @@ class DocumentTest < Test::Unit::TestCase
|
|||
doc << Solr::Field.new(:creator => 'Otis Gospodnetic')
|
||||
assert "<doc><field name='creator'>Erik Hatcher</field><field name='creator'>Otis Gospodnetic</field></doc>", doc.to_xml.to_s
|
||||
end
|
||||
|
||||
def test_bad_doc
|
||||
doc = Solr::Document.new
|
||||
assert_raise(RuntimeError) do
|
||||
doc << "invalid"
|
||||
end
|
||||
end
|
||||
|
||||
def test_hash_shorthand
|
||||
doc = Solr::Document.new :creator => 'Erik Hatcher', :title => 'Lucene in Action'
|
||||
assert_equal 'Erik Hatcher', doc[:creator]
|
||||
assert_equal 'Lucene in Action', doc[:title]
|
||||
assert_equal nil, doc[:foo]
|
||||
|
||||
doc = Solr::Document.new
|
||||
doc << {:creator => 'Erik Hatcher', :title => 'Lucene in Action'}
|
||||
doc[:subject] = 'Search'
|
||||
assert_equal 'Erik Hatcher', doc[:creator]
|
||||
assert_equal 'Lucene in Action', doc[:title]
|
||||
assert_equal 'Search', doc[:subject]
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -30,6 +30,10 @@ class RequestTest < Test::Unit::TestCase
|
|||
assert_equal "<add><doc><field name='title'>title</field></doc></add>", request.to_s
|
||||
assert :xml, request.response_format
|
||||
assert 'update', request.handler
|
||||
|
||||
assert_raise(RuntimeError) do
|
||||
Solr::Request::AddDocument.new("invalid")
|
||||
end
|
||||
end
|
||||
|
||||
def test_select_request
|
||||
|
|
Loading…
Reference in New Issue