2009-03-30 21:35:00 +00:00
|
|
|
#
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
# or more contributor license agreements. See the NOTICE file
|
|
|
|
# distributed with this work for additional information
|
|
|
|
# regarding copyright ownership. 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.
|
|
|
|
#
|
|
|
|
|
2012-09-28 01:59:04 +00:00
|
|
|
require 'spec_helper'
|
2008-06-18 01:11:18 +00:00
|
|
|
|
2012-09-28 01:59:04 +00:00
|
|
|
describe 'Thrift::HTTPClientTransport' do
|
2008-06-18 01:11:18 +00:00
|
|
|
|
2012-09-28 01:59:04 +00:00
|
|
|
describe Thrift::HTTPClientTransport do
|
2008-06-18 01:11:18 +00:00
|
|
|
before(:each) do
|
2012-09-28 01:59:04 +00:00
|
|
|
@client = Thrift::HTTPClientTransport.new("http://my.domain.com/path/to/service?param=value")
|
2008-06-18 01:11:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should always be open" do
|
|
|
|
@client.should be_open
|
|
|
|
@client.close
|
|
|
|
@client.should be_open
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should post via HTTP and return the results" do
|
|
|
|
@client.write "a test"
|
|
|
|
@client.write " frame"
|
|
|
|
Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
|
2012-10-01 18:42:23 +00:00
|
|
|
mock("Net::HTTP").tap do |http|
|
2008-10-16 19:14:47 +00:00
|
|
|
http.should_receive(:use_ssl=).with(false)
|
2012-05-11 18:08:58 +00:00
|
|
|
http.should_receive(:post).with("/path/to/service?param=value", "a test frame", {"Content-Type"=>"application/x-thrift"}).and_return do
|
2012-10-01 18:42:23 +00:00
|
|
|
mock("Net::HTTPOK").tap do |response|
|
2012-05-11 18:08:58 +00:00
|
|
|
response.should_receive(:body).and_return "data"
|
|
|
|
end
|
|
|
|
end
|
2008-06-18 01:11:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
@client.flush
|
|
|
|
@client.read(10).should == "data"
|
|
|
|
end
|
2010-08-05 22:12:01 +00:00
|
|
|
|
|
|
|
it "should send custom headers if defined" do
|
|
|
|
@client.write "test"
|
|
|
|
custom_headers = {"Cookie" => "Foo"}
|
|
|
|
headers = {"Content-Type"=>"application/x-thrift"}.merge(custom_headers)
|
|
|
|
|
|
|
|
@client.add_headers(custom_headers)
|
|
|
|
Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
|
2012-10-01 18:42:23 +00:00
|
|
|
mock("Net::HTTP").tap do |http|
|
2010-08-05 22:12:01 +00:00
|
|
|
http.should_receive(:use_ssl=).with(false)
|
2012-05-11 18:08:58 +00:00
|
|
|
http.should_receive(:post).with("/path/to/service?param=value", "test", headers).and_return do
|
2012-10-01 18:42:23 +00:00
|
|
|
mock("Net::HTTPOK").tap do |response|
|
2012-05-11 18:08:58 +00:00
|
|
|
response.should_receive(:body).and_return "data"
|
|
|
|
end
|
|
|
|
end
|
2010-08-05 22:12:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
@client.flush
|
|
|
|
end
|
2008-06-18 01:11:18 +00:00
|
|
|
end
|
|
|
|
end
|