nebulous_stomp 2.0.2 → 3.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 (40) hide show
  1. checksums.yaml +4 -4
  2. data/.hgignore +2 -0
  3. data/.hgtags +1 -0
  4. data/README.md +225 -28
  5. data/feature/connection_example.yaml +24 -0
  6. data/feature/feature_test_spec.rb +247 -0
  7. data/feature/gimme.rb +91 -0
  8. data/lib/nebulous_stomp/listener.rb +107 -0
  9. data/lib/nebulous_stomp/message.rb +132 -265
  10. data/lib/nebulous_stomp/msg/body.rb +169 -0
  11. data/lib/nebulous_stomp/msg/header.rb +98 -0
  12. data/lib/nebulous_stomp/param.rb +16 -35
  13. data/lib/nebulous_stomp/redis_handler.rb +19 -29
  14. data/lib/nebulous_stomp/redis_handler_null.rb +12 -11
  15. data/lib/nebulous_stomp/redis_helper.rb +110 -0
  16. data/lib/nebulous_stomp/request.rb +212 -0
  17. data/lib/nebulous_stomp/stomp_handler.rb +30 -96
  18. data/lib/nebulous_stomp/stomp_handler_null.rb +8 -22
  19. data/lib/nebulous_stomp/target.rb +52 -0
  20. data/lib/nebulous_stomp/version.rb +1 -1
  21. data/lib/nebulous_stomp.rb +63 -50
  22. data/md/LICENSE.txt +20 -2
  23. data/md/nebulous_protocol.md +25 -18
  24. data/spec/listener_spec.rb +104 -0
  25. data/spec/message_spec.rb +227 -116
  26. data/spec/nebulous_spec.rb +44 -9
  27. data/spec/param_spec.rb +16 -33
  28. data/spec/redis_handler_null_spec.rb +0 -2
  29. data/spec/redis_handler_spec.rb +0 -2
  30. data/spec/redis_helper_spec.rb +107 -0
  31. data/spec/request_spec.rb +249 -0
  32. data/spec/stomp_handler_null_spec.rb +33 -34
  33. data/spec/stomp_handler_spec.rb +1 -74
  34. data/spec/target_spec.rb +97 -0
  35. metadata +20 -11
  36. data/lib/nebulous_stomp/nebrequest.rb +0 -259
  37. data/lib/nebulous_stomp/nebrequest_null.rb +0 -37
  38. data/spec/nebrequest_null_spec.rb +0 -219
  39. data/spec/nebrequest_spec.rb +0 -239
  40. data/spec/through_test_spec.rb +0 -80
data/spec/param_spec.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
  require 'nebulous_stomp/param'
3
2
 
4
3
  include NebulousStomp
@@ -6,8 +5,10 @@ include NebulousStomp
6
5
 
7
6
  describe Param do
8
7
 
9
- before { Param.reset }
10
- after(:all) { Param.reset }
8
+ before { Param.send :reset }
9
+ after(:all) { Param.send :reset }
10
+
11
+ let(:target1) { Target.new(name: 'foo', receiveQueue: '/queue/foo', sendQueue: '/queue/bar') }
11
12
 
12
13
 
13
14
  describe "Param.set" do
@@ -35,30 +36,13 @@ describe Param do
35
36
 
36
37
  describe "Param.add_target" do
37
38
 
38
- let(:hash1) { {receiveQueue: '/queue/foo', sendQueue: '/queue/bar'} }
39
-
40
- it "rejects unkown values in the param string for the target" do
41
- expect { Param.add_target(:foo, {:notAValidThing => 14}) }.to \
42
- raise_exception NebulousError
43
-
44
- end
45
-
46
- it "expects both a send queue and a receive queue" do
47
- h = {receiveQueue: '/queue/foo'}
48
- expect{ Param.add_target(:foo, h) }.to raise_exception(NebulousError)
49
-
50
- h = {sendQueue: '/queue/foo'}
51
- expect{ Param.add_target(:foo, h) }.to raise_exception(NebulousError)
39
+ it "rejects a target that's not a Target" do
40
+ expect { Param.add_target(:notAValidThing => 14) }.to raise_exception NebulousError
52
41
  end
