Class: TestMessage

### Home Classes Methods

### In Files

- test/test_message.rb

### Parent

Test::Unit::TestCase

### Methods

- #setup
- #teardown
- #test_0010_kcode
- #test_0020_kcode
- #test_0030_kcode
- #test_0040_msg_create
- #test_0050_mh_msg_create
- #test_0060_hdr_ekv

### Included Modules

- TestBase

### Files

- CHANGELOG.rdoc
- LICENSE

### Class/Module Index

Quicksearch

- Stomp
- Stomp::Client
- Stomp::Connection
- Stomp::Error
- Stomp::Error::BrokerException
- Stomp::Error::ConnectReadTimeout
- Stomp::Error::DuplicateSubscription
- Stomp::Error::InvalidFormat
- Stomp::Error::InvalidHeartBeatHeaderError
- Stomp::Error::InvalidMessageLength
- Stomp::Error::InvalidServerCommand
- Stomp::Error::LoggerConnectionError
- Stomp::Error::MalformedFailoverOptionsError
- Stomp::Error::MaxReconnectAttempts
- Stomp::Error::MessageIDRequiredError
- Stomp::Error::NilMessageError
- Stomp::Error::NoCurrentConnection
- Stomp::Error::PacketParsingTimeout
- Stomp::Error::ProducerFlowControlException
- Stomp::Error::ProtocolError11p
- Stomp::Error::ProtocolErrorConnect
- Stomp::Error::ProtocolErrorEmptyHeaderKey
- Stomp::Error::ProtocolErrorEmptyHeaderValue
- Stomp::Error::ProtocolException
- Stomp::Error::ReadReceiptTimeoutException
- Stomp::Error::SSLClientParamsError
- Stomp::Error::SSLNoCertFileError
- Stomp::Error::SSLNoKeyFileError
- Stomp::Error::SSLNoTruststoreFileError
- Stomp::Error::SSLUnreadableCertFileError
- Stomp::Error::SSLUnreadableKeyFileError
- Stomp::Error::SSLUnreadableTruststoreFileError
- Stomp::Error::SocketOpenTimeout
- Stomp::Error::StartTimeoutException
- Stomp::Error::StompException
- Stomp::Error::StompServerError
- Stomp::Error::SubscriptionRequiredError
- Stomp::Error::UTF8ValidationError
- Stomp::Error::UnsupportedProtocolError
- Stomp::HeaderCodec
- Stomp::Message
- Stomp::NullLogger
- Stomp::SSLParams
- Client11Example1
- Client11PutGet1
- Connection11Example1
- Connection11Example2
- ExampleConsumer
- ExamplePublisher
- ExampleRubyCiphers
- ExampleSSL1
- ExampleSSL1C
- ExampleSSL2
- ExampleSSL2C
- ExampleSSL3
- ExampleSSL3C
- ExampleSSL4
- ExampleSSL4C
- ExampleSSLCtxOptions
- ExampleSSLNewParm
- ExampleTopicConsumer
- ExampleTopicPublisher
- Hash
- HeartBeatExample1
- LoggerExample
- Object
- Publish11Example1
- Receive11Example1
- Receive11Example2
- RepeatedHeadersExample
- SSLLoggerExample
- Slogger
- Stomp11Common
- TestAnonymous
- TestBase
- TestClient
- TestConnection
- TestConnection1P
- TestMessage
- TestSSL
- TestURLLogins
- Tlogger

No matching classes.

# TestMessage

Main class for testing Stomp::Message.

### Public Instance Methods

setup() click to toggle source

    # 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

teardown() click to toggle source

    # File test/test_message.rb, line 42
    def teardown
      @conn.disconnect if @conn # allow tests to disconnect
    end

test_0010_kcode() click to toggle source

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

test_0020_kcode() click to toggle source

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

test_0030_kcode() click to toggle source

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_0040_msg_create() click to toggle source

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_0050_mh_msg_create() click to toggle source

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

test_0060_hdr_ekv() click to toggle source

Test headers with empty key / value

    # File test/test_message.rb, line 175
          def test_0060_hdr_ekv
      #
      amsg = "MESSAGE\n" +
        "h1:val1\n" +
        ":val3\n" +
        "h2:val2\n" +
        "\n" +
        "payload" +
        "\00\\n"
      assert_raise Stomp::Error::ProtocolErrorEmptyHeaderKey do
        aframe = Stomp::Message.new(amsg, false)
      end
      assert_raise Stomp::Error::ProtocolErrorEmptyHeaderKey do
        aframe = Stomp::Message.new(amsg, true)
      end
      #
      amsg = "MESSAGE\n" +
        "h1:val1\n" +
        "h2:val3\n" +
        "h3:\n" +
        "\n" +
        "payload" +
        "\00\\n"
      assert_raise Stomp::Error::ProtocolErrorEmptyHeaderValue do
        aframe = Stomp::Message.new(amsg, false)
      end
      assert_nothing_raised {
        aframe = Stomp::Message.new(amsg, true)
      }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.