| 30 |
ashish |
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 |
|
|
|
20 |
require File.dirname(__FILE__) + '/spec_helper'
|
|
|
21 |
|
|
|
22 |
class ThriftHTTPClientTransportSpec < Spec::ExampleGroup
|
|
|
23 |
include Thrift
|
|
|
24 |
|
|
|
25 |
describe HTTPClientTransport do
|
|
|
26 |
before(:each) do
|
|
|
27 |
@client = HTTPClientTransport.new("http://my.domain.com/path/to/service")
|
|
|
28 |
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|
|
|
|
41 |
http.should_receive(:use_ssl=).with(false)
|
|
|
42 |
http.should_receive(:post).with("/path/to/service", "a test frame", {"Content-Type"=>"application/x-thrift"}).and_return([nil, "data"])
|
|
|
43 |
end
|
|
|
44 |
end
|
|
|
45 |
@client.flush
|
|
|
46 |
@client.read(10).should == "data"
|
|
|
47 |
end
|
|
|
48 |
end
|
|
|
49 |
end
|