53
42
 
54
43
  it 'works even when set has not been called' do
55
- Param.reset
56
- expect{ Param.add_target(:foo, hash1) }.not_to raise_exception
57
- end
58
-
59
- it "adds legitimate parameters to the target hash" do
60
- Param.add_target(:foo, hash1)
61
- expect( Param.get_all[:targets][:foo] ).to include(hash1)
44
+ Param.send :reset
45
+ expect{ Param.add_target(target1) }.not_to raise_exception
62
46
  end
63
47
 
64
48
  end # of Param:add_target
@@ -89,21 +73,20 @@ describe Param do
89
73
  describe "Param.get_target" do
90
74
 
91
75
  before do
92
- @targ = {receiveQueue: 'foo', sendQueue: 'bar'}
93
- Param.add_target(:one, @targ)
76
+ Param.add_target(target1)
94
77
  end
95
78
 
96
- it "throws an exception if you ask for a target it doesn't have" do
97
- expect{ Param.get_target(:two) }.to raise_exception(NebulousError)
79
+ it "returns nil if you ask for a target it doesn't have" do
80
+ expect( Param.get_target(:two) ).to be_nil
98
81
  end
99
82
 
100
- it "returns the target hash corresponding to the name" do
101
- expect( Param.get_target(:one) ).to include(@targ)
83
+ it "returns the Target corresponding to the name" do
84
+ expect( Param.get_target(:foo) ).to eq target1
102
85
  end
103
86
 
104
87
  it 'does not freak out if set() was never called' do
105
- Param.reset
106
- expect{ Param.get_target(:one) }.not_to raise_exception
88
+ Param.send :reset
89
+ expect{ Param.get_target(:foo) }.not_to raise_exception
107
90
  end
108
91
 
109
92
  end # of get_target
@@ -120,7 +103,7 @@ describe Param do
120
103
  end
121
104
 
122
105
  it 'does not freak out if set_logger() was never called' do
123
- Param.reset
106
+ Param.send :reset
124
107
  expect{ Param.get_logger }.not_to raise_exception
125
108
  end
126
109
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  require 'nebulous_stomp/redis_handler_null'
4
2
 
5
3
  include NebulousStomp
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  require 'nebulous_stomp/redis_handler'
4
2
 
5
3
  include NebulousStomp
