David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame^] | 1 | # |
| 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 | |
Kevin Clark | dd33025 | 2008-06-18 01:11:18 +0000 | [diff] [blame] | 20 | require File.dirname(__FILE__) + '/spec_helper' |
| 21 | require 'thrift/transport/httpclient' |
| 22 | |
| 23 | class ThriftHTTPClientSpec < Spec::ExampleGroup |
| 24 | include Thrift |
| 25 | |
| 26 | describe HTTPClient do |
| 27 | before(:each) do |
| 28 | @client = HTTPClient.new("http://my.domain.com/path/to/service") |
| 29 | end |
| 30 | |
| 31 | it "should always be open" do |
| 32 | @client.should be_open |
| 33 | @client.close |
| 34 | @client.should be_open |
| 35 | end |
| 36 | |
| 37 | it "should post via HTTP and return the results" do |
| 38 | @client.write "a test" |
| 39 | @client.write " frame" |
| 40 | Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do |
| 41 | mock("Net::HTTP").tee do |http| |
Kevin Clark | 6ca3881 | 2008-10-16 19:14:47 +0000 | [diff] [blame] | 42 | http.should_receive(:use_ssl=).with(false) |
| 43 | http.should_receive(:post).with("/path/to/service", "a test frame", {"Content-Type"=>"application/x-thrift"}).and_return([nil, "data"]) |
Kevin Clark | dd33025 | 2008-06-18 01:11:18 +0000 | [diff] [blame] | 44 | end |
| 45 | end |
| 46 | @client.flush |
| 47 | @client.read(10).should == "data" |
| 48 | end |
| 49 | end |
| 50 | end |