groem 0.0.4
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.
- data/.autotest +24 -0
- data/.gitignore +3 -0
- data/Gemfile +3 -0
- data/HISTORY.markdown +9 -0
- data/README.markdown +185 -0
- data/TODO.markdown +7 -0
- data/groem.gemspec +24 -0
- data/lib/groem.rb +10 -0
- data/lib/groem/app.rb +197 -0
- data/lib/groem/client.rb +169 -0
- data/lib/groem/constants.rb +74 -0
- data/lib/groem/marshal.rb +349 -0
- data/lib/groem/notification.rb +140 -0
- data/lib/groem/response.rb +86 -0
- data/lib/groem/route.rb +37 -0
- data/lib/groem/version.rb +3 -0
- data/spec/functional/app_notify_adhoc_spec.rb +73 -0
- data/spec/functional/app_notify_spec.rb +390 -0
- data/spec/functional/app_register_spec.rb +113 -0
- data/spec/functional/client_spec.rb +361 -0
- data/spec/integration/notify.rb +318 -0
- data/spec/integration/register.rb +133 -0
- data/spec/shared/dummy_server.rb +198 -0
- data/spec/shared/dummy_server_helper.rb +31 -0
- data/spec/shared/marshal_helper.rb +40 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/unit/app_spec.rb +77 -0
- data/spec/unit/marshal_request_spec.rb +380 -0
- data/spec/unit/marshal_response_spec.rb +162 -0
- data/spec/unit/notification_spec.rb +205 -0
- data/spec/unit/response_spec.rb +7 -0
- data/spec/unit/route_spec.rb +93 -0
- metadata +141 -0
@@ -0,0 +1,113 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'..','spec_helper')
|
2
|
+
|
3
|
+
describe 'Groem::App #register' do
|
4
|
+
|
5
|
+
describe 'with one notification, server responds OK' do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@p_svr = DummyServerHelper.fork_server(:register => '-OK')
|
9
|
+
Groem::Client.response_class = MarshalHelper.dummy_response_class
|
10
|
+
@subject = Groem::App.new('test',:port => DummyServerHelper::DEFAULT_PORT)
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
DummyServerHelper.kill_server(@p_svr)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should receive back one OK response' do
|
18
|
+
count = 0
|
19
|
+
@subject.when_register do |resp|
|
20
|
+
count += 1
|
21
|
+
resp[0].to_i.must_equal 0
|
22
|
+
resp[2].must_be_empty
|
23
|
+
count.must_equal 1
|
24
|
+
end
|
25
|
+
|
26
|
+
@subject.when_register_failed do |resp|
|
27
|
+
count.must_equal 1
|
28
|
+
flunk 'Expected OK response, got error connecting or ERROR response'
|
29
|
+
end
|
30
|
+
|
31
|
+
@subject.register do
|
32
|
+
notification 'hello' do end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should return OK response' do
|
38
|
+
ret = \
|
39
|
+
@subject.register do
|
40
|
+
notification 'hello' do end
|
41
|
+
end
|
42
|
+
|
43
|
+
ret.class.must_be_same_as Groem::Response
|
44
|
+
ret[0].to_i.must_equal 0
|
45
|
+
ret[2].must_be_empty
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'with three notifications, server responds OK' do
|
51
|
+
|
52
|
+
before do
|
53
|
+
@p_svr = DummyServerHelper.fork_server(:register => '-OK')
|
54
|
+
Groem::Client.response_class = MarshalHelper.dummy_response_class
|
55
|
+
@subject = Groem::App.new('test',:port => DummyServerHelper::DEFAULT_PORT)
|
56
|
+
end
|
57
|
+
|
58
|
+
after do
|
59
|
+
DummyServerHelper.kill_server(@p_svr)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should receive back one OK response' do
|
63
|
+
count = 0
|
64
|
+
@subject.when_register do |resp|
|
65
|
+
count += 1
|
66
|
+
resp[0].to_i.must_equal 0
|
67
|
+
resp[2].must_be_empty
|
68
|
+
count.must_equal 1
|
69
|
+
end
|
70
|
+
|
71
|
+
@subject.when_register_failed do |resp|
|
72
|
+
count.must_equal 1
|
73
|
+
flunk 'Expected OK response, got error connecting or ERROR response'
|
74
|
+
end
|
75
|
+
|
76
|
+
@subject.register do
|
77
|
+
notification 'hello' do end
|
78
|
+
notification 'goodbye' do |n|
|
79
|
+
n.text = 'farewell lovey'
|
80
|
+
n.sticky = 'True'
|
81
|
+
n.title = 'Bon Voyage'
|
82
|
+
end
|
83
|
+
notification 'wait' do |n|
|
84
|
+
n.callback 'default', :type => 'confirm'
|
85
|
+
n.header 'x_something_else', 'tomorrow'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should return OK response' do
|
92
|
+
ret = \
|
93
|
+
@subject.register do
|
94
|
+
notification 'hello' do end
|
95
|
+
notification 'goodbye' do |n|
|
96
|
+
n.text = 'farewell lovey'
|
97
|
+
n.sticky = 'True'
|
98
|
+
n.title = 'Bon Voyage'
|
99
|
+
end
|
100
|
+
notification 'wait' do |n|
|
101
|
+
n.callback 'default', :type => 'confirm'
|
102
|
+
n.header 'x_something_else', 'tomorrow'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
ret.class.must_be_same_as Groem::Response
|
107
|
+
ret[0].to_i.must_equal 0
|
108
|
+
ret[2].must_be_empty
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
@@ -0,0 +1,361 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'..','spec_helper')
|
2
|
+
|
3
|
+
describe 'Groem::Client' do
|
4
|
+
|
5
|
+
describe 'REGISTER request, handle OK response' do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@p_svr = DummyServerHelper.fork_server(:register => '-OK')
|
9
|
+
|
10
|
+
@input_env = { 'protocol' => 'GNTP',
|
11
|
+
'version' => '1.0',
|
12
|
+
'request_method' => 'REGISTER',
|
13
|
+
'encryption_id' => 'NONE'
|
14
|
+
}
|
15
|
+
@input_hdrs = {'Application-Name' => 'SurfWriter',
|
16
|
+
'Application-Icon' => 'http://www.site.org/image.jpg'
|
17
|
+
}
|
18
|
+
|
19
|
+
@input_notifs = { 'Download Complete' => {
|
20
|
+
'Notification-Display-Name' => 'Download completed',
|
21
|
+
'Notification-Enabled' => 'True',
|
22
|
+
'X-Language' => 'English',
|
23
|
+
'X-Timezone' => 'PST'
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
@input = MarshalHelper.dummy_request(
|
28
|
+
@input_env, @input_hdrs, @input_notifs)
|
29
|
+
|
30
|
+
Groem::Client.response_class = MarshalHelper.dummy_response_class
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
after do
|
35
|
+
DummyServerHelper.kill_server(@p_svr)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should receive back one OK response' do
|
39
|
+
ok_count = 0
|
40
|
+
error_count = 0
|
41
|
+
callback_count = 0
|
42
|
+
EM.run {
|
43
|
+
puts "Client sending request"
|
44
|
+
connect = Groem::Client.register(@input, 'localhost', DummyServerHelper::DEFAULT_PORT)
|
45
|
+
|
46
|
+
connect.when_ok do |resp|
|
47
|
+
puts "Client received OK response"
|
48
|
+
ok_count += 1
|
49
|
+
resp[0].to_i.must_equal 0
|
50
|
+
resp[2].must_be_empty
|
51
|
+
end
|
52
|
+
|
53
|
+
connect.errback do |resp|
|
54
|
+
puts "Client received error response"
|
55
|
+
error_count += 1
|
56
|
+
end
|
57
|
+
|
58
|
+
connect.when_callback do |resp|
|
59
|
+
puts "Client received callback response"
|
60
|
+
callback_count += 1
|
61
|
+
end
|
62
|
+
|
63
|
+
EM.add_timer(1) {
|
64
|
+
count = ok_count + error_count + callback_count
|
65
|
+
flunk "Expected one response, #{count} received" unless count == 1
|
66
|
+
flunk 'Expected OK response, none received' unless ok_count == 1
|
67
|
+
EM.stop
|
68
|
+
}
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
describe 'REGISTER request, handle ERROR response' do
|
76
|
+
|
77
|
+
before do
|
78
|
+
@error_code = 500
|
79
|
+
@p_svr = DummyServerHelper.fork_server(:register => ['-ERROR', @error_code])
|
80
|
+
|
81
|
+
@input_env = { 'protocol' => 'GNTP',
|
82
|
+
'version' => '1.0',
|
83
|
+
'request_method' => 'REGISTER',
|
84
|
+
'encryption_id' => 'NONE'
|
85
|
+
}
|
86
|
+
@input_hdrs = {'Application-Name' => 'SurfWriter',
|
87
|
+
'Application-Icon' => 'http://www.site.org/image.jpg'
|
88
|
+
}
|
89
|
+
|
90
|
+
@input_notifs = { 'Download Complete' => {
|
91
|
+
'Notification-Display_name' => 'Download completed',
|
92
|
+
'Notification-Enabled' => 'True',
|
93
|
+
'X-Language' => 'English',
|
94
|
+
'X-Timezone' => 'PST'
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
@input = MarshalHelper.dummy_request(
|
99
|
+
@input_env, @input_hdrs, @input_notifs)
|
100
|
+
|
101
|
+
Groem::Client.response_class = MarshalHelper.dummy_response_class
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
after do
|
106
|
+
DummyServerHelper.kill_server(@p_svr)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should receive back one error response' do
|
110
|
+
ok_count = 0
|
111
|
+
error_count = 0
|
112
|
+
callback_count = 0
|
113
|
+
EM.run {
|
114
|
+
puts "Client sending request"
|
115
|
+
connect = Groem::Client.register(@input, 'localhost', DummyServerHelper::DEFAULT_PORT)
|
116
|
+
|
117
|
+
connect.when_ok do |resp|
|
118
|
+
puts "Client received OK response"
|
119
|
+
ok_count += 1
|
120
|
+
end
|
121
|
+
|
122
|
+
connect.errback do |resp|
|
123
|
+
puts "Client received error response"
|
124
|
+
error_count += 1
|
125
|
+
resp[0].to_i.must_equal @error_code.to_i
|
126
|
+
resp[2].must_be_empty
|
127
|
+
end
|
128
|
+
|
129
|
+
connect.when_callback do |resp|
|
130
|
+
puts "Client received callback response"
|
131
|
+
callback_count += 1
|
132
|
+
end
|
133
|
+
|
134
|
+
EM.add_timer(1) {
|
135
|
+
count = ok_count + error_count + callback_count
|
136
|
+
flunk "Expected one response, #{count} received" unless count == 1
|
137
|
+
flunk 'Expected ERROR response, none received' unless error_count == 1
|
138
|
+
EM.stop
|
139
|
+
}
|
140
|
+
}
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
describe 'NOTIFY request, no callback specified, handle OK response' do
|
146
|
+
#TODO: basically the same as REGISTER -OK
|
147
|
+
end
|
148
|
+
|
149
|
+
describe 'NOTIFY request, no callback specified, handle ERROR response' do
|
150
|
+
#TODO: basically the same as REGISTER -ERROR
|
151
|
+
end
|
152
|
+
|
153
|
+
describe 'NOTIFY request, callback specified, handle OK and CALLBACK response' do
|
154
|
+
|
155
|
+
before do
|
156
|
+
@callback_delay = 3
|
157
|
+
@callback_result = 'CLICKED'
|
158
|
+
@p_svr = DummyServerHelper.fork_server(:notify => '-OK',
|
159
|
+
:callback => [@callback_result, @callback_delay])
|
160
|
+
|
161
|
+
@input_env = { 'protocol' => 'GNTP',
|
162
|
+
'version' => '1.0',
|
163
|
+
'request_method' => 'NOTIFY',
|
164
|
+
'encryption_id' => 'NONE'
|
165
|
+
}
|
166
|
+
@input_hdrs = {'Application-Name' => 'SurfWriter',
|
167
|
+
'Notification-ID' => '999',
|
168
|
+
'Notification-Callback-Context' => 'default',
|
169
|
+
'Notification-Callback-Context-Type' => 'confirm'
|
170
|
+
}
|
171
|
+
|
172
|
+
@input = MarshalHelper.dummy_request(
|
173
|
+
@input_env, @input_hdrs, {})
|
174
|
+
|
175
|
+
Groem::Client.response_class = MarshalHelper.dummy_response_class
|
176
|
+
|
177
|
+
@ok_count = 0
|
178
|
+
@error_count = 0
|
179
|
+
@callback_count = 0
|
180
|
+
|
181
|
+
EM.run {
|
182
|
+
puts "Client sending request"
|
183
|
+
connect = Groem::Client.notify(@input, 'localhost', DummyServerHelper::DEFAULT_PORT)
|
184
|
+
|
185
|
+
connect.when_ok do |resp|
|
186
|
+
puts "Client received OK response"
|
187
|
+
@ok_count += 1
|
188
|
+
resp[0].to_i.must_equal 0
|
189
|
+
resp[2].must_be_empty
|
190
|
+
end
|
191
|
+
|
192
|
+
connect.errback do |resp|
|
193
|
+
puts "Client received error response"
|
194
|
+
@error_count += 1
|
195
|
+
end
|
196
|
+
|
197
|
+
connect.when_callback do |resp|
|
198
|
+
puts "Client received callback response"
|
199
|
+
resp[2]['Notification-Callback-Result'].must_equal @callback_result
|
200
|
+
@callback_count += 1
|
201
|
+
end
|
202
|
+
|
203
|
+
EM.add_timer(@callback_delay + 1) { EM.stop }
|
204
|
+
}
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
after do
|
209
|
+
DummyServerHelper.kill_server(@p_svr)
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'should receive back one OK response' do
|
213
|
+
@ok_count.must_equal 1
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'should receive back one callback response after delay' do
|
217
|
+
@callback_count.must_equal 1
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'should receive no error response' do
|
221
|
+
@error_count.must_equal 0
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
225
|
+
|
226
|
+
describe 'NOTIFY request, callback specified, handle ERROR response' do
|
227
|
+
|
228
|
+
before do
|
229
|
+
@callback_delay = 3
|
230
|
+
@callback_result = 'CLICKED'
|
231
|
+
@error_code = '303'
|
232
|
+
@p_svr = DummyServerHelper.fork_server(:notify => ['-ERROR', @error_code],
|
233
|
+
:callback => [@callback_result, @callback_delay])
|
234
|
+
|
235
|
+
@input_env = { 'protocol' => 'GNTP',
|
236
|
+
'version' => '1.0',
|
237
|
+
'request_method' => 'NOTIFY',
|
238
|
+
'encryption_id' => 'NONE'
|
239
|
+
}
|
240
|
+
@input_hdrs = {'Application-Name' => 'SurfWriter',
|
241
|
+
'Notification-ID' => '999',
|
242
|
+
'Notification-Callback-Context' => 'default',
|
243
|
+
'Notification-Callback-Context-Type' => 'confirm'
|
244
|
+
}
|
245
|
+
|
246
|
+
@input = MarshalHelper.dummy_request(
|
247
|
+
@input_env, @input_hdrs, {})
|
248
|
+
|
249
|
+
Groem::Client.response_class = MarshalHelper.dummy_response_class
|
250
|
+
|
251
|
+
@ok_count = 0
|
252
|
+
@error_count = 0
|
253
|
+
@callback_count = 0
|
254
|
+
|
255
|
+
EM.run {
|
256
|
+
puts "Client sending request"
|
257
|
+
connect = Groem::Client.notify(@input, 'localhost', DummyServerHelper::DEFAULT_PORT)
|
258
|
+
|
259
|
+
connect.when_ok do |resp|
|
260
|
+
puts "Client received OK response"
|
261
|
+
@ok_count += 1
|
262
|
+
end
|
263
|
+
|
264
|
+
connect.errback do |resp|
|
265
|
+
puts "Client received error response"
|
266
|
+
@error_count += 1
|
267
|
+
resp[0].to_i.must_equal @error_code.to_i
|
268
|
+
resp[2].must_be_empty
|
269
|
+
end
|
270
|
+
|
271
|
+
connect.when_callback do |resp|
|
272
|
+
puts "Client received callback response"
|
273
|
+
@callback_count += 1
|
274
|
+
end
|
275
|
+
|
276
|
+
EM.add_timer(@callback_delay + 1) { EM.stop }
|
277
|
+
}
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
after do
|
282
|
+
DummyServerHelper.kill_server(@p_svr)
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'should receive back no OK response' do
|
286
|
+
@ok_count.must_equal 0
|
287
|
+
end
|
288
|
+
|
289
|
+
it 'should receive back no callback response' do
|
290
|
+
@callback_count.must_equal 0
|
291
|
+
end
|
292
|
+
|
293
|
+
it 'should receive one error response' do
|
294
|
+
@error_count.must_equal 1
|
295
|
+
end
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
describe 'NOTIFY request, callback specified, handle only CALLBACK response' do
|
300
|
+
|
301
|
+
before do
|
302
|
+
@callback_delay = 3
|
303
|
+
@callback_result = 'CLICKED'
|
304
|
+
@p_svr = DummyServerHelper.fork_server(:notify => '-OK',
|
305
|
+
:callback => [@callback_result, @callback_delay])
|
306
|
+
|
307
|
+
@input_env = { 'protocol' => 'GNTP',
|
308
|
+
'version' => '1.0',
|
309
|
+
'request_method' => 'NOTIFY',
|
310
|
+
'encryption_id' => 'NONE'
|
311
|
+
}
|
312
|
+
@input_hdrs = {'Application-Name' => 'SurfWriter',
|
313
|
+
'Notification-ID' => '999',
|
314
|
+
'Notification-Callback-Context' => 'default',
|
315
|
+
'Notification-Callback-Context-Type' => 'confirm'
|
316
|
+
}
|
317
|
+
|
318
|
+
@input = MarshalHelper.dummy_request(
|
319
|
+
@input_env, @input_hdrs, {})
|
320
|
+
|
321
|
+
Groem::Client.response_class = MarshalHelper.dummy_response_class
|
322
|
+
|
323
|
+
@error_count = 0
|
324
|
+
@callback_count = 0
|
325
|
+
|
326
|
+
EM.run {
|
327
|
+
puts "Client sending request"
|
328
|
+
connect = Groem::Client.notify(@input, 'localhost', DummyServerHelper::DEFAULT_PORT)
|
329
|
+
|
330
|
+
connect.errback do |resp|
|
331
|
+
puts "Client received error response"
|
332
|
+
@error_count += 1
|
333
|
+
end
|
334
|
+
|
335
|
+
connect.when_callback do |resp|
|
336
|
+
puts "Client received callback response"
|
337
|
+
puts resp.inspect
|
338
|
+
resp[2]['Notification-Callback-Result'].must_equal @callback_result
|
339
|
+
@callback_count += 1
|
340
|
+
end
|
341
|
+
|
342
|
+
EM.add_timer(@callback_delay + 1) { EM.stop }
|
343
|
+
}
|
344
|
+
|
345
|
+
end
|
346
|
+
|
347
|
+
after do
|
348
|
+
DummyServerHelper.kill_server(@p_svr)
|
349
|
+
end
|
350
|
+
|
351
|
+
it 'should receive back one callback response after delay' do
|
352
|
+
@callback_count.must_equal 1
|
353
|
+
end
|
354
|
+
|
355
|
+
it 'should receive no error response' do
|
356
|
+
@error_count.must_equal 0
|
357
|
+
end
|
358
|
+
|
359
|
+
end
|
360
|
+
|
361
|
+
end
|