@@ -0,0 +1,107 @@
1
+ require 'json'
2
+
3
+ require 'nebulous_stomp/redis_helper'
4
+ require 'nebulous_stomp/redis_handler_null'
5
+
6
+ include NebulousStomp
7
+
8
+
9
+ describe RedisHelper do
10
+
11
+ before do
12
+ @redis_hash = {host: '127.0.0.1', port: 6379, db: 0}
13
+ NebulousStomp.init(:redisConnectHash => @redis_hash)
14
+ @redis_handler = RedisHandlerNull.new(@redis_hash)
15
+ end
16
+
17
+ let(:helper) do
18
+ helper = RedisHelper.new
19
+ helper.redis_handler = @redis_handler
20
+ helper
21
+ end
22
+
23
+ def insert_fake( value={woof: true} )
24
+ @redis_handler.insert_fake( "bark", {value: value}.to_json )
25
+ end
26
+
27
+
28
+
29
+ describe "set" do
30
+
31
+ it "takes a key and a value" do
32
+ expect{ helper.set(:foo, "bar") }.not_to raise_error
33
+ end
34
+
35
+ it "takes an optional timeout" do
36
+ expect{ helper.set(:foo, "bar", "baz") }.to raise_error ArgumentError
37
+ expect{ helper.set(:foo, "bar", 14) }.not_to raise_error
38
+ end
39
+
40
+ it "calls RedisHandler.set to write the value" do
41
+ expect( @redis_handler ).to receive(:set).with("foo", {value:"bar"}.to_json)
42
+ helper.set(:foo, "bar")
43
+
44
+ expect( @redis_handler ).to receive(:set).with("foo", {value:"bar"}.to_json, {ex: 14})
45
+ helper.set(:foo, "bar", 14)
46
+ end
47
+
48
+ end
49
+ ##
50
+
51
+
52
+ describe "get" do
53
+
54
+ it "takes a key" do
55
+ insert_fake
56
+ expect{ helper.get("bark") }.not_to raise_error
57
+ end
58
+
59
+ it "calls RedisHandler.get to retreive the value" do
60
+ insert_fake
61
+ expect( @redis_handler ).to receive(:get).with("bark")
62
+ helper.get "bark"
63
+ end
64
+
65
+ it "returns the corresponding value" do
66
+ insert_fake
67
+ expect( helper.get("bark") ).to eq( {woof: true} )
68
+ expect( helper.get(:bark) ).to eq( {woof: true} )
69
+
70
+ insert_fake("baaah")
71
+ expect( helper.get("bark") ).to eq "baaah"
72
+
73
+ insert_fake(woof: "loud")
74
+ expect( helper.get("bark") ).to eq( {woof: "loud"} )
75
+ end
76
+
77
+ it "returns nil if the key does not exist in the store" do
78
+ expect( helper.get(:bark) ).to be_nil
79
+ end
80
+
81
+ end
82
+ ##
83
+
84
+
85
+ describe "del" do
86
+
87
+ it "takes a key" do
88
+ insert_fake
89
+ expect{ helper.del(:bark) }.not_to raise_error
90
+ end
91
+
92
+ it "calls RedisHandler.del on that key" do
93
+ insert_fake
94
+ expect( @redis_handler ).to receive(:del).with("bark")
95
+ helper.del(:bark)
96
+ end
97
+
98
+ it "raises NebulousError if the key does not exist in the store" do
99
+ expect{ helper.del(:bark) }.to raise_error ArgumentError
100
+ end
101
+
102
+ end
103
+ ##
104
+
105
+ end
106
+
107
+
@@ -0,0 +1,249 @@
1
+ require 'nebulous_stomp/request'
2
+ require 'nebulous_stomp/stomp_handler_null'
3
+ require 'nebulous_stomp/redis_handler_null'
4
+
5
+ include NebulousStomp
6
+
7
+
8
+ describe Request do
9
+
10
+ before do
11
+ @stomp_hash = { hosts: [{ login: 'guest',
12
+ passcode: 'guest',
13
+ host: '10.0.0.150',
14
+ port: 61613,
15
+ ssl: false }],
16
+ reliable: false }
17
+
18
+ @redis_hash = {host: '127.0.0.1', port: 6379, db: 0}
19
+
20
+ @stomp_handler = StompHandlerNull.new(@stomp_hash)
21
+ @redis_handler = RedisHandlerNull.new(@redis_hash)
22
+
23
+ NebulousStomp.init( :stompConnectHash => @stomp_hash,
24
+ :redisConnectHash => @redis_hash,
25
+ :messageTimeout => 5,
26
+ :cacheTimeout => 20 )
27
+
28
+ NebulousStomp.add_target( :accord,
29
+ :sendQueue => "/queue/laplace.dev",
30
+ :receiveQueue => "/queue/laplace.out",
31
+ :messageTimeout => 1 )
32
+
33
+ end
34
+
35
+ def new_request(target, message)
36
+ r = Request.new(target, message)
37
+ r.stomp_handler = @stomp_handler
38
+ r.redis_handler = @redis_handler
39
+ r
40
+ end
41
+
42
+ def turn_off_redis
43
+ Param.set(:stompConnectHash => @stomp_hash, :redisConnectHash => nil)
44
+ @redis_handler = nil
45
+ end
46
+
47
+ def turn_off_nebulous
48
+ Param.set(:stompConnectHash => nil, :redisConnectHash => @redis_hash)
49
+ @nebulous_handler = nil
50
+ end
51
+
52
+ let(:target1) do
53
+ Target.new( name: "target1",
54
+ sendQueue: "/queue/foo",
55
+ receiveQueue: "/queue/bar" )
56
+
57
+ end
58
+
59
+ let(:target2) do
60
+ Target.new( name: "target1",
61
+ sendQueue: "/queue/foo",
62
+ receiveQueue: "/queue/bar",
63
+ messageTimeout: 1 )
64
+
65
+ end
66
+
67
+ let(:message1) do
68
+ Message.new( verb: "boop", params: "booper", desc: "booping")
69
+ end
70
+
71
+ let(:message2) do
72
+ Message.new( verb: "parp", params: "parper", desc: "parping", replyTo: "parps" )
73
+ end
74
+
75
+ let(:request1) do
76
+ request = new_request(target1, message1)
77
+ @stomp_handler.insert_fake Message.new(inReplyTo: request.message.reply_id, verb: "foo")
78
+ request
79
+ end
80
+
81
+
82
+ describe "Request.new" do
83
+
84
+ it "requires a Target or a target name as the first parameter" do
85
+ expect{ Request.new(nil, message1) }.to raise_error ArgumentError
86
+ expect{ Request.new(14, message1) }.to raise_error ArgumentError
87
+
88
+ expect{ Request.new(target1, message1) }.not_to raise_error
89
+ expect{ Request.new("accord", message1) }.not_to raise_error
90
+ end
91
+
92
+ it "requires a Message as the second parameter" do
93
+ expect{ Request.new(target1, :foo) }.to raise_error ArgumentError
94
+ expect{ Request.new(target1, nil) }.to raise_error ArgumentError
95
+
96
+ expect{ Request.new(target1, message1) }.not_to raise_error
97
+ end
98
+
99
+ it "expects the message parameter to follow The Protocol" do
100
+ m = Message.new(body: "blarg")
101
+ expect{ Request.new(target1, m) }.to raise_error ArgumentError
102
+ end
103
+
104
+ it "stores the given message if it has a reply_to" do
105
+ expect( Request.new(target1, message2).message ).to eq message2
106
+ end
107
+
108
+ it "stores a new message with a reply_to from the target if the given one is missing it" do
109
+ r = new_request(target1, message1)
110
+ expect( r.message ).not_to eq message1
111
+ expect( r.message.verb ).to eq message1.verb
112
+ expect( r.message.params ).to eq message1.params
113
+ expect( r.message.desc ).to eq message1.desc
114
+ expect( r.message.reply_to ).to eq target1.send_queue
115
+ end
116
+
117
+ end
118
+
119
+
120
+ describe "message_timeout" do
121
+
122
+ it "takes the timeout on the target over the default" do
123
+ r = new_request(target2, message1)
124
+ expect( r.message_timeout ).to eq 1
125
+ end
126
+
127
+ it "falls back to the default if the timeout on the target is not set" do
128
+ r = new_request(target1, message1)
129
+ expect( r.message_timeout ).to eq 5
130
+ end
131
+
132
+ end
133
+
134
+
135
+ describe "cache_timeout" do
136
+
137
+ it "returns the cache timeout value stored in Param" do
138
+ r = new_request(target1, message1)
139
+ expect( r.cache_timeout ).to eq 20
140
+ end
141
+
142
+ end
143
+
144
+
145
+ describe "send_no_cache" do
146
+
147
+ it "returns a response from StompHandler" do
148
+ response = request1.send_no_cache
149
+ expect( response ).to be_a NebulousStomp::Message
150
+ expect( response.verb ).to eq "foo"
151
+ end
152
+
153
+ it "raises a NebulousTimeout if there is no response" do
154
+ request = new_request('accord', message1)
155
+
156
+ # if we don't give StompHandlerNull a response to send, request should time out
157
+ expect{ request.send_no_cache }.to raise_exception NebulousStomp::NebulousTimeout
158
+ end
159
+
160
+ it "returns nil if Nebulous is disabled in the config" do
161
+ turn_off_nebulous
162
+ request = new_request('accord', message1)
163
+ expect( request.send_no_cache ).to be_nil
164
+ end
165
+
166
+ end
167
+
168
+
169
+ describe "clear_cache" do
170
+
171
+ it "removes the redis cache for a single request" do
172
+ @redis_handler.insert_fake('foo', 'bar')
173
+ expect( @redis_handler ).to receive(:del).with( message1.protocol_json )
174
+
175
+ new_request(target1, message1).clear_cache
176
+ end
177
+
178
+ it "returns self" do
179
+ @redis_handler.insert_fake('foo', 'bar')
180
+ r = new_request(target1, message1)
181
+
182
+ expect( r.clear_cache ).to eq r
183
+ end
184
+
185
+ it "doesn't freak out if Redis is not connected" do
186
+ turn_off_redis
187
+ r = new_request(target1, message1)
188
+ expect{ r.clear_cache }.not_to raise_exception
189
+ expect( r.clear_cache ).to eq r
190
+ end
191
+
192
+ end
193
+
194
+
195
+ describe "send" do
196
+
197
+ it "returns a Message object from STOMP the first time" do
198
+ response = request1.send
199
+ expect( response ).to be_a NebulousStomp::Message
200
+ expect( response.verb ).to eq "foo"
201
+ end
202
+
203
+ it "returns the answer from the cache the second time" do
204
+ @stomp_handler.insert_fake Message.new(verb: "foo")
205
+ @redis_handler.insert_fake( "xxx", {'verb' => 'frog'}.to_json )
206
+
207
+ # First time
208
+ request = new_request(target1, message1)
209
+ response = request.send
210
+
211
+ # Second time
212
+ request = new_request(target1, message1)
213
+ response = request.send
214
+
215
+ expect( response ).to be_a NebulousStomp::Message
216
+ expect( response.verb ).to eq "frog"
217
+ end
218
+
219
+ it "allows you to specify a message timeout" do
220
+ expect{ request1.send(3) }.not_to raise_exception
221
+ end
222
+
223
+ it "allows you to specify a message timeout & cache timeout" do
224
+ expect{ request1.send(3, 120) }.not_to raise_exception
225
+ end
226
+
227
+ it "raises a NebulousTimeout if there is no response" do
228
+ request = new_request(target1, message1)
229
+ expect{ request.send }.to raise_exception NebulousStomp::NebulousTimeout
230
+ end
231
+
232
+ it "still works if Redis is turned off in the config" do
233
+ turn_off_redis
234
+ response = request1.send
235
+ expect( response ).to be_a NebulousStomp::Message
236
+ expect( response.verb ).to eq "foo"
237
+ end
238
+
239
+ it "returns nil if Nebulous is disabled in the config" do
240
+ turn_off_nebulous
241
+ request = new_request(target1, message1)
242
+ expect( request.send ).to be_nil
243
+ end
244
+
245
+ end
246
+
247
+
248
+ end
249
+
@@ -1,7 +1,4 @@
1
- require 'spec_helper'
2
-
3
1
  require 'time'
