mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
6f5a7b2004
seperate out protocol marshaling into a small 'ws' library in vendor, so that AWS itself only does integration with ActionPack, and so we can keep protocol specific code in AWS proper to a minimum. refactor unit tests to get 95% code coverage (for a baseline). be far more relaxed about the types given to us by the remote side, don't do any poor man's type checking, just try to cast and marshal to the correct types if possible, and if not, return what they gave us anyway. this should make interoperating with fuzzy XML-RPC clients easier. if exception reporting is turned on, do best-effort error responses, so that we can avoid "Internal protocol error" with no details if there is a bug in AWS itself. also perform extensive cleanups on AWS proper. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@800 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
68 lines
1.8 KiB
Ruby
68 lines
1.8 KiB
Ruby
require File.dirname(__FILE__) + '/abstract_unit'
|
|
|
|
module Nested
|
|
class StructClass
|
|
attr_accessor :name
|
|
attr_accessor :version
|
|
|
|
def initialize
|
|
@name = 5
|
|
@version = "1.0"
|
|
end
|
|
|
|
def ==(other)
|
|
@name == other.name && @version == other.version
|
|
end
|
|
end
|
|
end
|
|
|
|
module EncodingTest
|
|
def setup
|
|
@call_signature = [:int, :bool, :string, :float, [:time], Nested::StructClass]
|
|
@call_params = [1, true, "string", 5.0, [Time.now], Nested::StructClass.new]
|
|
@response_signature = [:string]
|
|
@response_param = "hello world"
|
|
test_setup
|
|
end
|
|
|
|
def test_abstract
|
|
obj = WS::Encoding::AbstractEncoding.new
|
|
assert_raises(NotImplementedError) do
|
|
obj.encode_rpc_call(nil, nil)
|
|
end
|
|
assert_raises(NotImplementedError) do
|
|
obj.decode_rpc_call(nil)
|
|
end
|
|
assert_raises(NotImplementedError) do
|
|
obj.encode_rpc_response(nil, nil)
|
|
end
|
|
assert_raises(NotImplementedError) do
|
|
obj.decode_rpc_response(nil)
|
|
end
|
|
end
|
|
|
|
def encode_rpc_call(method_name, signature, params)
|
|
params = params.dup
|
|
(0..(signature.length-1)).each do |i|
|
|
type_binding = @marshaler.register_type(signature[i])
|
|
info = WS::ParamInfo.create(signature[i], i, type_binding)
|
|
params[i] = @marshaler.marshal(WS::Param.new(params[i], info))
|
|
end
|
|
@encoder.encode_rpc_call(method_name, params)
|
|
end
|
|
|
|
def decode_rpc_call(obj)
|
|
@encoder.decode_rpc_call(obj)
|
|
end
|
|
|
|
def encode_rpc_response(method_name, signature, param)
|
|
type_binding = @marshaler.register_type(signature[0])
|
|
info = WS::ParamInfo.create(signature[0], 0, type_binding)
|
|
param = @marshaler.marshal(WS::Param.new(param, info))
|
|
@encoder.encode_rpc_response(method_name, param)
|
|
end
|
|
|
|
def decode_rpc_response(obj)
|
|
@encoder.decode_rpc_response(obj)
|
|
end
|
|
end
|