2008-06-18 01:05:47 +00:00
|
|
|
require File.dirname(__FILE__) + '/spec_helper'
|
|
|
|
|
2008-06-18 01:08:05 +00:00
|
|
|
class ThriftProcessorSpec < Spec::ExampleGroup
|
2008-06-18 01:05:47 +00:00
|
|
|
include Thrift
|
|
|
|
|
|
|
|
class ProcessorSpec
|
|
|
|
include Thrift::Processor
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "Processor" do
|
|
|
|
before(:each) do
|
|
|
|
@processor = ProcessorSpec.new(mock("MockHandler"))
|
|
|
|
@prot = mock("MockProtocol")
|
|
|
|
end
|
|
|
|
|
|
|
|
def mock_trans(obj)
|
|
|
|
obj.should_receive(:trans).ordered.and_return do
|
|
|
|
mock("trans").tee do |trans|
|
|
|
|
trans.should_receive(:flush).ordered
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should call process_<message> when it receives that message" do
|
|
|
|
@prot.should_receive(:read_message_begin).ordered.and_return ['testMessage', MessageTypes::CALL, 17]
|
|
|
|
@processor.should_receive(:process_testMessage).with(17, @prot, @prot).ordered
|
|
|
|
@processor.process(@prot, @prot).should == true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should raise an ApplicationException when the received message cannot be processed" do
|
|
|
|
@prot.should_receive(:read_message_begin).ordered.and_return ['testMessage', MessageTypes::CALL, 4]
|
|
|
|
@prot.should_receive(:skip).with(Types::STRUCT).ordered
|
|
|
|
@prot.should_receive(:read_message_end).ordered
|
|
|
|
@prot.should_receive(:write_message_begin).with('testMessage', MessageTypes::EXCEPTION, 4).ordered
|
|
|
|
ApplicationException.should_receive(:new).with(ApplicationException::UNKNOWN_METHOD, "Unknown function testMessage").and_return do
|
|
|
|
mock(ApplicationException).tee do |e|
|
|
|
|
e.should_receive(:write).with(@prot).ordered
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@prot.should_receive(:write_message_end).ordered
|
|
|
|
mock_trans(@prot)
|
|
|
|
@processor.process(@prot, @prot)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should pass args off to the args class" do
|
|
|
|
args_class = mock("MockArgsClass")
|
|
|
|
args = mock("#<MockArgsClass:mock>").tee do |args|
|
|
|
|
args.should_receive(:read).with(@prot).ordered
|
|
|
|
end
|
|
|
|
args_class.should_receive(:new).and_return args
|
|
|
|
@prot.should_receive(:read_message_end).ordered
|
|
|
|
@processor.read_args(@prot, args_class).should eql(args)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should write out a reply when asked" do
|
|
|
|
@prot.should_receive(:write_message_begin).with('testMessage', MessageTypes::REPLY, 23).ordered
|
|
|
|
result = mock("MockResult")
|
|
|
|
result.should_receive(:write).with(@prot).ordered
|
|
|
|
@prot.should_receive(:write_message_end).ordered
|
|
|
|
mock_trans(@prot)
|
|
|
|
@processor.write_result(result, @prot, 'testMessage', 23)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|