4
-
5
2
  require 'nebulous_stomp/stomp_handler_null'
6
3
 
7
4
  include NebulousStomp
@@ -22,17 +19,6 @@ describe StompHandlerNull do
22
19
  end
23
20
 
24
21
 
25
- describe 'StompHandlerNull.body_to_hash' do
26
-
27
- it "returns a hash" do
28
- expect{ StompHandlerNull.body_to_hash({}, 'baz') }.not_to raise_exception
29
- expect( StompHandlerNull.body_to_hash({}, 'baz') ).to be_a_kind_of Hash
30
- end
31
-
32
- end
33
- ##
34
-
35
-
36
22
  describe "#initialize" do
37
23
 
38
24
  it "takes an initialization hash" do
@@ -46,9 +32,10 @@ describe StompHandlerNull do
46
32
  describe '#insert_fake' do
47
33
 
48
34
  it 'sets the message to send' do
49
- handler.insert_fake( Message.from_parts('', '','foo', 'bar', 'baz') )
50
- expect( handler.fake_mess ).to be_a_kind_of NebulousStomp::Message
51
- expect( handler.fake_mess.verb ).to eq 'foo'
35
+ handler.insert_fake( Message.new(verb: 'foo', params: 'bar', desc: 'baz') )
36
+ expect( handler.fake_messages ).to be_a_kind_of Array
37
+ expect( handler.fake_messages.first ).to be_a_kind_of NebulousStomp::Message
38
+ expect( handler.fake_messages.first.verb ).to eq 'foo'
52
39
  end
