2007-01-02 23:57:00 -05:00
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
# (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2007-01-08 15:23:28 -05:00
|
|
|
require 'test/unit'
|
|
|
|
require 'solr'
|
|
|
|
|
2007-01-12 23:31:09 -05:00
|
|
|
class BadRequest < Solr::Request::Select
|
|
|
|
def response_format
|
|
|
|
:invalid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-01-12 21:53:39 -05:00
|
|
|
class ServerTest < Test::Unit::TestCase
|
2007-01-08 15:23:28 -05:00
|
|
|
include Solr
|
2007-01-08 16:50:30 -05:00
|
|
|
|
|
|
|
def setup
|
2007-01-12 21:53:39 -05:00
|
|
|
@connection = Connection.new("http://localhost:8888/solr")
|
2007-01-08 16:50:30 -05:00
|
|
|
end
|
2007-01-08 15:23:28 -05:00
|
|
|
|
2007-01-12 23:31:09 -05:00
|
|
|
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)
|
2007-01-11 10:42:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-01-08 15:23:28 -05:00
|
|
|
def test_commit
|
2007-01-12 21:53:39 -05:00
|
|
|
response = @connection.send(Solr::Request::Commit.new)
|
2007-01-08 15:23:28 -05:00
|
|
|
assert_equal "<result status=\"0\"></result>", response.raw_response
|
2007-01-02 23:57:00 -05:00
|
|
|
end
|
2007-01-08 16:50:30 -05:00
|
|
|
|
2007-01-12 23:31:09 -05:00
|
|
|
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
|
|
|
|
|
2007-01-08 16:50:30 -05:00
|
|
|
def test_escaping
|
2007-01-12 21:53:39 -05:00
|
|
|
doc = Solr::Document.new :id => 47, :ruby_t => 'puts "ouch!"'
|
|
|
|
@connection.send(Solr::Request::AddDocument.new(doc))
|
|
|
|
@connection.commit
|
2007-01-08 16:50:30 -05:00
|
|
|
|
2007-01-12 21:53:39 -05:00
|
|
|
request = Solr::Request::Select.new 'ruby_t:ouch'
|
2007-01-08 16:50:30 -05:00
|
|
|
result = @connection.send(request)
|
|
|
|
|
2007-01-12 21:53:39 -05:00
|
|
|
assert_match /puts/, result.raw_response
|
2007-01-08 16:50:30 -05:00
|
|
|
end
|
2007-01-12 21:53:39 -05:00
|
|
|
|
2007-01-02 23:57:00 -05:00
|
|
|
end
|