Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
require File.dirname(__FILE__) + '/binary_protocol_spec_shared'
22
 
23
class ThriftBinaryProtocolSpec < Spec::ExampleGroup
24
  include Thrift
25
 
26
  describe BinaryProtocol do
27
    it_should_behave_like 'a binary protocol'
28
 
29
    def protocol_class
30
      BinaryProtocol
31
    end
32
 
33
    it "should read a message header" do
34
      @trans.should_receive(:read_all).exactly(2).times.and_return(
35
        [protocol_class.const_get(:VERSION_1) | Thrift::MessageTypes::REPLY].pack('N'),
36
        [42].pack('N')
37
      )      
38
      @prot.should_receive(:read_string).and_return('testMessage')
39
      @prot.read_message_begin.should == ['testMessage', Thrift::MessageTypes::REPLY, 42]
40
    end
41
 
42
    it "should raise an exception if the message header has the wrong version" do
43
      @prot.should_receive(:read_i32).and_return(-1)
44
      lambda { @prot.read_message_begin }.should raise_error(Thrift::ProtocolException, 'Missing version identifier') do |e|
45
        e.type == Thrift::ProtocolException::BAD_VERSION
46
      end
47
    end
48
 
49
    it "should raise an exception if the message header does not exist and strict_read is enabled" do
50
      @prot.should_receive(:read_i32).and_return(42)
51
      @prot.should_receive(:strict_read).and_return(true)
52
      lambda { @prot.read_message_begin }.should raise_error(Thrift::ProtocolException, 'No version identifier, old protocol client?') do |e|        
53
        e.type == Thrift::ProtocolException::BAD_VERSION
54
      end
55
    end
56
  end
57
 
58
  describe BinaryProtocolFactory do
59
    it "should create a BinaryProtocol" do
60
      BinaryProtocolFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(BinaryProtocol)
61
    end
62
  end
63
end