Test::Unit::TestCase
Main class for testing Stomp::Message.
# File test/test_message.rb, line 30 def setup $KCODE = 'U' if RUBY_VERSION =~ /1\.8/ @conn = get_connection() # Message body data @messages = [ "normal text message", "bad byte: \3372", "\0004\b{\f:\tbody\"\0001\2207\0004\b{\b:\0016statusmsg\"\aOK:\0017statuscodei\0000:\tdata{\t:\voutput\"3Enabled, not running, last run 693 seconds ago:\frunningi\0000:\fenabledi\0006:\flastrunl+\aE\0021\0022M:\rsenderid\"\0032xx.xx.xx.xx:\0016requestid\"%849d647bbe3e421ea19ac9f947bbdde4:\0020senderagent\"\fpuppetd:\0016msgtarget\"%/topic/mcollective.puppetd.reply:\thash\"\0001\2257ZdQqtaDmmdD0jZinnEcpN+YbkxQDn8uuCnwsQdvGHau6d+gxnnfPLUddWRSb\nZNMs+sQUXgJNfcV1eVBn1H+Z8QQmzYXVDMqz7J43jmgloz5PsLVbN9K3PmX/\ngszqV/WpvIyAqm98ennWqSzpwMuiCC4q2Jr3s3Gm6bUJ6UkKXnY=\n:\fmsgtimel+\a\3372\0023\0022M" ] # end
# File test/test_message.rb, line 42 def teardown @conn.disconnect if @conn # allow tests to disconnect end
Various message bodies, including the failing test case reported
# File test/test_message.rb, line 47 def test_0010_kcode # dest = make_destination if @conn.protocol == Stomp::SPL_10 @conn.subscribe dest else sh = {} @conn.subscribe dest, sh, @conn.uuid() end @messages.each do |abody| @conn.publish dest, abody msg = @conn.receive assert_instance_of Stomp::Message , msg, "type check for #{abody}" assert_equal abody, msg.body, "equal check for #{abody}" end end
All possible byte values
# File test/test_message.rb, line 65 def test_0020_kcode # abody = "" "\0000".upto("\3377") {|abyte| abody << abyte } # dest = make_destination if @conn.protocol == Stomp::SPL_10 @conn.subscribe dest else sh = {} @conn.subscribe dest, sh, @conn.uuid() end @conn.publish dest, abody msg = @conn.receive assert_instance_of Stomp::Message , msg, "type check for #{abody}" assert_equal abody, msg.body, "equal check for #{abody}" end
A single byte at a time
# File test/test_message.rb, line 84 def test_0030_kcode # dest = make_destination if @conn.protocol == Stomp::SPL_10 @conn.subscribe dest else sh = {:id => @conn.uuid()} @conn.subscribe dest, sh end # "\0000".upto("\3377") do |abody| @conn.publish dest, abody msg = @conn.receive assert_instance_of Stomp::Message , msg, "type check for #{abody}" assert_equal abody, msg.body, "equal check for #{abody}" end end
Test various valid and invalid frames.
# File test/test_message.rb, line 103 def test_0040_msg_create # assert_raise(Stomp::Error::InvalidFormat) { aframe = Stomp::Message.new("junk", false) } # assert_raise(Stomp::Error::InvalidFormat) { aframe = Stomp::Message.new("command\njunk", false) } # assert_raise(Stomp::Error::InvalidFormat) { aframe = Stomp::Message.new("command\nheaders\n\njunk", false) } # assert_raise(Stomp::Error::InvalidServerCommand) { aframe = Stomp::Message.new("junkcommand\nheaders\n\njunk\00\\n\n", false) } # assert_raise(Stomp::Error::InvalidFormat) { aframe = Stomp::Message.new("ERROR\nbadheaders\n\njunk\00\\n\n", false) } # assert_nothing_raised { aframe = Stomp::Message.new("CONNECTED\nh1:val1\n\njunk\00\\n", false) } # assert_nothing_raised { aframe = Stomp::Message.new("MESSAGE\nh1:val1\n\njunk\00\\n", false) } # assert_nothing_raised { aframe = Stomp::Message.new("MESSAGE\nh2:val2\n\n\00"", false) } # assert_nothing_raised { aframe = Stomp::Message.new("RECEIPT\nh1:val1\n\njunk\00\\n", false) } # assert_nothing_raised { aframe = Stomp::Message.new("ERROR\nh1:val1\n\njunk\00\\n", false) } end
Test multiple headers with the same key
# File test/test_message.rb, line 148 def test_0050_mh_msg_create aframe = bframe = nil assert_nothing_raised { amsg = "MESSAGE\n" + "h1:val1\n" + "h2:val3\n" + "h2:val2\n" + "h2:val1\n" + "h3:val1\n" + "\n" + "payload" + "\00\\n" aframe = Stomp::Message.new(amsg, false) bframe = Stomp::Message.new(amsg, true) } # assert aframe.headers["h2"].is_a?(String), "Expected a String" assert_equal "val3", aframe.headers["h2"], "Expected 1st value" # assert bframe.headers["h2"].is_a?(Array), "Expected an Array" assert_equal 3, bframe.headers["h2"].length, "Expected 3 values" assert_equal "val3", bframe.headers["h2"][0], "Expected val3" assert_equal "val2", bframe.headers["h2"][1], "Expected val2" assert_equal "val1", bframe.headers["h2"][2], "Expected val1" end
Generated with the Darkfish Rdoc Generator 2.