Skip to content

Apache Lucene open-source search software

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

Erik Hatcher0b3fc2da6be4
diff --git a/client/ruby/solrb/lib/solr/connection.rb b/client/ruby/solrb/lib/solr/connection.rb
index be5fa139a76..f16e5d192dd 100755
--- a/client/ruby/solrb/lib/solr/connection.rb
+++ b/client/ruby/solrb/lib/solr/connection.rb
@@ -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
diff --git a/client/ruby/solrb/test/connection_test.rb b/client/ruby/solrb/test/connection_test.rb
index dd764535571..9420911a55e 100755
--- a/client/ruby/solrb/test/connection_test.rb
+++ b/client/ruby/solrb/test/connection_test.rb
@@ -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")
diff --git a/client/ruby/solrb/test/test_helper.rb b/client/ruby/solrb/test/test_helper.rb
index 5ae15ce1ae9..e6912b362c8 100644
--- a/client/ruby/solrb/test/test_helper.rb
+++ b/client/ruby/solrb/test/test_helper.rb
@@ -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
+