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