1 # Copyright 2010 Google Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
19 require 'google/api_client/transport/http_transport'
21 def assemble_body_string(body)
29 describe Google::APIClient::HTTPTransport, 'in the default configuration' do
31 @http = Google::APIClient::HTTPTransport.new
34 it 'should build a valid GET request' do
35 method, uri, headers, body =
36 @http.build_request(:get, "http://www.example.com/")
37 body_string = assemble_body_string(body)
38 method.should == "GET"
39 uri.should === "http://www.example.com/"
40 headers.keys.should_not include("Content-Length")
41 body_string.should == ""
44 it 'should build a valid POST request' do
45 method, uri, headers, body = @http.build_request(
46 :post, "http://www.example.com/", :body => "A body."
48 body_string = assemble_body_string(body)
49 method.should == "POST"
50 uri.should === "http://www.example.com/"
51 headers["Content-Length"].should == "7"
52 body_string.should == "A body."
55 it 'should build a valid PUT request' do
56 method, uri, headers, body = @http.build_request(
57 :put, "http://www.example.com/", :body => "A body."
59 body_string = assemble_body_string(body)
60 method.should == "PUT"
61 uri.should === "http://www.example.com/"
62 headers["Content-Length"].should == "7"
63 body_string.should == "A body."
66 it 'should build a valid DELETE request' do
67 method, uri, headers, body =
68 @http.build_request(:delete, "http://www.example.com/")
69 body_string = assemble_body_string(body)
70 method.should == "DELETE"
71 uri.should === "http://www.example.com/"
72 headers.keys.should_not include("Content-Length")
73 body_string.should == ""
76 it 'should not build a BOGUS request' do
78 @http.build_request(:bogus, "http://www.example.com/")
79 end).should raise_error(ArgumentError)
83 describe Google::APIClient::HTTPTransport,
84 'with a certificate store and connection pool' do
86 @http = Google::APIClient::HTTPTransport.new(
87 :cert_store => OpenSSL::X509::Store.new,
89 "http://www.example.com" => Net::HTTP.new("www.example.com", 80)
94 it 'should have the correct certificate store' do
95 # TODO(bobaman) Write a real test
96 @http.cert_store.should_not == nil
99 it 'should have the correct connection pool' do
100 @http.connection_pool.keys.should include("http://www.example.com")