first attempt at making a mock Solr::Connection base test case

git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@492628 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2007-01-04 16:40:07 +00:00
parent e534b04f31
commit 0b3fc2da6b
3 changed files with 26 additions and 2 deletions

View File

@ -21,13 +21,19 @@ module Solr
end
def send(request)
data = post(request)
return request.response_format == :ruby ? RubyResponse.new(data) : XmlResponse.new(data)
end
def post(request)
post = Net::HTTP::Post.new(request.url_path)
post.body = request.to_http_body
post.content_type = 'application/x-www-form-urlencoded; charset=utf-8'
response = Net::HTTP.start(@url.host, @url.port) do |http|
http.request(post)
end
return request.response_format == :ruby ? RubyResponse.new(response.body) : XmlResponse.new(response.body)
return response.body
end
end
end

View File

@ -13,7 +13,22 @@
require 'test/unit'
require 'solr'
class ConnectionTest < Test::Unit::TestCase
module Solr
class Connection
def post(request)
"foo"
end
end
class MockSolrBaseTest < Test::Unit::TestCase
def test_mock
connection = Connection.new("http://localhost:9999")
assert_equal "foo", connection.post(UpdateRequest.new("bogus"))
end
end
end
class ConnectionTest < Solr::MockSolrBaseTest
def test_connection_initialize
request = Solr::UpdateRequest.new("<commit/>")
connection = Solr::Connection.new("http://localhost:8983")

View File

@ -10,6 +10,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
require 'test/unit'
def start_solr_server
Dir.chdir(File.dirname(__FILE__) + '/../solr') do
puts "starting solr server"
@ -32,3 +34,4 @@ def stop_solr_server
puts "stopping solr server"
Process.kill('TERM', $SOLR_PID)
end