Debian Codegraph @

ruby/spec/message_spec.rb

raw
1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17
18
19 require "spec_helper"
20
21 module Qpid
22
23 module Proton
24
25 describe "A message" do
26
27 before (:each) do
28 @message = Qpid::Proton::Message.new
29 end
30
31 it "can be created" do
32 @message.wont_be_nil
33 end
34
35 it "can be cleared" do
36 subject = random_string(16)
37 @message.subject = subject
38 @message.subject.must_equal(subject)
39 @message.clear
40 @message.subject.wont_equal(subject)
41 end
42
43 it "can be durable" do
44 @message.durable = true
45 @message.durable.must_equal(true)
46 @message.durable = false
47 @message.durable.must_equal(false)
48 end
49
50 it "raises an error when setting durable to nil" do
51 proc {
52 @message.durable = nil
53 }.must_raise(TypeError)
54 end
55
56 it "raises an error when setting the priority to nil" do
57 proc {
58 @message.priority = nil
59 }.must_raise(TypeError)
60 end
61
62 it "raises an error when setting the priority to a non-number" do
63 proc {
64 @message.priority = "abck"
65 }.must_raise(TypeError)
66 end
67
68 it "sets the priority to the integer portion when a float" do
69 priority = rand(100) / 10
70 @message.priority = priority
71 @message.priority.must_equal(priority.floor)
72 end
73
74 it "rejects a priority with too large of a value" do
75 proc {
76 @message.priority = (rand(100) + 256)
77 }.must_raise(RangeError)
78 end
79
80 it "rejects a negative priority" do
81 proc {
82 @message.priority = (0 - (rand(255) + 1))
83 }.must_raise(RangeError)
84 end
85
86 it "has a priority" do
87 priority = rand(256)
88 @message.priority = priority
89 @message.priority.must_equal(priority)
90 end
91
92 it "raises an error when setting the time-to-live to nil" do
93 proc {
94 @message.ttl = nil
95 }.must_raise(TypeError)
96 end
97
98 it "raises an error when setting the time-to-live to a non-number" do
99 proc {
100 @message.ttl = random_string(5)
101 }.must_raise(TypeError)
102 end
103
104 it "sets the time-to-live to the integer portion when a float" do
105 ttl = (rand(32767) / 10)
106 @message.ttl = ttl
107 @message.ttl.must_equal(ttl.floor)
108 end
109
110 it "raises an error when the time-to-live is negative" do
111 proc {
112 @message.ttl = (0 - (rand(1000) + 1))
113 }.must_raise(RangeError)
114 end
115
116 it "has a time-to-live" do
117 ttl = rand(32767)
118 @message.ttl = ttl
119 @message.ttl.must_equal(ttl)
120 end
121
122 it "raises an error when setting first acquirer to nil" do
123 proc {
124 @message.first_acquirer = nil
125 }.must_raise(TypeError)
126 end
127
128 it "raises and error when setting first acquirer to a non-boolean" do
129 proc {
130 @message.first_acquirer = random_string(16)
131 }.must_raise(TypeError)
132 end
133
134 it "has a first acquirer" do
135 @message.first_acquirer = true
136 @message.first_acquirer?.must_equal(true)
137
138 @message.first_acquirer = false
139 @message.first_acquirer?.must_equal(false)
140 end
141
142 it "raises an error on a nil delivery count" do
143 proc {
144 @message.delivery_count = nil
145 }.must_raise(::ArgumentError)
146 end
147
148 it "raises an error on a negative delivery count" do
149 proc {
150 @message.delivery_count = -1
151 }.must_raise(RangeError)
152 end
153
154 it "raises an error on a non-numeric delivery count" do
155 proc {
156 @message.delivery_count = "farkle"
157 }.must_raise(::ArgumentError)
158 end
159
160 it "converts a floating point delivery count to its integer portion" do
161 count = rand(255) / 10.0
162 @message.delivery_count = count
163 @message.delivery_count.must_equal(count.floor)
164 end
165
166 it "has a delivery count" do
167 count = rand(255)
168 @message.delivery_count = count
169 @message.delivery_count.must_equal(count)
170 end
171
172 it "allows setting a nil id" do
173 @message.id = nil
174 @message.id.must_be_nil
175 end
176
177 it "has an id" do
178 id = random_string(16)
179 @message.id = id
180 @message.id.must_equal(id)
181 end
182
183 it "allows setting a nil user id" do
184 @message.user_id = nil
185 @message.user_id.must_equal("")
186 end
187
188 it "has a user id" do
189 id = random_string(16)
190 @message.user_id = id
191 @message.user_id.must_equal(id)
192 end
193
194 it "allows setting a nil address" do
195 @message.address = nil
196 @message.address.must_be_nil
197 end
198
199 it "has an address" do
200 address = "//0.0.0.0/#{random_string(16)}"
201 @message.address = address
202 @message.address.must_equal(address)
203 end
204
205 it "allows setting a nil subject" do
206 @message.subject = nil
207 @message.subject.must_be_nil
208 end
209
210 it "has a subject" do
211 subject = random_string(50)
212 @message.subject = subject
213 @message.subject.must_equal(subject)
214 end
215
216 it "will allow a nil reply-to address" do
217 @message.reply_to = nil
218 @message.reply_to.must_be_nil
219 end
220
221 it "has a reply-to address" do
222 address = "//0.0.0.0/#{random_string(16)}"
223 @message.reply_to = address
224 @message.reply_to.must_equal(address)
225 end
226
227 it "will allow a nil correlation id" do
228 @message.correlation_id = nil
229 @message.correlation_id.must_be_nil
230 end
231
232 it "has a correlation id" do
233 id = random_string(25)
234 @message.correlation_id = id
235 @message.correlation_id.must_equal(id)
236 end
237
238 it "will allow a nil content type" do
239 @message.content_type = nil
240 @message.content_type.must_be_nil
241 end
242
243 it "will allow an empty content type" do
244 @message.content_type = ""
245 @message.content_type.must_equal("")
246 end
247
248 it "has a content type" do
249 content_type = random_string(32)
250 @message.content_type = content_type
251 @message.content_type.must_equal(content_type)
252 end
253
254 it "can have nil content encoding" do
255 @message.content_encoding = nil
256 @message.content_encoding.must_be_nil
257 end
258
259 it "has a content encoding" do
260 encoding = "#{random_string(8)}/#{random_string(8)}"
261 @message.content_encoding = encoding
262 @message.content_encoding.must_equal(encoding)
263 end
264
265 it "raises an error on a nil expiry time" do
266 proc {
267 @message.expires = nil
268 }.must_raise(TypeError)
269 end
270
271 it "raises an error on a negative expiry time" do
272 proc {
273 @message.expires = (0-(rand(65535)))
274 }.must_raise(::ArgumentError)
275 end
276
277 it "can have a zero expiry time" do
278 @message.expires = 0
279 @message.expires.must_equal(0)
280 end
281
282 it "has an expiry time" do
283 time = rand(65535)
284 @message.expires = time
285 @message.expires.must_equal(time)
286 end
287
288 it "raises an error on a nil creation time" do
289 proc {
290 @message.creation_time = nil
291 }.must_raise(TypeError)
292 end
293
294 it "raises an error on a negative creation time" do
295 proc {
296 @message.creation_time = (0 - rand(65535))
297 }.must_raise(::ArgumentError)
298 end
299
300 it "can have a zero creation time" do
301 @message.creation_time = 0
302 @message.creation_time.must_equal(0)
303 end
304
305 it "has a creation time" do
306 time = rand(65535)
307 @message.creation_time = time
308 @message.creation_time.must_equal(time)
309 end
310
311 it "can have a nil group id" do
312 @message.group_id = nil
313 @message.group_id.must_be_nil
314 end
315
316 it "can have an empty group id" do
317 @message.group_id = ""
318 @message.group_id.must_equal("")
319 end
320
321 it "has a group id" do
322 id = random_string(16)
323 @message.group_id = id
324 @message.group_id.must_equal(id)
325 end
326
327
328 it "raises an error on a nil group sequence" do
329 proc {
330 @message.group_sequence = nil
331 }.must_raise(TypeError)
332 end
333
334 it "can have a zero group sequence" do
335 @message.group_sequence = 0
336 @message.group_sequence.must_equal(0)
337 end
338
339 it "has a group sequence" do
340 id = rand(4294967295)
341 @message.group_sequence = id
342 @message.group_sequence.must_equal(id)
343 end
344
345 it "can have a nil reply-to group id" do
346 @message.reply_to_group_id = nil
347 @message.reply_to_group_id.must_be_nil
348 end
349
350 it "can have an empty reply-to group id" do
351 @message.reply_to_group_id = ""
352 @message.reply_to_group_id.must_equal("")
353 end
354
355 it "has a reply-to group id" do
356 id = random_string(16)
357 @message.reply_to_group_id = id
358 @message.reply_to_group_id.must_equal(id)
359 end
360
361 it "has properties" do
362 @message.must_respond_to(:properties)
363 @message.must_respond_to(:properties=)
364 @message.must_respond_to(:[])
365 @message.must_respond_to(:[]=)
366
367 @message.properties.must_be_kind_of({}.class)
368 end
369
370 it "can replace the set of properties" do
371 values = random_hash(128)
372
373 @message.properties = values.clone
374 @message.properties.must_equal(values)
375 end
376
377 it "can set properties" do
378 name = random_string(16)
379 value = random_string(128)
380
381 @message[name] = value
382 @message[name].must_equal(value)
383 end
384
385 it "can update properties" do
386 name = random_string(16)
387 value = random_string(128)
388
389 @message[name] = value
390 @message[name].must_equal(value)
391
392 value = random_string(128)
393 @message[name] = value
394 @message[name].must_equal(value)
395 end
396
397 it "can hold a null property" do
398 name = random_string(16)
399 value = random_string(128)
400
401 @message[name] = value
402 @message[name].must_equal(value)
403
404 @message[name] = nil
405 @message[name].must_be_nil
406 end
407
408 it "can delete a property" do
409 name = random_string(16)
410 value = random_string(128)
411
412 @message[name] = value
413 @message[name].must_equal(value)
414
415 @message.delete_property(name)
416 @message.properties.keys.wont_include(name)
417 end
418
419 it "has no properties after being cleared" do
420 name = random_string(16)
421 value = random_string(128)
422
423 @message[name] = value
424 @message[name].must_equal(value)
425
426 @message.clear
427 @message.properties.must_be_empty
428 end
429
430 it "has instructions" do
431 @message.must_respond_to(:instructions)
432 @message.must_respond_to("instructions=".to_sym)
433 end
434
435 it "can set an instruction" do
436 name = random_string(16)
437 value = random_string(128)
438
439 @message.instructions[name] = value
440 @message.instructions[name].must_equal(value)
441 end
442
443 it "can update an instruction" do
444 name = random_string(16)
445 value = random_string(128)
446
447 @message.instructions[name] = value
448 @message.instructions[name].must_equal(value)
449
450 value = random_string(128)
451 @message.instructions[name] = value
452 @message.instructions[name].must_equal(value)
453 end
454
455 it "can delete the instructions" do
456 name = random_string(16)
457 value = random_string(128)
458
459 @message.instructions[name] = value
460 @message.instructions.wont_be_empty
461
462 @message.instructions = nil
463 @message.instructions.must_be_nil
464 end
465
466 it "can replace the instructions" do
467 values = random_hash(rand(128) + 1)
468
469 @message.instructions = values.clone
470 @message.instructions.must_equal(values)
471
472 values = random_hash(rand(64) + 1)
473
474 @message.instructions = values.clone
475 @message.instructions.must_equal(values)
476 end
477
478 it "can delete the set of instructions" do
479 values = random_hash(rand(128) + 1)
480
481 @message.instructions = values.clone
482 @message.instructions.must_equal(values)
483
484 @message.instructions = nil
485 @message.instructions.must_be_nil
486 end
487
488 it "has no instructions after being cleared" do
489 value = random_hash(128)
490
491 @message.instructions = value.clone
492 @message.instructions.must_equal(value)
493
494 @message.clear
495 @message.instructions.must_be_empty
496 end
497
498 it "has annotations" do
499 @message.must_respond_to(:annotations)
500 @message.must_respond_to(:annotations=)
501 end
502
503 it "can set an annotation" do
504 name = random_hash(32)
505 value = random_hash(256)
506
507 @message.annotations[name] = value.clone
508 @message.annotations[name].must_equal(value)
509 end
510
511 it "can update an annotation" do
512 name = random_hash(32)
513 value = random_hash(256)
514
515 @message.annotations[name] = value.clone
516 @message.annotations[name].must_equal(value)
517
518 value = random_hash(128)
519
520 @message.annotations[name] = value.clone
521 @message.annotations[name].must_equal(value)
522 end
523
524 it "can delete an annotation" do
525 name = random_hash(32)
526 value = random_hash(256)
527
528 @message.annotations[name] = value.clone
529 @message.annotations[name].must_equal(value)
530
531 @message.annotations[name] = nil
532 @message.annotations[name].must_be_nil
533 end
534
535 it "can replace all annotations" do
536 values = random_hash(rand(128) + 1)
537
538 @message.annotations = values.clone
539 @message.annotations.must_equal(values)
540
541 values = random_hash(rand(64) + 1)
542
543 @message.annotations = values.clone
544 @message.annotations.must_equal(values)
545 end
546
547 it "can delete the set of annotations" do
548 value = random_hash(rand(128) + 1)
549
550 @message.annotations = value.clone
551 @message.annotations.must_equal(value)
552
553 @message.annotations = nil
554 @message.annotations.must_be_nil
555 end
556
557 it "has no annotations after being cleared" do
558 value = random_hash(16)
559
560 @message.annotations = value
561 @message.annotations.must_equal(value)
562
563 @message.clear
564 @message.annotations.must_be_empty
565 end
566
567 it "has a body property" do
568 @message.must_respond_to(:body)
569 @message.must_respond_to(:body=)
570 end
571
572 it "has a default body that is nil" do
573 @message.body.must_be_nil
574 end
575
576 it "has no body after being cleared" do
577 value = random_string(128)
578
579 @message.body = value
580 @message.body.must_equal(value)
581
582 @message.clear
583 @message.body.must_be_nil
584 end
585
586 it "can set the body property" do
587 (1..3).each do |which|
588 case which
589 when 0
590 value = random_string(32)
591 when 1
592 value = random_array(100)
593 when 2
594 value = random_hash(100)
595 when 3
596 value = rand(512)
597 end
598
599 @message.body = value
600 @message.body.must_equal(value)
601 end
602 end
603
604 it "can update the body property" do
605 (1..3).each do |which|
606 case which
607 when 0
608 value = random_string(32)
609 when 1
610 value = random_array(100)
611 when 2
612 value = random_hash(100)
613 when 3
614 value = rand(512)
615 end
616
617 @message.body = value
618 @message.body.must_equal(value)
619
620 @message.body = nil
621 @message.body.must_be_nil
622 end
623 end
624
625 end
626
627 end
628
629 end