blob: 30561ab58478b1f4bce2869b5026fe3e4f0d304d [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18#
19
Jake Farrell89414582011-11-10 00:53:17 +000020require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
Kevin Clarkdd330252008-06-18 01:11:18 +000021
Bryan Duxburyd1d15422009-04-04 00:58:03 +000022class ThriftHTTPClientTransportSpec < Spec::ExampleGroup
Kevin Clarkdd330252008-06-18 01:11:18 +000023 include Thrift
24
Bryan Duxburyd1d15422009-04-04 00:58:03 +000025 describe HTTPClientTransport do
Kevin Clarkdd330252008-06-18 01:11:18 +000026 before(:each) do
Bryan Duxbury3e60fa62010-03-02 18:34:00 +000027 @client = HTTPClientTransport.new("http://my.domain.com/path/to/service?param=value")
Kevin Clarkdd330252008-06-18 01:11:18 +000028 end
29
30 it "should always be open" do
31 @client.should be_open
32 @client.close
33 @client.should be_open
34 end
35
36 it "should post via HTTP and return the results" do
37 @client.write "a test"
38 @client.write " frame"
39 Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
40 mock("Net::HTTP").tee do |http|
Kevin Clark6ca38812008-10-16 19:14:47 +000041 http.should_receive(:use_ssl=).with(false)
Roger Meiera30930f2012-05-11 18:08:58 +000042 http.should_receive(:post).with("/path/to/service?param=value", "a test frame", {"Content-Type"=>"application/x-thrift"}).and_return do
43 mock("Net::HTTPOK").tee do |response|
44 response.should_receive(:body).and_return "data"
45 end
46 end
Kevin Clarkdd330252008-06-18 01:11:18 +000047 end
48 end
49 @client.flush
50 @client.read(10).should == "data"
51 end
Bryan Duxburyad776c12010-08-05 22:12:01 +000052
53 it "should send custom headers if defined" do
54 @client.write "test"
55 custom_headers = {"Cookie" => "Foo"}
56 headers = {"Content-Type"=>"application/x-thrift"}.merge(custom_headers)
57
58 @client.add_headers(custom_headers)
59 Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
60 mock("Net::HTTP").tee do |http|
61 http.should_receive(:use_ssl=).with(false)
Roger Meiera30930f2012-05-11 18:08:58 +000062 http.should_receive(:post).with("/path/to/service?param=value", "test", headers).and_return do
63 mock("Net::HTTPOK").tee do |response|
64 response.should_receive(:body).and_return "data"
65 end
66 end
Bryan Duxburyad776c12010-08-05 22:12:01 +000067 end
68 end
69 @client.flush
70 end
Kevin Clarkdd330252008-06-18 01:11:18 +000071 end
72end