rack-amf 0.0.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +18 -9
- data/Rakefile +23 -38
- data/lib/rack/amf/environment.rb +5 -8
- data/lib/rack/amf/middleware/pass_through.rb +5 -4
- data/lib/rack/amf/middleware/service_manager.rb +11 -3
- data/lib/rack/amf/middleware.rb +2 -1
- data/lib/rack/amf/request.rb +3 -16
- data/lib/rack/amf/response.rb +8 -67
- data/lib/rack/amf.rb +41 -1
- data/spec/{rack/service_manager_spec.rb → service_manager_spec.rb} +1 -2
- data/spec/spec.opts +2 -1
- data/spec/spec_helper.rb +1 -24
- metadata +19 -84
- data/lib/amf/class_mapping.rb +0 -211
- data/lib/amf/common.rb +0 -28
- data/lib/amf/constants.rb +0 -47
- data/lib/amf/pure/deserializer.rb +0 -361
- data/lib/amf/pure/io_helpers.rb +0 -94
- data/lib/amf/pure/remoting.rb +0 -120
- data/lib/amf/pure/serializer.rb +0 -327
- data/lib/amf/pure.rb +0 -14
- data/lib/amf/values/array_collection.rb +0 -9
- data/lib/amf/values/messages.rb +0 -133
- data/lib/amf/values/typed_hash.rb +0 -13
- data/lib/amf/version.rb +0 -9
- data/lib/amf.rb +0 -17
- data/spec/amf/class_mapping_set_spec.rb +0 -34
- data/spec/amf/class_mapping_spec.rb +0 -120
- data/spec/amf/deserializer_spec.rb +0 -311
- data/spec/amf/remoting_spec.rb +0 -51
- data/spec/amf/serializer_spec.rb +0 -328
- data/spec/amf/values/array_collection_spec.rb +0 -6
- data/spec/amf/values/messages_spec.rb +0 -31
- data/spec/fixtures/objects/amf0-boolean.bin +0 -1
- data/spec/fixtures/objects/amf0-date.bin +0 -0
- data/spec/fixtures/objects/amf0-ecma-ordinal-array.bin +0 -0
- data/spec/fixtures/objects/amf0-hash.bin +0 -0
- data/spec/fixtures/objects/amf0-null.bin +0 -1
- data/spec/fixtures/objects/amf0-number.bin +0 -0
- data/spec/fixtures/objects/amf0-object.bin +0 -0
- data/spec/fixtures/objects/amf0-ref-test.bin +0 -0
- data/spec/fixtures/objects/amf0-strict-array.bin +0 -0
- data/spec/fixtures/objects/amf0-string.bin +0 -0
- data/spec/fixtures/objects/amf0-typed-object.bin +0 -0
- data/spec/fixtures/objects/amf0-undefined.bin +0 -1
- data/spec/fixtures/objects/amf0-untyped-object.bin +0 -0
- data/spec/fixtures/objects/amf3-0.bin +0 -0
- data/spec/fixtures/objects/amf3-arrayRef.bin +0 -1
- data/spec/fixtures/objects/amf3-bigNum.bin +0 -0
- data/spec/fixtures/objects/amf3-date.bin +0 -0
- data/spec/fixtures/objects/amf3-datesRef.bin +0 -0
- data/spec/fixtures/objects/amf3-dynObject.bin +0 -2
- data/spec/fixtures/objects/amf3-emptyArray.bin +0 -1
- data/spec/fixtures/objects/amf3-emptyArrayRef.bin +0 -1
- data/spec/fixtures/objects/amf3-emptyStringRef.bin +0 -1
- data/spec/fixtures/objects/amf3-false.bin +0 -1
- data/spec/fixtures/objects/amf3-graphMember.bin +0 -0
- data/spec/fixtures/objects/amf3-hash.bin +0 -2
- data/spec/fixtures/objects/amf3-largeMax.bin +0 -0
- data/spec/fixtures/objects/amf3-largeMin.bin +0 -0
- data/spec/fixtures/objects/amf3-max.bin +0 -1
- data/spec/fixtures/objects/amf3-min.bin +0 -0
- data/spec/fixtures/objects/amf3-mixedArray.bin +0 -11
- data/spec/fixtures/objects/amf3-null.bin +0 -1
- data/spec/fixtures/objects/amf3-objRef.bin +0 -0
- data/spec/fixtures/objects/amf3-primArray.bin +0 -1
- data/spec/fixtures/objects/amf3-string.bin +0 -1
- data/spec/fixtures/objects/amf3-stringRef.bin +0 -0
- data/spec/fixtures/objects/amf3-symbol.bin +0 -1
- data/spec/fixtures/objects/amf3-true.bin +0 -1
- data/spec/fixtures/objects/amf3-typedObject.bin +0 -2
- data/spec/fixtures/request/acknowledge-response.bin +0 -0
- data/spec/fixtures/request/amf0-error-response.bin +0 -0
- data/spec/fixtures/request/commandMessage.bin +0 -0
- data/spec/fixtures/request/remotingMessage.bin +0 -0
- data/spec/fixtures/request/simple-response.bin +0 -0
- data/spec/rack/request_spec.rb +0 -6
- data/spec/rack/response_spec.rb +0 -47
data/lib/amf/version.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
module AMF
|
2
|
-
# AMF version
|
3
|
-
VERSION = '0.0.4'
|
4
|
-
VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
|
5
|
-
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
|
6
|
-
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
|
7
|
-
VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
|
8
|
-
VARIANT_BINARY = false
|
9
|
-
end
|
data/lib/amf.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
2
|
-
$:.unshift "#{File.expand_path(File.dirname(__FILE__))}/amf/"
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'amf/version'
|
6
|
-
require 'amf/common'
|
7
|
-
|
8
|
-
module AMF
|
9
|
-
begin
|
10
|
-
raise LoadError, 'C extensions not implemented'
|
11
|
-
rescue LoadError
|
12
|
-
require 'amf/pure'
|
13
|
-
end
|
14
|
-
require 'amf/class_mapping'
|
15
|
-
|
16
|
-
ClassMapper = AMF::ClassMapping.new
|
17
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
-
|
3
|
-
describe AMF::ClassMapping::MappingSet do
|
4
|
-
before :each do
|
5
|
-
@config = AMF::ClassMapping::MappingSet.new
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should retrieve AS mapping for ruby class" do
|
9
|
-
@config.map :as => 'ASTest', :ruby => 'RubyTest'
|
10
|
-
@config.get_as_class_name('RubyTest').should == 'ASTest'
|
11
|
-
@config.get_as_class_name('BadClass').should be_nil
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should retrive ruby class name mapping for AS class" do
|
15
|
-
@config.map :as => 'ASTest', :ruby => 'RubyTest'
|
16
|
-
@config.get_ruby_class_name('ASTest').should == 'RubyTest'
|
17
|
-
@config.get_ruby_class_name('BadClass').should be_nil
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should map special classes by default" do
|
21
|
-
SPECIAL_CLASSES = [
|
22
|
-
'flex.messaging.messages.AcknowledgeMessage',
|
23
|
-
'flex.messaging.messages.ErrorMessage',
|
24
|
-
'flex.messaging.messages.CommandMessage',
|
25
|
-
'flex.messaging.messages.ErrorMessage',
|
26
|
-
'flex.messaging.messages.RemotingMessage',
|
27
|
-
'flex.messaging.io.ArrayCollection'
|
28
|
-
]
|
29
|
-
|
30
|
-
SPECIAL_CLASSES.each do |as_class|
|
31
|
-
@config.get_ruby_class_name(as_class).should_not be_nil
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,120 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
-
|
3
|
-
describe AMF::ClassMapping do
|
4
|
-
before(:all) do
|
5
|
-
class ClassMappingTest
|
6
|
-
attr_accessor :prop_a
|
7
|
-
attr_accessor :prop_b
|
8
|
-
attr_accessor :prop_c
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
before :each do
|
13
|
-
@mapper = AMF::ClassMapping.new
|
14
|
-
@mapper.define do |m|
|
15
|
-
m.map :as => 'ASClass', :ruby => 'ClassMappingTest'
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should return AS class name for ruby objects" do
|
20
|
-
@mapper.get_as_class_name(ClassMappingTest.new).should == 'ASClass'
|
21
|
-
@mapper.get_as_class_name('ClassMappingTest').should == 'ASClass'
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should allow config modification" do
|
25
|
-
@mapper.define do |m|
|
26
|
-
m.map :as => 'SecondClass', :ruby => 'ClassMappingTest'
|
27
|
-
end
|
28
|
-
@mapper.get_as_class_name(ClassMappingTest.new).should == 'SecondClass'
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "ruby object generator" do
|
32
|
-
it "should instantiate a ruby class" do
|
33
|
-
@mapper.get_ruby_obj('ASClass').should be_a(ClassMappingTest)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should properly instantiate namespaced classes" do
|
37
|
-
module ANamespace; class TestRubyClass; end; end
|
38
|
-
@mapper.define {|m| m.map :as => 'ASClass', :ruby => 'ANamespace::TestRubyClass'}
|
39
|
-
@mapper.get_ruby_obj('ASClass').should be_a(ANamespace::TestRubyClass)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should return a hash with original type if not mapped" do
|
43
|
-
obj = @mapper.get_ruby_obj('UnmappedClass')
|
44
|
-
obj.should be_a(AMF::Values::TypedHash)
|
45
|
-
obj.type.should == 'UnmappedClass'
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe "ruby object populator" do
|
50
|
-
it "should populate a ruby class" do
|
51
|
-
obj = @mapper.populate_ruby_obj ClassMappingTest.new, {:prop_a => 'Data'}
|
52
|
-
obj.prop_a.should == 'Data'
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should populate a typed hash" do
|
56
|
-
obj = @mapper.populate_ruby_obj AMF::Values::TypedHash.new('UnmappedClass'), {:prop_a => 'Data'}
|
57
|
-
obj[:prop_a].should == 'Data'
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should allow custom populators" do
|
61
|
-
class CustomPopulator
|
62
|
-
def can_handle? obj
|
63
|
-
true
|
64
|
-
end
|
65
|
-
def populate obj, props, dynamic_props
|
66
|
-
obj[:populated] = true
|
67
|
-
obj.merge! props
|
68
|
-
obj.merge! dynamic_props if dynamic_props
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
@mapper.object_populators << CustomPopulator.new
|
73
|
-
obj = @mapper.populate_ruby_obj({}, {:prop_a => 'Data'})
|
74
|
-
obj[:populated].should == true
|
75
|
-
obj[:prop_a].should == 'Data'
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "property extractor" do
|
80
|
-
it "should extract hash properties" do
|
81
|
-
hash = {:a => 'test1', :b => 'test2'}
|
82
|
-
props = @mapper.props_for_serialization(hash)
|
83
|
-
props.should == {'a' => 'test1', 'b' => 'test2'}
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should extract object properties" do
|
87
|
-
obj = ClassMappingTest.new
|
88
|
-
obj.prop_a = 'Test A'
|
89
|
-
obj.prop_b = 'Test B'
|
90
|
-
|
91
|
-
hash = @mapper.props_for_serialization obj
|
92
|
-
hash.should == {'prop_a' => 'Test A', 'prop_b' => 'Test B', 'prop_c' => nil}
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should extract inherited object properties" do
|
96
|
-
class ClassMappingTest2 < ClassMappingTest
|
97
|
-
end
|
98
|
-
obj = ClassMappingTest2.new
|
99
|
-
obj.prop_a = 'Test A'
|
100
|
-
obj.prop_b = 'Test B'
|
101
|
-
|
102
|
-
hash = @mapper.props_for_serialization obj
|
103
|
-
hash.should == {'prop_a' => 'Test A', 'prop_b' => 'Test B', 'prop_c' => nil}
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should allow custom serializers" do
|
107
|
-
class CustomSerializer
|
108
|
-
def can_handle? obj
|
109
|
-
true
|
110
|
-
end
|
111
|
-
def serialize obj
|
112
|
-
{:success => true}
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
@mapper.object_serializers << CustomSerializer.new
|
117
|
-
@mapper.props_for_serialization(nil).should == {:success => true}
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
@@ -1,311 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
-
|
3
|
-
describe "when deserializing" do
|
4
|
-
before :each do
|
5
|
-
AMF::ClassMapper.reset
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "AMF0" do
|
9
|
-
it "should deserialize numbers" do
|
10
|
-
input = object_fixture('amf0-number.bin')
|
11
|
-
output = AMF.deserialize(input, 0)
|
12
|
-
output.should == 3.5
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should deserialize booleans" do
|
16
|
-
input = object_fixture('amf0-boolean.bin')
|
17
|
-
output = AMF.deserialize(input, 0)
|
18
|
-
output.should === true
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should deserialize strings" do
|
22
|
-
input = object_fixture('amf0-string.bin')
|
23
|
-
output = AMF.deserialize(input, 0)
|
24
|
-
output.should == "this is a テスト"
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should deserialize anonymous objects" do
|
28
|
-
input = object_fixture('amf0-object.bin')
|
29
|
-
output = AMF.deserialize(input, 0)
|
30
|
-
output.should == {:foo => 'baz', :bar => 3.14}
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should deserialize nulls" do
|
34
|
-
input = object_fixture('amf0-null.bin')
|
35
|
-
output = AMF.deserialize(input, 0)
|
36
|
-
output.should == nil
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should deserialize undefineds" do
|
40
|
-
input = object_fixture('amf0-undefined.bin')
|
41
|
-
output = AMF.deserialize(input, 0)
|
42
|
-
output.should == nil
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should deserialize references properly" do
|
46
|
-
input = object_fixture('amf0-ref-test.bin')
|
47
|
-
output = AMF.deserialize(input, 0)
|
48
|
-
output.length.should == 2
|
49
|
-
output[0].should === output[1]
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should deserialize hashes" do
|
53
|
-
input = object_fixture('amf0-hash.bin')
|
54
|
-
output = AMF.deserialize(input, 0)
|
55
|
-
output.should == {:a => 'b', :c => 'd'}
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should deserialize arrays from flash player" do
|
59
|
-
# Even Array is serialized as a "hash", so check that deserializer converts to array
|
60
|
-
input = object_fixture('amf0-ecma-ordinal-array.bin')
|
61
|
-
output = AMF.deserialize(input, 0)
|
62
|
-
output.should == ['a', 'b', 'c', 'd']
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should serialize strict arrays" do
|
66
|
-
input = object_fixture('amf0-strict-array.bin')
|
67
|
-
output = AMF.deserialize(input, 0)
|
68
|
-
output.should == ['a', 'b', 'c', 'd']
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should deserialize dates" do
|
72
|
-
input = object_fixture('amf0-date.bin')
|
73
|
-
output = AMF.deserialize(input, 0)
|
74
|
-
output.should == Time.utc(2003, 2, 13, 5)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should deserialize XML"
|
78
|
-
|
79
|
-
it "should deserialize an unmapped object as a dynamic anonymous object" do
|
80
|
-
input = object_fixture("amf0-typed-object.bin")
|
81
|
-
output = AMF.deserialize(input, 0)
|
82
|
-
|
83
|
-
output.type.should == 'org.rackAMF.ASClass'
|
84
|
-
output.should == {:foo => 'bar', :baz => nil}
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should deserialize a mapped object as a mapped ruby class instance" do
|
88
|
-
class RubyClass
|
89
|
-
attr_accessor :foo, :baz
|
90
|
-
end
|
91
|
-
AMF::ClassMapper.define {|m| m.map :as => 'org.rackAMF.ASClass', :ruby => 'RubyClass'}
|
92
|
-
|
93
|
-
input = object_fixture("amf0-typed-object.bin")
|
94
|
-
output = AMF.deserialize(input, 0)
|
95
|
-
|
96
|
-
output.should be_a(RubyClass)
|
97
|
-
output.foo.should == 'bar'
|
98
|
-
output.baz.should == nil
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe "AMF3" do
|
103
|
-
describe "simple messages" do
|
104
|
-
it "should deserialize a null" do
|
105
|
-
input = object_fixture("amf3-null.bin")
|
106
|
-
output = AMF.deserialize(input, 3)
|
107
|
-
output.should == nil
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should deserialize a false" do
|
111
|
-
input = object_fixture("amf3-false.bin")
|
112
|
-
output = AMF.deserialize(input, 3)
|
113
|
-
output.should == false
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should deserialize a true" do
|
117
|
-
input = object_fixture("amf3-true.bin")
|
118
|
-
output = AMF.deserialize(input, 3)
|
119
|
-
output.should == true
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should deserialize integers" do
|
123
|
-
input = object_fixture("amf3-max.bin")
|
124
|
-
output = AMF.deserialize(input, 3)
|
125
|
-
output.should == AMF::MAX_INTEGER
|
126
|
-
|
127
|
-
input = object_fixture("amf3-0.bin")
|
128
|
-
output = AMF.deserialize(input, 3)
|
129
|
-
output.should == 0
|
130
|
-
|
131
|
-
input = object_fixture("amf3-min.bin")
|
132
|
-
output = AMF.deserialize(input, 3)
|
133
|
-
output.should == AMF::MIN_INTEGER
|
134
|
-
end
|
135
|
-
|
136
|
-
it "should deserialize large integers" do
|
137
|
-
input = object_fixture("amf3-largeMax.bin")
|
138
|
-
output = AMF.deserialize(input, 3)
|
139
|
-
output.should == AMF::MAX_INTEGER + 1
|
140
|
-
|
141
|
-
input = object_fixture("amf3-largeMin.bin")
|
142
|
-
output = AMF.deserialize(input, 3)
|
143
|
-
output.should == AMF::MIN_INTEGER - 1
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should deserialize BigNums" do
|
147
|
-
input = object_fixture("amf3-bigNum.bin")
|
148
|
-
output = AMF.deserialize(input, 3)
|
149
|
-
output.should == 2**1000
|
150
|
-
end
|
151
|
-
|
152
|
-
it "should deserialize a simple string" do
|
153
|
-
input = object_fixture("amf3-string.bin")
|
154
|
-
output = AMF.deserialize(input, 3)
|
155
|
-
output.should == "String . String"
|
156
|
-
end
|
157
|
-
|
158
|
-
it "should deserialize a symbol as a string" do
|
159
|
-
input = object_fixture("amf3-symbol.bin")
|
160
|
-
output = AMF.deserialize(input, 3)
|
161
|
-
output.should == "foo"
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should deserialize dates" do
|
165
|
-
input = object_fixture("amf3-date.bin")
|
166
|
-
output = AMF.deserialize(input, 3)
|
167
|
-
output.should == Time.at(0)
|
168
|
-
end
|
169
|
-
|
170
|
-
#BAH! Who sends XML over AMF?
|
171
|
-
it "should deserialize a REXML document"
|
172
|
-
end
|
173
|
-
|
174
|
-
describe "objects" do
|
175
|
-
it "should deserialize an unmapped object as a dynamic anonymous object" do
|
176
|
-
input = object_fixture("amf3-dynObject.bin")
|
177
|
-
output = AMF.deserialize(input, 3)
|
178
|
-
|
179
|
-
expected = {
|
180
|
-
:property_one => 'foo',
|
181
|
-
:property_two => 1,
|
182
|
-
:nil_property => nil,
|
183
|
-
:another_public_property => 'a_public_value'
|
184
|
-
}
|
185
|
-
output.should == expected
|
186
|
-
end
|
187
|
-
|
188
|
-
it "should deserialize a mapped object as a mapped ruby class instance" do
|
189
|
-
class RubyClass
|
190
|
-
attr_accessor :foo, :baz
|
191
|
-
end
|
192
|
-
AMF::ClassMapper.define {|m| m.map :as => 'org.rackAMF.ASClass', :ruby => 'RubyClass'}
|
193
|
-
|
194
|
-
input = object_fixture("amf3-typedObject.bin")
|
195
|
-
output = AMF.deserialize(input, 3)
|
196
|
-
|
197
|
-
output.should be_a(RubyClass)
|
198
|
-
output.foo.should == 'bar'
|
199
|
-
output.baz.should == nil
|
200
|
-
end
|
201
|
-
|
202
|
-
it "should deserialize a hash as a dynamic anonymous object" do
|
203
|
-
input = object_fixture("amf3-hash.bin")
|
204
|
-
output = AMF.deserialize(input, 3)
|
205
|
-
output.should == {:foo => "bar", :answer => 42}
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should deserialize an empty array" do
|
209
|
-
input = object_fixture("amf3-emptyArray.bin")
|
210
|
-
output = AMF.deserialize(input, 3)
|
211
|
-
output.should == []
|
212
|
-
end
|
213
|
-
|
214
|
-
it "should deserialize an array of primatives" do
|
215
|
-
input = object_fixture("amf3-primArray.bin")
|
216
|
-
output = AMF.deserialize(input, 3)
|
217
|
-
output.should == [1,2,3,4,5]
|
218
|
-
end
|
219
|
-
|
220
|
-
it "should deserialize an array of mixed objects" do
|
221
|
-
input = object_fixture("amf3-mixedArray.bin")
|
222
|
-
output = AMF.deserialize(input, 3)
|
223
|
-
|
224
|
-
h1 = {:foo_one => "bar_one"}
|
225
|
-
h2 = {:foo_two => ""}
|
226
|
-
so1 = {:foo_three => 42}
|
227
|
-
output.should == [h1, h2, so1, {:foo_three => nil}, {}, [h1, h2, so1], [], 42, "", [], "", {}, "bar_one", so1]
|
228
|
-
end
|
229
|
-
|
230
|
-
it "should deserialize a byte array"
|
231
|
-
end
|
232
|
-
|
233
|
-
describe "and implementing the AMF Spec" do
|
234
|
-
it "should keep references of duplicate strings" do
|
235
|
-
input = object_fixture("amf3-stringRef.bin")
|
236
|
-
output = AMF.deserialize(input, 3)
|
237
|
-
|
238
|
-
class StringCarrier; attr_accessor :str; end
|
239
|
-
foo = "foo"
|
240
|
-
bar = "str"
|
241
|
-
sc = StringCarrier.new
|
242
|
-
sc = {:str => foo}
|
243
|
-
output.should == [foo, bar, foo, bar, foo, sc]
|
244
|
-
end
|
245
|
-
|
246
|
-
it "should not reference the empty string" do
|
247
|
-
input = object_fixture("amf3-emptyStringRef.bin")
|
248
|
-
output = AMF.deserialize(input, 3)
|
249
|
-
output.should == ["",""]
|
250
|
-
end
|
251
|
-
|
252
|
-
it "should keep references of duplicate dates" do
|
253
|
-
input = object_fixture("amf3-datesRef.bin")
|
254
|
-
output = AMF.deserialize(input, 3)
|
255
|
-
|
256
|
-
output[0].should equal(output[1])
|
257
|
-
# Expected object:
|
258
|
-
# [DateTime.parse "1/1/1970", DateTime.parse "1/1/1970"]
|
259
|
-
end
|
260
|
-
|
261
|
-
it "should keep reference of duplicate objects" do
|
262
|
-
input = object_fixture("amf3-objRef.bin")
|
263
|
-
output = AMF.deserialize(input, 3)
|
264
|
-
|
265
|
-
obj1 = {:foo => "bar"}
|
266
|
-
obj2 = {:foo => obj1[:foo]}
|
267
|
-
output.should == [[obj1, obj2], "bar", [obj1, obj2]]
|
268
|
-
end
|
269
|
-
|
270
|
-
it "should keep references of duplicate arrays" do
|
271
|
-
input = object_fixture("amf3-arrayRef.bin")
|
272
|
-
output = AMF.deserialize(input, 3)
|
273
|
-
|
274
|
-
a = [1,2,3]
|
275
|
-
b = %w{ a b c }
|
276
|
-
output.should == [a, b, a, b]
|
277
|
-
end
|
278
|
-
|
279
|
-
it "should not keep references of duplicate empty arrays unless the object_id matches" do
|
280
|
-
input = object_fixture("amf3-emptyArrayRef.bin")
|
281
|
-
output = AMF.deserialize(input, 3)
|
282
|
-
|
283
|
-
a = []
|
284
|
-
b = []
|
285
|
-
output.should == [a,b,a,b]
|
286
|
-
end
|
287
|
-
|
288
|
-
it "should keep references of duplicate XML and XMLDocuments"
|
289
|
-
it "should keep references of duplicate byte arrays"
|
290
|
-
|
291
|
-
it "should deserialize a deep object graph with circular references" do
|
292
|
-
input = object_fixture("amf3-graphMember.bin")
|
293
|
-
output = AMF.deserialize(input, 3)
|
294
|
-
|
295
|
-
output[:children][0][:parent].should === output
|
296
|
-
output[:parent].should === nil
|
297
|
-
output[:children].length.should == 2
|
298
|
-
# Expected object:
|
299
|
-
# parent = Hash.new
|
300
|
-
# child1 = Hash.new
|
301
|
-
# child1[:parent] = parent
|
302
|
-
# child1[:children] = []
|
303
|
-
# child2 = Hash.new
|
304
|
-
# child2[:parent] = parent
|
305
|
-
# child2[:children] = []
|
306
|
-
# parent[:parent] = nil
|
307
|
-
# parent[:children] = [child1, child2]
|
308
|
-
end
|
309
|
-
end
|
310
|
-
end
|
311
|
-
end
|
data/spec/amf/remoting_spec.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
-
|
3
|
-
describe "when handling requests" do
|
4
|
-
it "should handle remoting message from remote object" do
|
5
|
-
input = request_fixture("remotingMessage.bin")
|
6
|
-
req = AMF::Request.new.populate_from_stream(input)
|
7
|
-
|
8
|
-
req.headers.length.should == 0
|
9
|
-
req.messages.length.should == 1
|
10
|
-
message = req.messages[0].data
|
11
|
-
message.should be_a(AMF::Values::RemotingMessage)
|
12
|
-
message.messageId.should == "FE4AF2BC-DD3C-5470-05D8-9971D51FF89D"
|
13
|
-
message.body.should == [true]
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should handle command message from remote object" do
|
17
|
-
input = request_fixture("commandMessage.bin")
|
18
|
-
req = AMF::Request.new.populate_from_stream(input)
|
19
|
-
|
20
|
-
req.headers.length.should == 0
|
21
|
-
req.messages.length.should == 1
|
22
|
-
message = req.messages[0].data
|
23
|
-
message.should be_a(AMF::Values::CommandMessage)
|
24
|
-
message.messageId.should == "7B0ACE15-8D57-6AE5-B9D4-99C2D32C8246"
|
25
|
-
message.body.should == {}
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "when handling responses" do
|
30
|
-
it "should serialize a simple call" do
|
31
|
-
resp = AMF::Response.new
|
32
|
-
resp.amf_version = 3
|
33
|
-
resp.messages << AMF::Message.new('/1/onResult', '', 'hello')
|
34
|
-
|
35
|
-
expected = request_fixture('simple-response.bin')
|
36
|
-
resp.serialize.should == expected
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should serialize a AcknowledgeMessage response" do
|
40
|
-
ak = AMF::Values::AcknowledgeMessage.new
|
41
|
-
ak.clientId = "7B0ACE15-8D57-6AE5-B9D4-99C2D32C8246"
|
42
|
-
ak.messageId = "7B0ACE15-8D57-6AE5-B9D4-99C2D32C8246"
|
43
|
-
ak.timestamp = 0
|
44
|
-
resp = AMF::Response.new
|
45
|
-
resp.amf_version = 3
|
46
|
-
resp.messages << AMF::Message.new('/1/onResult', '', ak)
|
47
|
-
|
48
|
-
expected = request_fixture('acknowledge-response.bin')
|
49
|
-
resp.serialize.should == expected
|
50
|
-
end
|
51
|
-
end
|