53
40
 
54
41
  end
@@ -62,7 +49,7 @@ describe StompHandlerNull do
62
49
  end
63
50
 
64
51
  it 'returns true if fake_message was called' do
65
- handler.insert_fake( Message.from_parts('','', 'one', 'two', 'three') )
52
+ handler.insert_fake( Message.new(verb: 'one', params: 'two', desc: 'three') )
66
53
  expect( handler.connected? ).to be_truthy
67
54
  end
68
55
 
@@ -92,7 +79,7 @@ describe StompHandlerNull do
92
79
 
93
80
 
94
81
  describe "send_message" do
95
- let(:mess) { NebulousStomp::Message.from_parts(nil, nil, 'foo', nil, nil) }
82
+ let(:mess) { NebulousStomp::Message.new(verb: 'foo') }
96
83
 
97
84
  it "accepts a queue name and a Message" do
98
85
  expect{ handler.send_message('foo', mess) }.not_to raise_exception
@@ -109,10 +96,10 @@ describe StompHandlerNull do
109
96
  describe "#listen" do
110
97
 
111
98
  def run_listen(secs)
112
- got = nil
99
+ got = []
113
100
 
114
101
  handler.listen('/queue/foo') do |m|
115
- got = m
102
+ got << m
116
103
  end
117
104
  sleep secs
