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.
|
|
|
|
|
|
|
|
require 'test/unit'
|
|
|
|
require 'solr'
|
|
|
|
|
2007-01-12 22:36:10 -05:00
|
|
|
class BadRequest < Solr::Request::Base
|
|
|
|
end
|
|
|
|
|
2007-01-02 23:57:00 -05:00
|
|
|
class RequestTest < Test::Unit::TestCase
|
|
|
|
|
2007-01-12 21:53:39 -05:00
|
|
|
def test_commit_request
|
|
|
|
request = Solr::Request::Commit.new
|
|
|
|
assert_equal :xml, request.response_format
|
|
|
|
assert_equal 'update', request.handler
|
|
|
|
assert_equal '<commit/>', request.to_s
|
2007-01-02 23:57:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_doc_request
|
2007-01-12 21:53:39 -05:00
|
|
|
request = Solr::Request::AddDocument.new(:title => "title")
|
|
|
|
assert_equal "<add><doc><field name='title'>title</field></doc></add>", request.to_s
|
|
|
|
assert :xml, request.response_format
|
|
|
|
assert 'update', request.handler
|
2007-01-12 23:31:09 -05:00
|
|
|
|
|
|
|
assert_raise(RuntimeError) do
|
|
|
|
Solr::Request::AddDocument.new("invalid")
|
|
|
|
end
|
2007-01-02 23:57:00 -05:00
|
|
|
end
|
2007-01-12 21:53:39 -05:00
|
|
|
|
|
|
|
def test_select_request
|
|
|
|
request = Solr::Request::Select.new('belkin')
|
|
|
|
assert_equal :ruby, request.response_format
|
|
|
|
assert 'select', request.handler
|
|
|
|
assert 'belkin', request.to_hash['q']
|
|
|
|
assert_match /q=belkin/, request.to_s
|
2007-01-11 08:54:22 -05:00
|
|
|
end
|
2007-01-12 22:36:10 -05:00
|
|
|
|
|
|
|
def test_ping_request
|
|
|
|
request = Solr::Request::Ping.new
|
|
|
|
assert_equal :xml, request.response_format
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_bad_request_class
|
|
|
|
assert_raise(RuntimeError) do
|
|
|
|
BadRequest.new.response_format
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raise(RuntimeError) do
|
|
|
|
BadRequest.new.handler
|
|
|
|
end
|
|
|
|
end
|
2007-01-12 21:53:39 -05:00
|
|
|
|
2007-01-02 23:57:00 -05:00
|
|
|
end
|