rack-amf 0.0.4 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. data/README.rdoc +18 -9
  2. data/Rakefile +23 -38
  3. data/lib/rack/amf/environment.rb +5 -8
  4. data/lib/rack/amf/middleware/pass_through.rb +5 -4
  5. data/lib/rack/amf/middleware/service_manager.rb +11 -3
  6. data/lib/rack/amf/middleware.rb +2 -1
  7. data/lib/rack/amf/request.rb +3 -16
  8. data/lib/rack/amf/response.rb +8 -67
  9. data/lib/rack/amf.rb +41 -1
  10. data/spec/{rack/service_manager_spec.rb → service_manager_spec.rb} +1 -2
  11. data/spec/spec.opts +2 -1
  12. data/spec/spec_helper.rb +1 -24
  13. metadata +19 -84
  14. data/lib/amf/class_mapping.rb +0 -211
  15. data/lib/amf/common.rb +0 -28
  16. data/lib/amf/constants.rb +0 -47
  17. data/lib/amf/pure/deserializer.rb +0 -361
  18. data/lib/amf/pure/io_helpers.rb +0 -94
  19. data/lib/amf/pure/remoting.rb +0 -120
  20. data/lib/amf/pure/serializer.rb +0 -327
  21. data/lib/amf/pure.rb +0 -14
  22. data/lib/amf/values/array_collection.rb +0 -9
  23. data/lib/amf/values/messages.rb +0 -133
  24. data/lib/amf/values/typed_hash.rb +0 -13
  25. data/lib/amf/version.rb +0 -9
  26. data/lib/amf.rb +0 -17
  27. data/spec/amf/class_mapping_set_spec.rb +0 -34
  28. data/spec/amf/class_mapping_spec.rb +0 -120
  29. data/spec/amf/deserializer_spec.rb +0 -311
  30. data/spec/amf/remoting_spec.rb +0 -51
  31. data/spec/amf/serializer_spec.rb +0 -328
  32. data/spec/amf/values/array_collection_spec.rb +0 -6
  33. data/spec/amf/values/messages_spec.rb +0 -31
  34. data/spec/fixtures/objects/amf0-boolean.bin +0 -1
  35. data/spec/fixtures/objects/amf0-date.bin +0 -0
  36. data/spec/fixtures/objects/amf0-ecma-ordinal-array.bin +0 -0
  37. data/spec/fixtures/objects/amf0-hash.bin +0 -0
  38. data/spec/fixtures/objects/amf0-null.bin +0 -1
  39. data/spec/fixtures/objects/amf0-number.bin +0 -0
  40. data/spec/fixtures/objects/amf0-object.bin +0 -0
  41. data/spec/fixtures/objects/amf0-ref-test.bin +0 -0
  42. data/spec/fixtures/objects/amf0-strict-array.bin +0 -0
  43. data/spec/fixtures/objects/amf0-string.bin +0 -0
  44. data/spec/fixtures/objects/amf0-typed-object.bin +0 -0
  45. data/spec/fixtures/objects/amf0-undefined.bin +0 -1
  46. data/spec/fixtures/objects/amf0-untyped-object.bin +0 -0
  47. data/spec/fixtures/objects/amf3-0.bin +0 -0
  48. data/spec/fixtures/objects/amf3-arrayRef.bin +0 -1
  49. data/spec/fixtures/objects/amf3-bigNum.bin +0 -0
  50. data/spec/fixtures/objects/amf3-date.bin +0 -0
  51. data/spec/fixtures/objects/amf3-datesRef.bin +0 -0
  52. data/spec/fixtures/objects/amf3-dynObject.bin +0 -2
  53. data/spec/fixtures/objects/amf3-emptyArray.bin +0 -1
  54. data/spec/fixtures/objects/amf3-emptyArrayRef.bin +0 -1
  55. data/spec/fixtures/objects/amf3-emptyStringRef.bin +0 -1
  56. data/spec/fixtures/objects/amf3-false.bin +0 -1
  57. data/spec/fixtures/objects/amf3-graphMember.bin +0 -0
  58. data/spec/fixtures/objects/amf3-hash.bin +0 -2
  59. data/spec/fixtures/objects/amf3-largeMax.bin +0 -0
  60. data/spec/fixtures/objects/amf3-largeMin.bin +0 -0
  61. data/spec/fixtures/objects/amf3-max.bin +0 -1
  62. data/spec/fixtures/objects/amf3-min.bin +0 -0
  63. data/spec/fixtures/objects/amf3-mixedArray.bin +0 -11
  64. data/spec/fixtures/objects/amf3-null.bin +0 -1
  65. data/spec/fixtures/objects/amf3-objRef.bin +0 -0
  66. data/spec/fixtures/objects/amf3-primArray.bin +0 -1
  67. data/spec/fixtures/objects/amf3-string.bin +0 -1
  68. data/spec/fixtures/objects/amf3-stringRef.bin +0 -0
  69. data/spec/fixtures/objects/amf3-symbol.bin +0 -1
  70. data/spec/fixtures/objects/amf3-true.bin +0 -1
  71. data/spec/fixtures/objects/amf3-typedObject.bin +0 -2
  72. data/spec/fixtures/request/acknowledge-response.bin +0 -0
  73. data/spec/fixtures/request/amf0-error-response.bin +0 -0
  74. data/spec/fixtures/request/commandMessage.bin +0 -0
  75. data/spec/fixtures/request/remotingMessage.bin +0 -0
  76. data/spec/fixtures/request/simple-response.bin +0 -0
  77. data/spec/rack/request_spec.rb +0 -6
  78. data/spec/rack/response_spec.rb +0 -47