118
105
 
@@ -120,12 +107,18 @@ describe StompHandlerNull do
120
107
  end
121
108
 
122
109
 
123
- it "yields a Message" do
124
- handler.insert_fake( Message.from_parts('', '', 'foo', 'bar', 'baz') )
125
- gotMessage = run_listen(1)
110
+ it "yields each Message" do
111
+ handler.insert_fake( Message.new(verb: 'foo', params: 'bar', desc: 'baz') )
112
+ handler.insert_fake( Message.new(verb: 'one', params: 'two', desc: 'three') )
113
+ messages = run_listen(1)
126
114
 
127
- expect(gotMessage).not_to be_nil
128
- expect(gotMessage).to be_a_kind_of NebulousStomp::Message
115
+ expect(messages.first).not_to be_nil
116
+ expect(messages.first).to be_a_kind_of NebulousStomp::Message
117
+ expect(messages.first.verb).to eq "foo"
118
+
119
+ expect(messages.last).not_to be_nil
120
+ expect(messages.last).to be_a_kind_of NebulousStomp::Message
121
+ expect(messages.last.verb).to eq "one"
129
122
  end
130
123
 
131
124
  end
@@ -135,22 +128,28 @@ describe StompHandlerNull do
135
128
  describe "listen_with_timeout" do
136
129
 
137
130
  def run_listen_with_timeout(secs)
138
- got = nil
131
+ got = []
139
132
  handler.listen_with_timeout('/queue/foo', secs) do |m|
140
- got = m
133
+ got << m
141
134
  end
142
135
 
143
136
  got
144
137
  end
145
138
 
146
- context "when there is a message" do
139
+ context "when there are messages" do
140
+
141
+ it "yields each Message" do
142
+ handler.insert_fake( Message.new(verb: 'foo', params: 'bar', desc: 'baz') )
143
+ handler.insert_fake( Message.new(verb: 'one', params: 'two', desc: 'three') )
144
+ messages = run_listen_with_timeout(1)
147
145
 
148
- it "yields a Message" do
149
- handler.insert_fake( Message.from_parts('', '', 'foo', 'bar', 'baz') )
150
- gotMessage = run_listen_with_timeout(1)
146
+ expect( messages.first ).not_to be_nil
147
+ expect( messages.first ).to be_a_kind_of NebulousStomp::Message
148
+ expect(messages.first.verb).to eq "foo"
151
149
 
152
- expect( gotMessage ).not_to be_nil
153
- expect( gotMessage ).to be_a_kind_of NebulousStomp::Message
150
+ expect(messages.last).not_to be_nil
151
+ expect(messages.last).to be_a_kind_of NebulousStomp::Message
152
+ expect(messages.last.verb).to eq "one"
154
153
  end
