Rev 30 | Blame | Compare with Previous | Last modification | View Log | RSS feed
## Licensed to the Apache Software Foundation (ASF) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The ASF licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing,# software distributed under the License is distributed on an# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY# KIND, either express or implied. See the License for the# specific language governing permissions and limitations# under the License.#require File.dirname(__FILE__) + '/spec_helper'class ThriftExceptionSpec < Spec::ExampleGroupinclude Thriftdescribe Exception doit "should have an accessible message" doe = Exception.new("test message")e.message.should == "test message"endenddescribe ApplicationException doit "should inherit from Thrift::Exception" doApplicationException.superclass.should == Exceptionendit "should have an accessible type and message" doe = ApplicationException.newe.type.should == ApplicationException::UNKNOWNe.message.should be_nile = ApplicationException.new(ApplicationException::UNKNOWN_METHOD, "test message")e.type.should == ApplicationException::UNKNOWN_METHODe.message.should == "test message"endit "should read a struct off of a protocol" doprot = mock("MockProtocol")prot.should_receive(:read_struct_begin).orderedprot.should_receive(:read_field_begin).exactly(3).times.and_return(["message", Types::STRING, 1],["type", Types::I32, 2],[nil, Types::STOP, 0])prot.should_receive(:read_string).ordered.and_return "test message"prot.should_receive(:read_i32).ordered.and_return ApplicationException::BAD_SEQUENCE_IDprot.should_receive(:read_field_end).exactly(2).timesprot.should_receive(:read_struct_end).orderede = ApplicationException.newe.read(prot)e.message.should == "test message"e.type.should == ApplicationException::BAD_SEQUENCE_IDendit "should skip bad fields when reading a struct" doprot = mock("MockProtocol")prot.should_receive(:read_struct_begin).orderedprot.should_receive(:read_field_begin).exactly(5).times.and_return(["type", Types::I32, 2],["type", Types::STRING, 2],["message", Types::MAP, 1],["message", Types::STRING, 3],[nil, Types::STOP, 0])prot.should_receive(:read_i32).and_return ApplicationException::INVALID_MESSAGE_TYPEprot.should_receive(:skip).with(Types::STRING).twiceprot.should_receive(:skip).with(Types::MAP)prot.should_receive(:read_field_end).exactly(4).timesprot.should_receive(:read_struct_end).orderede = ApplicationException.newe.read(prot)e.message.should be_nile.type.should == ApplicationException::INVALID_MESSAGE_TYPEendit "should write a Thrift::ApplicationException struct to the oprot" doprot = mock("MockProtocol")prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").orderedprot.should_receive(:write_field_begin).with("message", Types::STRING, 1).orderedprot.should_receive(:write_string).with("test message").orderedprot.should_receive(:write_field_begin).with("type", Types::I32, 2).orderedprot.should_receive(:write_i32).with(ApplicationException::UNKNOWN_METHOD).orderedprot.should_receive(:write_field_end).twiceprot.should_receive(:write_field_stop).orderedprot.should_receive(:write_struct_end).orderede = ApplicationException.new(ApplicationException::UNKNOWN_METHOD, "test message")e.write(prot)endit "should skip nil fields when writing to the oprot" doprot = mock("MockProtocol")prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").orderedprot.should_receive(:write_field_begin).with("message", Types::STRING, 1).orderedprot.should_receive(:write_string).with("test message").orderedprot.should_receive(:write_field_end).orderedprot.should_receive(:write_field_stop).orderedprot.should_receive(:write_struct_end).orderede = ApplicationException.new(nil, "test message")e.write(prot)prot = mock("MockProtocol")prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").orderedprot.should_receive(:write_field_begin).with("type", Types::I32, 2).orderedprot.should_receive(:write_i32).with(ApplicationException::BAD_SEQUENCE_ID).orderedprot.should_receive(:write_field_end).orderedprot.should_receive(:write_field_stop).orderedprot.should_receive(:write_struct_end).orderede = ApplicationException.new(ApplicationException::BAD_SEQUENCE_ID)e.write(prot)prot = mock("MockProtocol")prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").orderedprot.should_receive(:write_field_stop).orderedprot.should_receive(:write_struct_end).orderede = ApplicationException.new(nil)e.write(prot)endenddescribe ProtocolException doit "should have an accessible type" doprot = ProtocolException.new(ProtocolException::SIZE_LIMIT, "message")prot.type.should == ProtocolException::SIZE_LIMITprot.message.should == "message"endendend