@@ -1,328 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
2
-
3
- require 'rexml/document'
4
-
5
- describe "when serializing" do
6
- before :each do
7
- AMF::ClassMapper.reset
8
- end
9
-
10
- describe "AMF0" do
11
- it "should serialize nils" do
12
- output = AMF.serialize(nil, 0)
13
- output.should == object_fixture('amf0-null.bin')
14
- end
15
-
16
- it "should serialize booleans" do
17
- output = AMF.serialize(true, 0)
18
- output.should === object_fixture('amf0-boolean.bin')
19
- end
20
-
21
- it "should serialize numbers" do
22
- output = AMF.serialize(3.5, 0)
23
- output.should == object_fixture('amf0-number.bin')
24
- end
25
-
26
- it "should serialize strings" do
27
- output = AMF.serialize("this is a テスト", 0)
28
- output.should == object_fixture('amf0-string.bin')
29
- end
30
-
31
- it "should serialize arrays" do
32
- output = AMF.serialize(['a', 'b', 'c', 'd'], 0)
33
- output.should == object_fixture('amf0-strict-array.bin')
34
- end
35
-
36
- it "should serialize references" do
37
- class OtherClass
38
- attr_accessor :foo, :bar
39
- end
40
- obj = OtherClass.new
41
- obj.foo = "baz"
42
- obj.bar = 3.14
43
-
44
- output = AMF.serialize({'0' => obj, '1' => obj}, 0)
45
- output.should == object_fixture('amf0-ref-test.bin')
46
- end
47
-
48
- it "should serialize dates" do
49
- output = AMF.serialize(Time.utc(2003, 2, 13, 5), 0)
50
- output.should == object_fixture('amf0-date.bin')
51
- end
52
-
53
- it "should serialize hashes" do
54
- output = AMF.serialize({:a => 'b', :c => 'd'}, 0)
55
- output.should == object_fixture('amf0-hash.bin')
56
- end
57
-
58
- it "should serialize unmapped objects" do
59
- class RubyClass
60
- attr_accessor :foo, :baz
61
- end
62
- obj = RubyClass.new
63
- obj.foo = "bar"
64
-
65
- output = AMF.serialize(obj, 0)
66
- output.should == object_fixture('amf0-untyped-object.bin')
67
- end
68
-
69
- it "should serialize mapped objects" do
70
- class RubyClass
71
- attr_accessor :foo, :baz
72
- end
73
- obj = RubyClass.new
74
- obj.foo = "bar"
75
- AMF::ClassMapper.define {|m| m.map :as => 'org.rackAMF.ASClass', :ruby => 'RubyClass'}
76
-
77
- output = AMF.serialize(obj, 0)
78
- output.should == object_fixture('amf0-typed-object.bin')
79
- end
80
- end
81
-
82
- describe "AMF3" do
83
- describe "simple messages" do
84
- it "should serialize a null" do
85
- expected = object_fixture("amf3-null.bin")
86
- output = AMF.serialize(nil, 3)
87
- output.should == expected
88
- end
89
-
90
- it "should serialize a false" do
91
- expected = object_fixture("amf3-false.bin")
92
- output = AMF.serialize(false, 3)
93
- output.should == expected
94
- end
95
-
96
- it "should serialize a true" do
97
- expected = object_fixture("amf3-true.bin")
98
- output = AMF.serialize(true, 3)
99
- output.should == expected
100
- end
101
-
102
- it "should serialize integers" do
103
- expected = object_fixture("amf3-max.bin")
104
- input = AMF::MAX_INTEGER
105
- output = AMF.serialize(input, 3)
106
- output.should == expected
107
-
108
- expected = object_fixture("amf3-0.bin")
109
- output = AMF.serialize(0, 3)
110
- output.should == expected
111
-
112
- expected = object_fixture("amf3-min.bin")
113
- input = AMF::MIN_INTEGER
114
- output = AMF.serialize(input, 3)
115
- output.should == expected
116
- end
117
-
118
- it "should serialize large integers" do
119
- expected = object_fixture("amf3-largeMax.bin")
120
- input = AMF::MAX_INTEGER + 1
121
- output = AMF.serialize(input, 3)
122
- output.should == expected
123
-
124
- expected = object_fixture("amf3-largeMin.bin")
125
- input = AMF::MIN_INTEGER - 1
126
- output = AMF.serialize(input, 3)
127
- output.should == expected
128
- end
129
-
130
- it "should serialize BigNums" do
131
- expected = object_fixture("amf3-bigNum.bin")
132
- input = 2**1000
133
- output = AMF.serialize(input, 3)
134
- output.should == expected
135
- end
136
-
137
- it "should serialize a simple string" do
138
- expected = object_fixture("amf3-string.bin")
139
- input = "String . String"
140
- output = AMF.serialize(input, 3)
141
- output.should == expected
142
- end
143
-
144
- it "should serialize a symbol as a string" do
145
- expected = object_fixture("amf3-symbol.bin")
146
- output = AMF.serialize(:foo, 3)
147
- output.should == expected
148
- end
149
-
150
- it "should serialize Times" do
151
- expected = object_fixture("amf3-date.bin")
152
- input = Time.utc 1970, 1, 1, 0
153
- output = AMF.serialize(input, 3)
154
- output.should == expected
155
- end
156
-
157
- #BAH! Who sends XML over AMF?
158
- it "should serialize a REXML document"
159
- end
160
-
161
- describe "objects" do
162
- it "should serialize an unmapped object as a dynamic anonymous object" do
163
- class NonMappedObject
164
- attr_accessor :property_one
165
- attr_accessor :property_two
166
- attr_accessor :nil_property
167
- attr_writer :read_only_prop
168
-
169
- def another_public_property
170
- 'a_public_value'
171
- end
172
-
173
- def method_with_arg arg='foo'
174
- arg
175
- end
176
- end
177
- obj = NonMappedObject.new
178
- obj.property_one = 'foo'
179
- obj.property_two = 1
180
- obj.nil_property = nil
181
-
182
- expected = object_fixture("amf3-dynObject.bin")
183
- input = obj
184
- output = AMF.serialize(input, 3)
185
- output.should == expected
186
- end
187
-
188
- it "should serialize a hash as a dynamic anonymous object" do
189
- hash = {}
190
- hash[:answer] = 42
191
- hash[:foo] = "bar"
192
-
193
- expected = object_fixture("amf3-hash.bin")
194
- input = hash
195
- output = AMF.serialize(input, 3)
196
- output.should == expected
197
- end
198
-
199
- it "should serialize an empty array" do
200
- expected = object_fixture("amf3-emptyArray.bin")
201
- input = []
202
- output = AMF.serialize(input, 3)
203
- output.should == expected
204
- end
205
-
206
- it "should serialize an array of primatives" do
207
- expected = object_fixture("amf3-primArray.bin")
208
- input = [1, 2, 3, 4, 5]
209
- output = AMF.serialize(input, 3)
210
- output.should == expected
211
- end
212
-
213
- it "should serialize an array of mixed objects" do
214
- h1 = {:foo_one => "bar_one"}
215
- h2 = {:foo_two => ""}
216
- class SimpleObj
217
- attr_accessor :foo_three
218
- end
219
- so1 = SimpleObj.new
220
- so1.foo_three = 42
221
-
222
- expected = object_fixture("amf3-mixedArray.bin")
223
- input = [h1, h2, so1, SimpleObj.new, {}, [h1, h2, so1], [], 42, "", [], "", {}, "bar_one", so1]
224
- output = AMF.serialize(input, 3)
225
- output.should == expected
226
- end
227
-
228
- it "should serialize a byte array"
229
- end
230
-
231
- describe "and implementing the AMF Spec" do
232
- it "should keep references of duplicate strings" do
233
- class StringCarrier
234
- attr_accessor :str
235
- end
236
- foo = "foo"
237
- bar = "str"
238
- sc = StringCarrier.new
239
- sc.str = foo
240
-
241
- expected = object_fixture("amf3-stringRef.bin")
242
- input = [foo, bar, foo, bar, foo, sc]
243
- output = AMF.serialize(input, 3)
244
- output.should == expected
245
- end
246
-
247
- it "should not reference the empty string" do
248
- expected = object_fixture("amf3-emptyStringRef.bin")
249
- input = ""
250
- output = AMF.serialize([input,input], 3)
251
- output.should == expected
252
- end
253
-
254
- it "should keep references of duplicate dates" do
255
- expected = object_fixture("amf3-datesRef.bin")
256
- input = Time.utc 1970, 1, 1, 0
257
- output = AMF.serialize([input,input], 3)
258
- output.should == expected
259
- end
260
-
261
- it "should keep reference of duplicate objects" do
262
- class SimpleReferenceableObj
263
- attr_accessor :foo
264
- end
265
- obj1 = SimpleReferenceableObj.new
266
- obj1.foo = :bar
267
- obj2 = SimpleReferenceableObj.new
268
- obj2.foo = obj1.foo
269
-
270
- expected = object_fixture("amf3-objRef.bin")
271
- input = [[obj1, obj2], "bar", [obj1, obj2]]
272
- output = AMF.serialize(input, 3)
273
- output.should == expected
274
- end
275
-
276
- it "should keep references of duplicate arrays" do
277
- a = [1,2,3]
278
- b = %w{ a b c }
279
-
280
- expected = object_fixture("amf3-arrayRef.bin")
281
- input = [a, b, a, b]
282
- output = AMF.serialize(input, 3)
283
- output.should == expected
284
- end
285
-
286
- it "should not keep references of duplicate empty arrays unless the object_id matches" do
287
- a = []
288
- b = []
289
- a.should == b
290
- a.object_id.should_not == b.object_id
291
-
292
- expected = object_fixture("amf3-emptyArrayRef.bin")
293
- input = [a,b,a,b]
294
- output = AMF.serialize(input, 3)
295
- output.should == expected
296
- end
297
-
298
- it "should keep references of duplicate XML and XMLDocuments"
299
- it "should keep references of duplicate byte arrays"
300
-
301
- it "should serialize a deep object graph with circular references" do
302
- class GraphMember
303
- attr_accessor :parent
304
- attr_accessor :children
305
-
306
- def initialize
307
- self.children = []
308
- end
309
-
310
- def add_child child
311
- children << child
312
- child.parent = self
313
- child
314
- end
315
- end
316
-
317
- parent = GraphMember.new
318
- level_1_child_1 = parent.add_child GraphMember.new
319
- level_1_child_2 = parent.add_child GraphMember.new
320
-
321
- expected = object_fixture("amf3-graphMember.bin")
322
- input = parent
323
- output = AMF.serialize(input, 3)
324
- output.should == expected
325
- end
326
- end
327
- end
328
- end
@@ -1,6 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- describe AMF::Values::ArrayCollection do
4
- it "should deserialize properly"
5
- it "should serialize properly"
6
- end
@@ -1,31 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- describe AMF::Values::AbstractMessage do
4
- before :each do
5
- @message = AMF::Values::AbstractMessage.new
6
- end
7
-
8
- it "should generate conforming uuids" do
9
- @message.send(:rand_uuid).should =~ /[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}/i
10
- end
11
- end
12
-
13
- describe AMF::Values::ErrorMessage do
14
- before :each do
15
- @e = Exception.new('Error message')
16
- @e.set_backtrace(['Backtrace 1', 'Backtrace 2'])
17
- @message = AMF::Values::ErrorMessage.new(nil, @e)
18
- end
19
-
20
- it "should serialize as a hash in AMF0" do
21
- response = AMF::Response.new
22
- response.messages << AMF::Message.new('1/onStatus', '', @message)
23
- response.serialize.should == request_fixture('amf0-error-response.bin')
24
- end
25
-
26
- it "should extract exception properties correctly" do
27
- @message.faultCode.should == 'Exception'
28
- @message.faultString.should == 'Error message'
29
- @message.faultDetail.should == "Backtrace 1\nBacktrace 2"
30
- end
31
- end
@@ -1 +0,0 @@
1
- 
Binary file
Binary file
@@ -1 +0,0 @@
1
- 
Binary file
Binary file
Binary file
@@ -1 +0,0 @@
1
- 
Binary file
@@ -1 +0,0 @@
1
-   abc  
Binary file
Binary file
@@ -1,2 +0,0 @@
1
-
2
- /another_public_propertya_public_valuenil_propertyproperty_onefooproperty_two
@@ -1 +0,0 @@
1
- 
@@ -1 +0,0 @@
1
-     
@@ -1 +0,0 @@
1
- 
@@ -1 +0,0 @@
1
- 
@@ -1,2 +0,0 @@
1
-
2
- 
@@ -1 +0,0 @@
1
- ����
Binary file
@@ -1,11 +0,0 @@
1
- 
2
- foo_onebar_one
3
- foo_two
4
- foo_three*
5
- 
6
-  
7
- 
8
- 
9
-  * 
10
- 
11
- 
@@ -1 +0,0 @@
1
- 
Binary file
@@ -1 +0,0 @@
1
- 
@@ -1 +0,0 @@
1
- String . String
@@ -1 +0,0 @@
1
- foo
@@ -1 +0,0 @@
1
- 
@@ -1,2 +0,0 @@
1
-
2
- #'org.rackAMF.ASClassbazfoobar
@@ -1,6 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
2
- require 'rack/amf'
3
- require 'rack/amf/request'
4
-
5
- describe Rack::AMF::Request do
6
- end
@@ -1,47 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
2
- require 'rack/amf'
3
- require 'rack/amf/response'
4
-
5
- describe Rack::AMF::Response do
6
- it "should serialize response when converted to string" do
7
- response = Rack::AMF::Response.new(create_rack_request('commandMessage.bin'))
8
- response.raw_response.should_receive(:serialize).and_return('serialized')
9
- response.to_s.should == 'serialized'
10
- end
11
-
12
- it "should respond to ping command" do
13
- response = Rack::AMF::Response.new(create_rack_request('commandMessage.bin'))
14
- response.each_method_call {|method, args| nil}
15
-
16
- r = response.raw_response
17
- r.messages.length.should == 1
18
- r.messages[0].data.should be_a(AMF::Values::AcknowledgeMessage)
19
- end
20
-
21
- it "should handle RemotingMessages properly" do
22
- response = Rack::AMF::Response.new(create_rack_request('remotingMessage.bin'))
23
-
24
- response.each_method_call do |method, args|
25
- method.should == 'WritesController.save'
26
- args.should == [true]
27
- true
28
- end
29
-
30
- r = response.raw_response
31
- r.messages.length.should == 1
32
- r.messages[0].data.should be_a(AMF::Values::AcknowledgeMessage)
33
- r.messages[0].data.body.should == true
34
- end
35
-
36
- it "should catch exceptions properly" do
37
- response = Rack::AMF::Response.new(create_rack_request('remotingMessage.bin'))
38
- response.each_method_call do |method, args|
39
- raise 'Error in call'
40
- end
41
-
42
- r = response.raw_response
43
- r.messages.length.should == 1
44
- r.messages[0].data.should be_a(AMF::Values::ErrorMessage)
45
- r.messages[0].target_uri.should =~ /onStatus$/
46
- end
47
- end