155
154
 
156
155
  end
@@ -1,5 +1,4 @@
1
1
  require 'time'
2
- require 'spec_helper'
3
2
 
4
3
  require 'nebulous_stomp/stomp_handler'
5
4
  require 'nebulous_stomp/message'
@@ -57,78 +56,6 @@ describe StompHandler do
57
56
  end
58
57
 
59
58
 
60
- describe 'StompHandler.body_to_hash' do
61
-
62
- it "raises an error unless headers is a hash" do
63
- expect{ StompHandler.body_to_hash() }.to raise_exception ArgumentError
64
-
65
- expect{ StompHandler.body_to_hash('foo') }.
66
- to raise_exception ArgumentError
67
-
68
- expect{ StompHandler.body_to_hash('foo', 'bar') }.
69
- to raise_exception ArgumentError
70
-
71
- expect{ StompHandler.body_to_hash({}, 'baz') }.not_to raise_exception
72
- end
73
-
74
- context "when the content type is JSON" do
75
-
76
- it "parses the json" do
77
- body = {'one' => 'two', 'three' => [4,5]}
78
- msg = stomp_message('application/json', body.to_json)
79
- expect( StompHandler.body_to_hash(msg.headers, msg.body) ).to eq body
80
-
81
- body = [ {'one' => 2, 'three' => 4}, {'five' => 6} ]
82
- msg = stomp_message('application/json', body.to_json)
83
- expect( StompHandler.body_to_hash(msg.headers, msg.body) ).to eq body
84
- end
85
-
86
- end
87
-
88
- context "when the content type is not JSON" do
89
-
90
- it "assumes text lines in key:value format" do
91
- # Note that all values will be strings, and we can't support arrays.
92
- result = {'one' => 'two', 'three' => '4'}
93
- body = result.map{|k,v| "#{k}:#{v}" }.join("\n")
94
- msg = stomp_message('application/text', body )
95
-
96
- expect( StompHandler.body_to_hash(msg.headers, msg.body) ).to eq result
97
- end
98
-
99
- end
100
-
101
- it "allows the caller to override the content type" do
102
- result = {'one' => 'two', 'three' => '4'}
103
- body = result.map{|k,v| "#{k}:#{v}" }.join("\n")
104
- msg = stomp_message('application/json', body )
105
-
106
- expect( StompHandler.body_to_hash( msg.headers,
107
- msg.body,
108
- 'application/text') ).to eq result
109
-
110
- end
111
-
112
- it "returns a hash or an array of hashes" do
113
- # lets check some corner cases to ensure this
114
- msg = stomp_message('appplication/json', ''.to_json)
115
- expect( StompHandler.body_to_hash(msg.headers, msg.body) ).to eq({})
116
-
117
- msg = stomp_message('appplication/json', nil.to_json)
118
- expect( StompHandler.body_to_hash(msg.headers, msg.body) ).to eq({})
119
-
120
- msg = stomp_message('appplication/text', '')
121
- expect( StompHandler.body_to_hash(msg.headers, msg.body) ).to eq({})
122
-
123
- msg = stomp_message('appplication/text', nil)
124
- expect( StompHandler.body_to_hash(msg.headers, msg.body) ).to eq({})
125
- end
126
-
127
-
128
- end
129
- ##
130
-
131
-
132
59
  describe "StompHandler.with_timeout" do
133
60
 
134
61
  it "should hang for the given timeout period" do
@@ -265,7 +192,7 @@ describe StompHandler do
265
192
  # We're kind of navel gazing here because send_message is just one line: a
266
193
  # call to client.publish. Still, call it a warming up exercise....
267
194
 
268
- let(:mess) { NebulousStomp::Message.from_parts(nil, nil, 'foo', nil, nil) }
195
+ let(:mess) { NebulousStomp::Message.new(verb: 'foo', params: nil, desc: nil) }
269
196
 
270
197
  before do
271
198
  handler.stomp_connect