scotttam-RocketAMF 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/README.rdoc +45 -0
  2. data/Rakefile +54 -0
  3. data/lib/rocketamf.rb +128 -0
  4. data/lib/rocketamf/class_mapping.rb +231 -0
  5. data/lib/rocketamf/constants.rb +46 -0
  6. data/lib/rocketamf/pure.rb +28 -0
  7. data/lib/rocketamf/pure/deserializer.rb +419 -0
  8. data/lib/rocketamf/pure/io_helpers.rb +94 -0
  9. data/lib/rocketamf/pure/remoting.rb +134 -0
  10. data/lib/rocketamf/pure/serializer.rb +433 -0
  11. data/lib/rocketamf/remoting.rb +144 -0
  12. data/lib/rocketamf/values/array_collection.rb +13 -0
  13. data/lib/rocketamf/values/messages.rb +133 -0
  14. data/lib/rocketamf/values/typed_hash.rb +13 -0
  15. data/spec/amf/class_mapping_spec.rb +150 -0
  16. data/spec/amf/deserializer_spec.rb +367 -0
  17. data/spec/amf/remoting_spec.rb +132 -0
  18. data/spec/amf/serializer_spec.rb +384 -0
  19. data/spec/amf/values/array_collection_spec.rb +19 -0
  20. data/spec/amf/values/messages_spec.rb +31 -0
  21. data/spec/fixtures/objects/amf0-boolean.bin +1 -0
  22. data/spec/fixtures/objects/amf0-complexEncodedStringArray.bin +0 -0
  23. data/spec/fixtures/objects/amf0-date.bin +0 -0
  24. data/spec/fixtures/objects/amf0-ecma-ordinal-array.bin +0 -0
  25. data/spec/fixtures/objects/amf0-hash.bin +0 -0
  26. data/spec/fixtures/objects/amf0-null.bin +1 -0
  27. data/spec/fixtures/objects/amf0-number.bin +0 -0
  28. data/spec/fixtures/objects/amf0-object.bin +0 -0
  29. data/spec/fixtures/objects/amf0-ref-test.bin +0 -0
  30. data/spec/fixtures/objects/amf0-strict-array.bin +0 -0
  31. data/spec/fixtures/objects/amf0-string.bin +0 -0
  32. data/spec/fixtures/objects/amf0-typed-object.bin +0 -0
  33. data/spec/fixtures/objects/amf0-undefined.bin +1 -0
  34. data/spec/fixtures/objects/amf0-untyped-object.bin +0 -0
  35. data/spec/fixtures/objects/amf0-xmlDoc.bin +0 -0
  36. data/spec/fixtures/objects/amf3-0.bin +0 -0
  37. data/spec/fixtures/objects/amf3-arrayCollection.bin +2 -0
  38. data/spec/fixtures/objects/amf3-arrayRef.bin +1 -0
  39. data/spec/fixtures/objects/amf3-bigNum.bin +0 -0
  40. data/spec/fixtures/objects/amf3-byteArray.bin +0 -0
  41. data/spec/fixtures/objects/amf3-byteArrayRef.bin +1 -0
  42. data/spec/fixtures/objects/amf3-complexEncodedStringArray.bin +1 -0
  43. data/spec/fixtures/objects/amf3-date.bin +0 -0
  44. data/spec/fixtures/objects/amf3-datesRef.bin +0 -0
  45. data/spec/fixtures/objects/amf3-dictionary.bin +0 -0
  46. data/spec/fixtures/objects/amf3-dynObject.bin +2 -0
  47. data/spec/fixtures/objects/amf3-emptyArray.bin +1 -0
  48. data/spec/fixtures/objects/amf3-emptyArrayRef.bin +1 -0
  49. data/spec/fixtures/objects/amf3-emptyDictionary.bin +0 -0
  50. data/spec/fixtures/objects/amf3-emptyStringRef.bin +1 -0
  51. data/spec/fixtures/objects/amf3-encodedStringRef.bin +0 -0
  52. data/spec/fixtures/objects/amf3-false.bin +1 -0
  53. data/spec/fixtures/objects/amf3-float.bin +0 -0
  54. data/spec/fixtures/objects/amf3-graphMember.bin +0 -0
  55. data/spec/fixtures/objects/amf3-hash.bin +2 -0
  56. data/spec/fixtures/objects/amf3-largeMax.bin +0 -0
  57. data/spec/fixtures/objects/amf3-largeMin.bin +0 -0
  58. data/spec/fixtures/objects/amf3-max.bin +1 -0
  59. data/spec/fixtures/objects/amf3-min.bin +0 -0
  60. data/spec/fixtures/objects/amf3-mixedArray.bin +11 -0
  61. data/spec/fixtures/objects/amf3-null.bin +1 -0
  62. data/spec/fixtures/objects/amf3-objRef.bin +0 -0
  63. data/spec/fixtures/objects/amf3-primArray.bin +1 -0
  64. data/spec/fixtures/objects/amf3-string.bin +1 -0
  65. data/spec/fixtures/objects/amf3-stringRef.bin +0 -0
  66. data/spec/fixtures/objects/amf3-symbol.bin +1 -0
  67. data/spec/fixtures/objects/amf3-traitRef.bin +3 -0
  68. data/spec/fixtures/objects/amf3-true.bin +1 -0
  69. data/spec/fixtures/objects/amf3-typedObject.bin +2 -0
  70. data/spec/fixtures/objects/amf3-xml.bin +1 -0
  71. data/spec/fixtures/objects/amf3-xmlDoc.bin +1 -0
  72. data/spec/fixtures/objects/amf3-xmlRef.bin +1 -0
  73. data/spec/fixtures/request/acknowledge-response.bin +0 -0
  74. data/spec/fixtures/request/amf0-error-response.bin +0 -0
  75. data/spec/fixtures/request/commandMessage.bin +0 -0
  76. data/spec/fixtures/request/remotingMessage.bin +0 -0
  77. data/spec/fixtures/request/simple-response.bin +0 -0
  78. data/spec/fixtures/request/unsupportedCommandMessage.bin +0 -0
  79. data/spec/spec.opts +1 -0
  80. data/spec/spec_helper.rb +31 -0
  81. metadata +153 -0
@@ -0,0 +1,367 @@
1
+ # encoding: UTF-8
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
4
+
5
+ describe "when deserializing" do
6
+ before :each do
7
+ RocketAMF::ClassMapper.reset
8
+ end
9
+
10
+ describe "AMF0" do
11
+ it "should deserialize numbers" do
12
+ input = object_fixture('amf0-number.bin')
13
+ output = RocketAMF.deserialize(input, 0)
14
+ output.should == 3.5
15
+ end
16
+
17
+ it "should deserialize booleans" do
18
+ input = object_fixture('amf0-boolean.bin')
19
+ output = RocketAMF.deserialize(input, 0)
20
+ output.should === true
21
+ end
22
+
23
+ it "should deserialize UTF8 strings" do
24
+ input = object_fixture('amf0-string.bin')
25
+ output = RocketAMF.deserialize(input, 0)
26
+ output.should == "this is a テスト"
27
+ end
28
+
29
+ it "should deserialize anonymous objects" do
30
+ input = object_fixture('amf0-object.bin')
31
+ output = RocketAMF.deserialize(input, 0)
32
+ output.should == {:foo => 'baz', :bar => 3.14}
33
+ end
34
+
35
+ it "should deserialize nulls" do
36
+ input = object_fixture('amf0-null.bin')
37
+ output = RocketAMF.deserialize(input, 0)
38
+ output.should == nil
39
+ end
40
+
41
+ it "should deserialize undefineds" do
42
+ input = object_fixture('amf0-undefined.bin')
43
+ output = RocketAMF.deserialize(input, 0)
44
+ output.should == nil
45
+ end
46
+
47
+ it "should deserialize references properly" do
48
+ input = object_fixture('amf0-ref-test.bin')
49
+ output = RocketAMF.deserialize(input, 0)
50
+ output.length.should == 2
51
+ output[0].should === output[1]
52
+ end
53
+
54
+ it "should deserialize hashes" do
55
+ input = object_fixture('amf0-hash.bin')
56
+ output = RocketAMF.deserialize(input, 0)
57
+ output.should == {:a => 'b', :c => 'd'}
58
+ end
59
+
60
+ it "should deserialize arrays from flash player" do
61
+ # Even Array is serialized as a "hash", so check that deserializer converts to array
62
+ input = object_fixture('amf0-ecma-ordinal-array.bin')
63
+ output = RocketAMF.deserialize(input, 0)
64
+ output.should == ['a', 'b', 'c', 'd']
65
+ end
66
+
67
+ it "should serialize strict arrays" do
68
+ input = object_fixture('amf0-strict-array.bin')
69
+ output = RocketAMF.deserialize(input, 0)
70
+ output.should == ['a', 'b', 'c', 'd']
71
+ end
72
+
73
+ it "should deserialize dates" do
74
+ input = object_fixture('amf0-date.bin')
75
+ output = RocketAMF.deserialize(input, 0)
76
+ output.should == Time.utc(2003, 2, 13, 5)
77
+ end
78
+
79
+ it "should deserialize an XML document" do
80
+ input = object_fixture('amf0-xmlDoc.bin')
81
+ output = RocketAMF.deserialize(input, 0)
82
+ output.should == '<parent><child prop="test" /></parent>'
83
+ end
84
+
85
+ it "should deserialize an unmapped object as a dynamic anonymous object" do
86
+ input = object_fixture("amf0-typed-object.bin")
87
+ output = RocketAMF.deserialize(input, 0)
88
+
89
+ output.type.should == 'org.rocketAMF.ASClass'
90
+ output.should == {:foo => 'bar', :baz => nil}
91
+ end
92
+
93
+ it "should deserialize a mapped object as a mapped ruby class instance" do
94
+ RocketAMF::ClassMapper.define {|m| m.map :as => 'org.rocketAMF.ASClass', :ruby => 'RubyClass'}
95
+
96
+ input = object_fixture("amf0-typed-object.bin")
97
+ output = RocketAMF.deserialize(input, 0)
98
+
99
+ output.should be_a(RubyClass)
100
+ output.foo.should == 'bar'
101
+ output.baz.should == nil
102
+ end
103
+ end
104
+
105
+ describe "AMF3" do
106
+ describe "simple messages" do
107
+ it "should deserialize a null" do
108
+ input = object_fixture("amf3-null.bin")
109
+ output = RocketAMF.deserialize(input, 3)
110
+ output.should == nil
111
+ end
112
+
113
+ it "should deserialize a false" do
114
+ input = object_fixture("amf3-false.bin")
115
+ output = RocketAMF.deserialize(input, 3)
116
+ output.should == false
117
+ end
118
+
119
+ it "should deserialize a true" do
120
+ input = object_fixture("amf3-true.bin")
121
+ output = RocketAMF.deserialize(input, 3)
122
+ output.should == true
123
+ end
124
+
125
+ it "should deserialize integers" do
126
+ input = object_fixture("amf3-max.bin")
127
+ output = RocketAMF.deserialize(input, 3)
128
+ output.should == RocketAMF::MAX_INTEGER
129
+
130
+ input = object_fixture("amf3-0.bin")
131
+ output = RocketAMF.deserialize(input, 3)
132
+ output.should == 0
133
+
134
+ input = object_fixture("amf3-min.bin")
135
+ output = RocketAMF.deserialize(input, 3)
136
+ output.should == RocketAMF::MIN_INTEGER
137
+ end
138
+
139
+ it "should deserialize large integers" do
140
+ input = object_fixture("amf3-largeMax.bin")
141
+ output = RocketAMF.deserialize(input, 3)
142
+ output.should == RocketAMF::MAX_INTEGER + 1
143
+
144
+ input = object_fixture("amf3-largeMin.bin")
145
+ output = RocketAMF.deserialize(input, 3)
146
+ output.should == RocketAMF::MIN_INTEGER - 1
147
+ end
148
+
149
+ it "should deserialize BigNums" do
150
+ input = object_fixture("amf3-bigNum.bin")
151
+ output = RocketAMF.deserialize(input, 3)
152
+ output.should == 2**1000
153
+ end
154
+
155
+ it "should deserialize a simple string" do
156
+ input = object_fixture("amf3-string.bin")
157
+ output = RocketAMF.deserialize(input, 3)
158
+ output.should == "String . String"
159
+ end
160
+
161
+ it "should deserialize a symbol as a string" do
162
+ input = object_fixture("amf3-symbol.bin")
163
+ output = RocketAMF.deserialize(input, 3)
164
+ output.should == "foo"
165
+ end
166
+
167
+ it "should deserialize dates" do
168
+ input = object_fixture("amf3-date.bin")
169
+ output = RocketAMF.deserialize(input, 3)
170
+ output.should == Time.at(0)
171
+ end
172
+
173
+ it "should deserialize XML" do
174
+ # XMLDocument tag
175
+ input = object_fixture("amf3-xmlDoc.bin")
176
+ output = RocketAMF.deserialize(input, 3)
177
+ output.should == '<parent><child prop="test" /></parent>'
178
+
179
+ # XML tag
180
+ input = object_fixture("amf3-xml.bin")
181
+ output = RocketAMF.deserialize(input, 3)
182
+ output.should == '<parent><child prop="test"/></parent>'
183
+ end
184
+ end
185
+
186
+ describe "objects" do
187
+ it "should deserialize an unmapped object as a dynamic anonymous object" do
188
+ input = object_fixture("amf3-dynObject.bin")
189
+ output = RocketAMF.deserialize(input, 3)
190
+
191
+ expected = {
192
+ :property_one => 'foo',
193
+ :property_two => 1,
194
+ :nil_property => nil,
195
+ :another_public_property => 'a_public_value'
196
+ }
197
+ output.should == expected
198
+ end
199
+
200
+ it "should deserialize a mapped object as a mapped ruby class instance" do
201
+ RocketAMF::ClassMapper.define {|m| m.map :as => 'org.rocketAMF.ASClass', :ruby => 'RubyClass'}
202
+
203
+ input = object_fixture("amf3-typedObject.bin")
204
+ output = RocketAMF.deserialize(input, 3)
205
+
206
+ output.should be_a(RubyClass)
207
+ output.foo.should == 'bar'
208
+ output.baz.should == nil
209
+ end
210
+
211
+ it "should deserialize a hash as a dynamic anonymous object" do
212
+ input = object_fixture("amf3-hash.bin")
213
+ output = RocketAMF.deserialize(input, 3)
214
+ output.should == {:foo => "bar", :answer => 42}
215
+ end
216
+
217
+ it "should deserialize an empty array" do
218
+ input = object_fixture("amf3-emptyArray.bin")
219
+ output = RocketAMF.deserialize(input, 3)
220
+ output.should == []
221
+ end
222
+
223
+ it "should deserialize an array of primitives" do
224
+ input = object_fixture("amf3-primArray.bin")
225
+ output = RocketAMF.deserialize(input, 3)
226
+ output.should == [1,2,3,4,5]
227
+ end
228
+
229
+ it "should deserialize an array of mixed objects" do
230
+ input = object_fixture("amf3-mixedArray.bin")
231
+ output = RocketAMF.deserialize(input, 3)
232
+
233
+ h1 = {:foo_one => "bar_one"}
234
+ h2 = {:foo_two => ""}
235
+ so1 = {:foo_three => 42}
236
+ output.should == [h1, h2, so1, {:foo_three => nil}, {}, [h1, h2, so1], [], 42, "", [], "", {}, "bar_one", so1]
237
+ end
238
+
239
+ it "should deserialize a byte array" do
240
+ input = object_fixture("amf3-byteArray.bin")
241
+ output = RocketAMF.deserialize(input, 3)
242
+
243
+ output.should be_a(StringIO)
244
+ expected = "\000\003これtest\100"
245
+ expected.force_encoding("ASCII-8BIT") if expected.respond_to?(:force_encoding)
246
+ output.string.should == expected
247
+ end
248
+
249
+ it "should deserialize an empty dictionary" do
250
+ input = object_fixture("amf3-emptyDictionary.bin")
251
+ output = RocketAMF.deserialize(input, 3)
252
+ output.should == {}
253
+ end
254
+
255
+ it "should deserialize a dictionary" do
256
+ input = object_fixture("amf3-dictionary.bin")
257
+ output = RocketAMF.deserialize(input, 3)
258
+
259
+ keys = output.keys
260
+ keys.length.should == 2
261
+ obj_key, str_key = keys[0].is_a?(RocketAMF::Values::TypedHash) ? [keys[0], keys[1]] : [keys[1], keys[0]]
262
+ obj_key.type.should == 'org.rocketAMF.ASClass'
263
+ output[obj_key].should == "asdf2"
264
+ str_key.should == "bar"
265
+ output[str_key].should == "asdf1"
266
+ end
267
+ end
268
+
269
+ describe "and implementing the AMF Spec" do
270
+ it "should keep references of duplicate strings" do
271
+ input = object_fixture("amf3-stringRef.bin")
272
+ output = RocketAMF.deserialize(input, 3)
273
+
274
+ class StringCarrier; attr_accessor :str; end
275
+ foo = "foo"
276
+ bar = "str"
277
+ sc = StringCarrier.new
278
+ sc = {:str => foo}
279
+ output.should == [foo, bar, foo, bar, foo, sc]
280
+ end
281
+
282
+ it "should not reference the empty string" do
283
+ input = object_fixture("amf3-emptyStringRef.bin")
284
+ output = RocketAMF.deserialize(input, 3)
285
+ output.should == ["",""]
286
+ end
287
+
288
+ it "should keep references of duplicate dates" do
289
+ input = object_fixture("amf3-datesRef.bin")
290
+ output = RocketAMF.deserialize(input, 3)
291
+
292
+ output[0].should equal(output[1])
293
+ # Expected object:
294
+ # [DateTime.parse "1/1/1970", DateTime.parse "1/1/1970"]
295
+ end
296
+
297
+ it "should keep reference of duplicate objects" do
298
+ input = object_fixture("amf3-objRef.bin")
299
+ output = RocketAMF.deserialize(input, 3)
300
+
301
+ obj1 = {:foo => "bar"}
302
+ obj2 = {:foo => obj1[:foo]}
303
+ output.should == [[obj1, obj2], "bar", [obj1, obj2]]
304
+ end
305
+
306
+ it "should keep reference of duplicate object traits" do
307
+ RocketAMF::ClassMapper.define {|m| m.map :as => 'org.rocketAMF.ASClass', :ruby => 'RubyClass'}
308
+
309
+ input = object_fixture("amf3-traitRef.bin")
310
+ output = RocketAMF.deserialize(input, 3)
311
+
312
+ output[0].foo.should == "foo"
313
+ output[1].foo.should == "bar"
314
+ end
315
+
316
+ it "should keep references of duplicate arrays" do
317
+ input = object_fixture("amf3-arrayRef.bin")
318
+ output = RocketAMF.deserialize(input, 3)
319
+
320
+ a = [1,2,3]
321
+ b = %w{ a b c }
322
+ output.should == [a, b, a, b]
323
+ end
324
+
325
+ it "should not keep references of duplicate empty arrays unless the object_id matches" do
326
+ input = object_fixture("amf3-emptyArrayRef.bin")
327
+ output = RocketAMF.deserialize(input, 3)
328
+
329
+ a = []
330
+ b = []
331
+ output.should == [a,b,a,b]
332
+ end
333
+
334
+ it "should keep references of duplicate XML and XMLDocuments" do
335
+ input = object_fixture("amf3-xmlRef.bin")
336
+ output = RocketAMF.deserialize(input, 3)
337
+ output.should == ['<parent><child prop="test"/></parent>', '<parent><child prop="test"/></parent>']
338
+ end
339
+
340
+ it "should keep references of duplicate byte arrays" do
341
+ input = object_fixture("amf3-byteArrayRef.bin")
342
+ output = RocketAMF.deserialize(input, 3)
343
+ output[0].object_id.should == output[1].object_id
344
+ output[0].string.should == "ASDF"
345
+ end
346
+
347
+ it "should deserialize a deep object graph with circular references" do
348
+ input = object_fixture("amf3-graphMember.bin")
349
+ output = RocketAMF.deserialize(input, 3)
350
+
351
+ output[:children][0][:parent].should === output
352
+ output[:parent].should === nil
353
+ output[:children].length.should == 2
354
+ # Expected object:
355
+ # parent = Hash.new
356
+ # child1 = Hash.new
357
+ # child1[:parent] = parent
358
+ # child1[:children] = []
359
+ # child2 = Hash.new
360
+ # child2[:parent] = parent
361
+ # child2[:children] = []
362
+ # parent[:parent] = nil
363
+ # parent[:children] = [child1, child2]
364
+ end
365
+ end
366
+ end
367
+ end
@@ -0,0 +1,132 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
2
+
3
+ describe RocketAMF::Envelope do
4
+ describe 'deserializer' do
5
+ it "should handle remoting message from remote object" do
6
+ req = create_envelope("remotingMessage.bin")
7
+
8
+ req.headers.length.should == 0
9
+ req.messages.length.should == 1
10
+ message = req.messages[0].data
11
+ message.should be_a(RocketAMF::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
+ req = create_envelope("commandMessage.bin")
18
+
19
+ req.headers.length.should == 0
20
+ req.messages.length.should == 1
21
+ message = req.messages[0].data
22
+ message.should be_a(RocketAMF::Values::CommandMessage)
23
+ message.messageId.should == "7B0ACE15-8D57-6AE5-B9D4-99C2D32C8246"
24
+ message.body.should == {}
25
+ end
26
+ end
27
+
28
+ describe "#deserialize" do
29
+ it "should parse the message envelope into a hash" do
30
+ parsed_amf = RocketAMF::Envelope.new.deserialize(create_envelope('commandMessage.bin').serialize)
31
+ parsed_amf[:amf_version].should == 3
32
+ parsed_amf[:headers].should == []
33
+ parsed_amf[:bodies].first[:target_uri].should == "null"
34
+ parsed_amf[:bodies].first[:response_uri].should == "/1"
35
+ puts parsed_amf[:bodies].first[:content].class.should == RocketAMF::Values::CommandMessage
36
+ end
37
+
38
+ it "should return nil if nil is passed in" do
39
+ RocketAMF::Envelope.new.deserialize(nil).should be_nil
40
+ end
41
+ end
42
+
43
+ describe 'serializer' do
44
+ it "should serialize response when converted to string" do
45
+ res = RocketAMF::Envelope.new
46
+ res.should_receive(:serialize).and_return('serialized')
47
+ res.to_s.should == 'serialized'
48
+ end
49
+
50
+ it "should serialize a simple call" do
51
+ res = RocketAMF::Envelope.new :amf_version => 3
52
+ res.messages << RocketAMF::Message.new('/1/onResult', '', 'hello')
53
+
54
+ expected = request_fixture('simple-response.bin')
55
+ res.serialize.should == expected
56
+ end
57
+
58
+ it "should serialize a AcknowledgeMessage response" do
59
+ ak = RocketAMF::Values::AcknowledgeMessage.new
60
+ ak.clientId = "7B0ACE15-8D57-6AE5-B9D4-99C2D32C8246"
61
+ ak.messageId = "7B0ACE15-8D57-6AE5-B9D4-99C2D32C8246"
62
+ ak.timestamp = 0
63
+ res = RocketAMF::Envelope.new :amf_version => 3
64
+ res.messages << RocketAMF::Message.new('/1/onResult', '', ak)
65
+
66
+ expected = request_fixture('acknowledge-response.bin')
67
+ res.serialize.should == expected
68
+ end
69
+ end
70
+
71
+ describe 'message handler' do
72
+ it "should respond to ping command" do
73
+ res = RocketAMF::Envelope.new
74
+ req = create_envelope('commandMessage.bin')
75
+ res.each_method_call req do |method, args|
76
+ nil
77
+ end
78
+
79
+ res.messages.length.should == 1
80
+ res.messages[0].data.should be_a(RocketAMF::Values::AcknowledgeMessage)
81
+ end
82
+
83
+ it "should fail on unsupported command" do
84
+ res = RocketAMF::Envelope.new
85
+ req = create_envelope('unsupportedCommandMessage.bin')
86
+ res.each_method_call req do |method, args|
87
+ nil
88
+ end
89
+
90
+ res.messages.length.should == 1
91
+ res.messages[0].data.should be_a(RocketAMF::Values::ErrorMessage)
92
+ res.messages[0].data.faultString.should == "CommandMessage 10000 not implemented"
93
+ end
94
+
95
+ it "should handle RemotingMessages properly" do
96
+ res = RocketAMF::Envelope.new
97
+ req = create_envelope('remotingMessage.bin')
98
+ res.each_method_call req do |method, args|
99
+ method.should == 'WritesController.save'
100
+ args.should == [true]
101
+ true
102
+ end
103
+
104
+ res.messages.length.should == 1
105
+ res.messages[0].data.should be_a(RocketAMF::Values::AcknowledgeMessage)
106
+ res.messages[0].data.body.should == true
107
+ end
108
+
109
+ it "should catch exceptions properly" do
110
+ res = RocketAMF::Envelope.new
111
+ req = create_envelope('remotingMessage.bin')
112
+ res.each_method_call req do |method, args|
113
+ raise 'Error in call'
114
+ end
115
+
116
+ res.messages.length.should == 1
117
+ res.messages[0].data.should be_a(RocketAMF::Values::ErrorMessage)
118
+ res.messages[0].target_uri.should =~ /onStatus$/
119
+ end
120
+
121
+ it "should not crash if source missing on RemotingMessage" do
122
+ res = RocketAMF::Envelope.new
123
+ req = create_envelope('remotingMessage.bin')
124
+ req.messages[0].data.instance_variable_set("@source", nil)
125
+ lambda {
126
+ res.each_method_call req do |method,args|
127
+ true
128
+ end
129
+ }.should_not raise_error
130
+ end
131
+ end
132
+ end