qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tr...@apache.org
Subject svn commit: r1227786 - in /qpid/trunk/qpid/cpp/bindings/qpid/ruby: ./ lib/qpid/ spec/ spec/qpid/ test/
Date Thu, 05 Jan 2012 19:45:02 GMT
Author: tross
Date: Thu Jan  5 19:45:01 2012
New Revision: 1227786

URL: http://svn.apache.org/viewvc?rev=1227786&view=rev
Log:
QPID-3727 - Applied patch from Darryl Pierce


Added:
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/address_spec.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/connection_spec.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/duration_spec.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/message_spec.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/receiver_spec.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/sender_spec.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/session_spec.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb
Removed:
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/test/
Modified:
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/Rakefile
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/address.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/connection.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/duration.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/message.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb

Modified: qpid/trunk/qpid/cpp/bindings/qpid/ruby/Rakefile
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/Rakefile?rev=1227786&r1=1227785&r2=1227786&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/Rakefile (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/Rakefile Thu Jan  5 19:45:01 2012
@@ -32,6 +32,8 @@ require "rake/extensiontask"
 require "rake/rdoctask"
 require "rake/testtask"
 
+require "spec/rake/spectask"
+
 CLOBBER.include("pkg")
 
 load "./lib/qpid/version.rb"
@@ -58,6 +60,17 @@ desc "Run all tests (alias for test:all)
 task :test => :"test:all"
 
 namespace :test do
+
+  desc "Run RSpec tests."
+  Spec::Rake::SpecTask.new do |t|
+    t.ruby_opts = ['-rtest/unit']
+    t.spec_files = FileList["spec/**/*_spec.rb"]
+    t.rcov       = true
+    t.rcov_opts  = [
+                    '--exclude', 'lib\/qpid.rb,spec\/,lib\/ruby',
+                   ]
+  end
+
   desc "Run all tests (default)."
   task :all => [:units, :integrations]
 

Modified: qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/address.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/address.rb?rev=1227786&r1=1227785&r2=1227786&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/address.rb (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/address.rb Thu Jan  5 19:45:01 2012
@@ -38,75 +38,137 @@ module Qpid
     # Or they can be lists of values, where they are contained within square
     # brackets but still comma delimited, such as:
     #
-    # [value1,value2,value3]
+    #   [value1,value2,value3]
     #
     # The following are the list of supported options:
     #
-    # create:: Indicates if the address should be created; values are *always*,
-    #          *never*, *sender* or *reciever*.
+    # [:create]
+    #   Indicates if the address should be created; values are *always*,
+    #   *never*, *sender* or *reciever*.
+    #
+    # [:assert]
+    #   Indicates whether or not to assert any specified node properties;
+    #   values are *always*, *never*, *sender* or *receiver*.
+    #
+    # [:delete]
+    #   Indicates whether or not to delete the addressed node when a sender
+    #   or receiver is cancelled; values are *always*, *never*, *sender* or
+    #   *receiver*.
+    #
+    # [:node]
+    #   A nested map describing properties for the addressed node. Properties
+    #   are *type* (*topic* or *queue*), *durable* (a boolean), *x-declare*
+    #   (a nested map of amqp 0.10-specific options) and *x-bindings*. (nested
+    #   list which specifies a queue, exchange or a binding key and arguments.
+    #
+    # [:link]
+    #   A nested map through which properties of the link can be specified;
+    #   properties are *durable*, *reliability*, *x-declare*, *x-subscribe*
+    #   and *x-bindings*.
+    #
+    # [:mode]
+    #   (*For receivers only*) indicates whether the receiver should consume
+    #   or browse messages; values are *consume* (the default) and *browse*.
     #
-    # assert:: Indicates whether or not to assert any specified node properties;
-    #          values are *always*, *never*, *sender* or *receiver*.
-    #
-    # delete:: Indicates whether or not to delete the addressed node when a
-    #          sender or receiver is cancelled; values are *always*, *never*,
-    #          *sender* or *receiver*.
-    #
-    # node:: A nested map describing properties for the addressed node.
-    #        Properties are *type* (*topic* or *queue*), *durable* (a boolean),
-    #        *x-declare* (a nested map of amqp 0.10-specific options) and
-    #        *x-bindings*. (nested list which specifies a queue, exchange or
-    #        a binding key and arguments.
-    #
-    # link:: A nested map through which properties of the link can be specified;
-    #        properties are *durable*, *reliability*, *x-declare*, *x-subscribe*
-    #        and *x-bindings*.
-    #
-    # mode:: (*For receivers only*) indicates whether the receiver should consume
-    #        or browse messages; values are *consume* (the default) and *browse*.
     class Address
 
+      # Creates a new +Address+ object.
+      #
+      # ==== Options
+      #
+      # * name - The name for the +Address+.
+      # * subject - The subject for the +Address+
+      # * :create - See the class documentation.
+      # * :assert - See the class documentation.
+      # * :delete - See the class documentation.
+      # * :node   - See the class documentation.
+      # * :link   - See the class documentation.
+      # * :mode   - See the class documentation.
+      #
+      # ==== Examples
+      #
+      #   addr = Qpid::Messaging::Address.new "my-queue"
+      #   addr = Qpid::Messaging::Address.new "my-queue", "testing", :create => :always
+      #
       def initialize(name, subject, options = {}, _type = "", address_impl = nil)
         @address_impl = address_impl || Cqpid::Address.new(name, subject, convert_options(options), _type)
       end
 
-       def address_impl # :nodoc:
-         @address_impl
-       end
+      def address_impl # :nodoc:
+        @address_impl
+      end
 
-       # Returns the name.
+      # Returns the name for the +Address+.
+      #
+      # ==== Examples
+      #
+      #   puts "The address name is #{addr.name}."
+      #
       def name; @address_impl.getName; end
 
-      # Sets the name.
+      # Sets the name for the +Address+.
+      #
+      # ==== Examples
+      #
+      #   addr.name = "my-new-queue"
+      #
       def name=(name); @address_impl.setName name; end
 
-      # Returns the subject.
+      # Returns the subject for the +Address+.
+      #
+      # ==== Examples
+      #
+      #   puts "The subject is #{addr.subject}."
+      #
       def subject; @address_impl.getSubject; end
 
-      # Sets the subject.
+      # Sets the subject for the +Address+.
+      #
+      # ==== Examples
+      #
+      #   addr.subject = "testing"
+      #
       def subject=(subject); @address_impl.setSubject(subject); end
 
-      # Returns the type.
+      # Returns the type for the +Address+.
+      #
+      # ==== Examples
+      #
+      #   puts "The address is a #{address.address_type}."
+      #
       #---
       # We cannot use "type" since that clashes with the Ruby object.type
       # identifier.
-      def _type; @address_impl.getType; end
+      def address_type; @address_impl.getType; end
 
-      # Sets the type.
+      # Sets the type for the +Address+.
       #
-      # The type of the address determines how Sender and Receiver objects
+      # The type of the address determines how +Sender+ and +Receiver+ objects
       # are constructed for it. If no type is specified then it will be
       # determined by querying the broker.
-      def _type=(_type); @address_impl.setType(_type); end
+      #
+      # ===== Options
+      #
+      # * type - the address type
+      #
+      def address_type=(type); @address_impl.setType(type); end
 
       # Returns the options.
       def options; @address_impl.getOptions; end
 
       # Sets the options for the address.
-      # Any symbols are converted to strings.
-      def options=(options); @address_impl.setOptions(convert_options(options)); end
+      #
+      # *NOTE:* See the class documentation for more details on options.
+      #
+      # ==== Examples
+      #
+      #   addr.options = :create => :always
+      #
+      def options=(options = {}); @address_impl.setOptions(convert_options(options)); end
 
-      def to_s; @address_impl.str; end
+      def to_s # :nodoc:
+        @address_impl.str
+      end
 
       private
 

Modified: qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/connection.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/connection.rb?rev=1227786&r1=1227785&r2=1227786&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/connection.rb (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/connection.rb Thu Jan  5 19:45:01 2012
@@ -26,6 +26,8 @@ module Qpid
     # Establishes a connection to a remote endpoint.
     class Connection
 
+      attr_reader :options # :nodoc:
+
       # Creates a connection object, but does not actually connect to
       # the specified location.
       #
@@ -64,8 +66,8 @@ module Qpid
       #
       def initialize(opts = {})
         @url = opts[:url] || "localhost"
-        @options = opts[:options] || {}
-        @connection_impl = opts[:impl] || Cqpid::Connection.new(@url, convert_options)
+        @options = convert_options(opts[:options] || {})
+        @connection_impl = opts[:impl] || Cqpid::Connection.new(@url, @options)
       end
 
       def connection_impl # :nodoc:
@@ -132,7 +134,7 @@ module Qpid
       def session name
         begin
           session_impl = @connection_impl.getSession name
-          Qpid::Messaging::Session.new session_impl if session_impl
+          Qpid::Messaging::Session.new self, session_impl if session_impl
         rescue
           raise Qpid::Messaging::SessionNameException.new "No such session: #{name}"
         end
@@ -141,29 +143,12 @@ module Qpid
       # Returns the username used to authenticate with the connection.
       def authenticated_username; @connection_impl.getAuthenticatedUsername if open?; end
 
-      # inherited from Handle
-
-      # Returns whether the underlying handle is valid; i.e., not null.
-      def valid?
-        @connection_impl.isValid
-      end
-
-      # Returns whether the underlying handle is null.
-      def null?
-        @connection_impl.isNull
-      end
-
-      # Swaps the underlying connection handle.
-      def swap connection
-        @connection_impl.swap connection.connection_impl
-      end
-
       private
 
-      def convert_options
+      def convert_options(options)
         result = {}
-        unless @options.nil? || @options.empty?
-          @options.each_pair {|key, value| result[key.to_s] = value.to_s}
+        unless options.nil? || options.empty?
+          options.each_pair {|key, value| result[key.to_s] = value.to_s}
         end
 
         return result

Modified: qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/duration.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/duration.rb?rev=1227786&r1=1227785&r2=1227786&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/duration.rb (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/duration.rb Thu Jan  5 19:45:01 2012
@@ -33,14 +33,27 @@ module Qpid
     # :MINUTE :: 60,000ms
     class Duration
 
-      def initialize duration # :nodoc:
-        @duration_impl = Cqpid::Duration.new duration
+      # Creates a Duration with the specified length, in milliseconds.
+      def initialize length
+        @duration_impl = Cqpid::Duration.new length
       end
 
       def duration_impl # :nodoc:
         @duration_impl
       end
 
+      # Returns the period of time in milliseconds
+      #
+      # ==== Examples
+      #
+      #   duration = Qpid::Messaging::Duration.new :length => 5000
+      #   puts "Waiting #{duration.milliseconds} ms for a message."
+      #   msg = receiver.fetch duration
+      #
+      def milliseconds
+        @duration_impl.getMilliseconds
+      end
+
       def self.add_item(key, value) # :nodoc:
         @hash ||= {}
         @hash[key] = Duration.new value

Modified: qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/message.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/message.rb?rev=1227786&r1=1227785&r2=1227786&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/message.rb (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/message.rb Thu Jan  5 19:45:01 2012
@@ -23,105 +23,306 @@ module Qpid
 
   module Messaging
 
-    # Message represents a message.
+    # A +Message+ represents an routable piece of information.
+    #
+    # The content for a message is automatically encoded and decoded.
+    #
     class Message
 
-      def initialize(args = {}, message_impl = nil)
-        @message_impl = message_impl
+      # Creates a new instance of +Message+.
+      #
+      # ==== Options
+      #
+      # * :content - The content.
+      #
+      # ==== Examples
+      #
+      #   message = Qpid::Messaging::Message.new :content => "This is a message."
+      #
+      def initialize(args = {})
+        @message_impl = (args[:impl] if args[:impl]) || nil
         @message_impl = Cqpid::Message.new if @message_impl.nil?
-        @message_impl.setContent args[:content].to_s if args[:content]
         @content = nil
+        args = {} if args.nil?
+        self.content = args[:content] if args[:content]
       end
 
       def message_impl # :nodoc:
         @message_impl
       end
 
-      # Assigns the reply to address.
-      # The address must be an instance of Address.
-      def reply_to=(address); @message_impl.setReplyTo address.address_impl; end
+      # Sets the address to which replies should be sent for the +Message+.
+      #
+      # *NOTE:* The address must be an instance of Address.
+      #
+      # ==== Options
+      #
+      # * address - an instance of +Address+
+      #
+      # ==== Examples
+      #
+      #   msg.reply_to = Qpid:Messaging::Address.new "my-responses"
+      #
+      def reply_to=(address)
+        raise ArgumentError, "Agument must be an Address" unless address.is_a? Qpid::Messaging::Address
+        @message_impl.setReplyTo address.address_impl
+      end
 
-      # Returns the reply to address for the message as an instance of +Address+.
+      # Returns the reply to address for the +Message+.
+      #
       def reply_to
         address_impl = @message_impl.getReplyTo
         # only return an address if a reply to was specified
         Qpid::Messaging::Address.new(nil, nil, nil, nil, address_impl) if address_impl
       end
 
-      # Sets the subject.
+      # Sets the subject for the +Message+.
+      #
+      # ==== Options
+      #
+      # * subject - the subject
+      #
+      # ==== Examples
+      #
+      #   msg.subject = "mysubject"
+      #
       def subject=(subject); @message_impl.setSubject subject; end
 
-      # Returns the subject.
+      # Returns the subject of the +Message+.
+      #
+      # ==== Options
+      #
+      #   puts "The subject is #{msg.subject}"
+      #
       def subject; @message_impl.getSubject; end
 
-      # Sets the content type.
+      # Sets the content type for the +Message+.
+      #
+      # This should be set by the sending applicaton and indicates to
+      # recipients of the message how to interpret or decode the content.
+      #
+      # By default, only dictionaries and maps are automatically given a content
+      # type. If this content type is replaced then retrieving the content will
+      # not behave correctly.
+      #
+      # ==== Options
+      #
+      # * content_type - the content type.
+      #
       def content_type=(content_type); @message_impl.setContentType content_type; end
 
-      # Returns the content type.
+      # Returns the content type for the +Message+.
+      #
+      # ==== Examples
+      #
+      #   case msg.content_type
+      #     when "myapp/image"
+      #       ctl.handle_image msg
+      #       end
+      #     when "myapp/audio"
+      #       ctl.handle_audio msg
+      #       end
+      #   end
+      #
       def content_type; @message_impl.getContentType; end
 
       # Sets the message id.
+      #
+      # *NOTE:* this field must be a UUID type currently. A non-UUID value will
+      # be converted to a zero UUID, though a blank ID will be left untouched.
+      #
+      # ==== Options
+      #
+      # * id - the id
+      #
+      # ==== Examples
+      #
+      #
       def message_id=(message_id); @message_impl.setMessageId message_id.to_s; end
 
       # Returns the message id.
+      #
+      # See +message_id=+ for details.
       def message_id; @message_impl.getMessageId; end
 
-      # Sets the user id.
+      # Sets the user id for the +Message+.
+      #
+      # This should in general be the user-id which was used when authenticating
+      # the connection itself, as the messaging infrastructure will verify
+      # this.
+      #
+      # See +Qpid::Messaging::Connection.authenticated_username+
+      #
+      # *NOTE:* If the id is not a +String+ then the id is set using
+      # the object's string representation.
+      #
+      # ==== Options
+      #
+      # * id - the id
+      #
       def user_id=(user_id); @message_impl.setUserId user_id; end
 
-      # Returns the user id.
+      # Returns the user id for the +Message+.
+      #
+      # See +user_id=+ for details.
+      #
       def user_id; @message_impl.getUserId; end
 
-      # Sets the correlation id.
+      # Sets the correlation id of the +Message+.
+      #
+      # The correlation id can be used as part of a protocol for message
+      # exchange patterns; e.g., a requestion-response pattern might require
+      # the correlation id of the request and the response to match, or it
+      # might use the message id of the request as the correlation id on
+      # the response
+      #
+      # *NOTE:* If the id is not a +String+ then the id is setup using
+      # the object's string representation.
+      #
+      # ==== Options
+      #
+      # * id - the id
+      #
       def correlation_id=(correlation_id); @message_impl.setCorrelationId correlation_id; end
 
-      # Returns the correlation id.
+      # Returns the correlation id of the +Message+.
+      #
+      # *NOTE:* See +correlation_id=+ for details.
+      #
       def correlation_id; @message_impl.getCorrelationId; end
 
-      # Sets the priority.
+      # Sets the priority of the +Message+.
+      #
+      # This may be used by the messaging infrastructure to prioritize
+      # delivery of messages with higher priority.
+      #
+      # *NOTE:* If the priority is not an integer type then it is set using
+      # the object's integer representation. If the integer value is greater
+      # than 8-bits then only the first 8-bits are used.
+      #
+      # ==== Options
+      #
+      # * priority - the priority
+      #
       def priority=(priority); @message_impl.setPriority priority; end
 
-      # Returns the priority.
+      # Returns the priority for the +Message+.
+      #
       def priority; @message_impl.getPriority; end
 
       # Sets the time-to-live in milliseconds.
-      def ttl=(duration); @message_impl.setTtl duration; end
+      #
+      # ==== Options
+      #
+      # * duration - the number of milliseconds
+      #
+      def ttl=(duration)
+        if duration.is_a? Qpid::Messaging::Duration
+          @message_impl.setTtl duration.duration_impl
+        else
+          @message_impl.setTtl Cqpid::Duration.new duration.to_i
+        end
+      end
 
       # Returns the time-to-live in milliseconds.
-      def ttl; @message_impl.getTtl; end
+      def ttl; Qpid::Messaging::Duration.new @message_impl.getTtl.getMilliseconds; end
 
-      # Sets the durability.
+      # Sets the durability of the +Message+.
+      #
+      # This is a hint to the messaging infrastructure that the message
+      # should be persisted or otherwise stored. This helps to ensure
+      # that th emessage is not lost during to failures or a shutdown.
+      #
+      # ==== Options
+      #
+      # * durable - the durability flag (def. false)
+      #
       def durable=(durable); @message_impl.setDurable durable; end
 
-      # Returns the durability.
+      # Returns the durability for the +Message+.
+      #
       def durable; @message_impl.getDurable; end
 
-      # Allows marking the message as redelivered.
+      # This is a hint to the messaging infrastructure that if de-duplication
+      # is required, that this message should be examined to determine if it
+      # is a duplicate.
+      #
+      # ==== Options
+      #
+      # * redelivered - sets the redelivered state (def. false)
+      #
+      # ==== Examples
+      #
+      #   # processed is an array of processed message ids
+      #   msg.redelivered = true if processed.include? msg.message_id
+      #
       def redelivered=(redelivered); @message_impl.setRedelivered redelivered; end
 
-      # Returns if the message was redelivered.
+      # Returns whether the +Message+ has been marked as redelivered.
+      #
       def redelivered; @message_impl.getRedelivered; end
 
       # Returns all named properties.
-      # *NOTE:* It is recommended to use the +foo[key]+ method for
-      # retrieving properties.
+      #
+      # *NOTE:* It is recommended to use the []= method for
+      # retrieving and setting properties. Using this method may
+      # result in non-deterministic behavior.
+      #
       def properties; @message_impl.getProperties; end
 
       # Returns the value for the named property.
+      #
+      # ==== Options
+      #
+      # * name - the property name
+      #
+      # ==== Examples
+      #
+      #   # use of message properties to mark a message as digitally signed
+      #   verify(msg) if msg[:signed]
+      #
       def [](key); self.properties[key.to_s]; end
 
       # Assigns a value to the named property.
+      #
+      # *NOTE:* Both the key or the value may be a symbol, but they will
+      # both be converted to a +String+ for ease of transport.
+      #
+      # ==== Options
+      #
+      # * name - the property name
+      # * value - the property value
       def []=(key, value); @message_impl.setProperty(key.to_s, value.to_s); end
 
-      # Sets the content.
+      # Sets the content for the +Message+.
+      #
+      # Content is automatically encoded for Array and Hash types. Other types
+      # need to set their own content types (via +content_type+) in order to
+      # specify how recipients should process the content.
+      #
+      # ==== Options
+      #
+      # * content - the content
+      #
+      # ==== Examples
+      #
+      #   msg.content = "This is a simple message." # a simple message
+      #   msg.content = {:foo => :bar} # content is automatically encoded
+      #
       def content=(content)
         content_type = nil
         @content = content
         case @content
         when Hash
           content_type = "amqp/map"
+          new_content  = {}
+          content.each_pair{|key, value| new_content[key.to_s] = value.to_s}
+          @content = new_content
         when Array
+          new_content  = []
           content_type = "amqp/list"
+          content.each {|element| new_content << element.to_s}
+          @content = new_content
         end
         if content_type.nil?
           @message_impl.setContent @content
@@ -130,7 +331,16 @@ module Qpid
         end
       end
 
-      # Returns the content.
+      # Returns the content of the +Message+.
+      #
+      # Content is automatically decoded based on the specified content type.
+      # If the content type is application-specific, then no decoding is
+      # performed and the content is returnedas a +String+ representation.
+      #
+      # For example, if an array of integers are sent, then the receiver will
+      # find the message content to be an array of String objects, where each
+      # String is a representation of the sent integer value.
+      #
       def content
         if @content.nil?
           @content = @message_impl.getContent
@@ -147,6 +357,7 @@ module Qpid
       end
 
       # Returns the content's size.
+      #
       def content_size; @message_impl.getContentSize; end
 
     end

Modified: qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb?rev=1227786&r1=1227785&r2=1227786&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb Thu Jan  5 19:45:01 2012
@@ -166,7 +166,7 @@ module Qpid
       private
 
       def create_message_wrapper message_impl # :nodoc:
-        Qpid::Messaging::Message.new({}, message_impl)
+        Qpid::Messaging::Message.new(:impl => message_impl)
       end
 
     end

Added: qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/address_spec.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/address_spec.rb?rev=1227786&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/address_spec.rb (added)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/address_spec.rb Thu Jan  5 19:45:01 2012
@@ -0,0 +1,78 @@
+#
+# 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 Messaging
+
+    describe Address do
+
+      before(:each) do
+        @address = Qpid::Messaging::Address.new "my-name", "my-subject", :create => :always
+      end
+
+      it "stores the name, subject and options when created" do
+        name    = @address.name
+        subject = @address.subject
+        create  = @address.options["create"]
+
+        name.should    == "my-name"
+        subject.should == "my-subject"
+        create.should  == "always"
+      end
+
+      it "can update the name" do
+        @address.name = "new-name"
+
+        name = @address.name
+
+        name.should == "new-name"
+      end
+
+      it "can update the subject" do
+        @address.subject = "new-subject"
+
+        subject = @address.subject
+
+        subject.should == "new-subject"
+      end
+
+      it "can update the type" do
+        @address.address_type = "routed"
+
+        type = @address.address_type
+
+        type.should == "routed"
+      end
+
+      it "can update the options" do
+        @address.options[:create] = :never
+
+        create = @address.options["create"]
+
+        create.should == "always"
+      end
+
+    end
+
+  end
+
+end

Added: qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/connection_spec.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/connection_spec.rb?rev=1227786&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/connection_spec.rb (added)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/connection_spec.rb Thu Jan  5 19:45:01 2012
@@ -0,0 +1,191 @@
+#
+# 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 Messaging
+
+    describe Connection do
+
+      before(:each) do
+        @session_impl    = double('Cqpid::Session')
+        @connection_impl = double('Cqpid::Connection')
+
+        @connection = Qpid::Messaging::Connection.new :impl => @connection_impl
+      end
+
+      it "accepts options on construction" do
+        expect {
+          connection = Qpid::Messaging::Connection.new :options => {:username => "foo"}
+
+          connection.options.should include("username")
+        }.should_not raise_error
+      end
+
+      it "returns the underlying implementation" do
+        impl = @connection.connection_impl
+
+        impl.should == @connection_impl
+      end
+
+      it "opens the connection" do
+        @connection_impl.should_receive(:open)
+
+        @connection.open
+      end
+
+      it "closes the connection" do
+        @connection_impl.should_receive(:close)
+
+        @connection.close
+      end
+
+      it "retrieves a session by name" do
+        @connection_impl.should_receive(:getSession).
+          with("farkle").
+          and_return(@session_impl)
+
+        session = @connection.session "farkle"
+
+        session.session_impl.should == @session_impl
+      end
+
+      it "raises an error when a session name is invalid" do
+        @connection_impl.should_receive(:getSession).
+          with("farkle").
+          and_raise(RuntimeError)
+
+        expect {
+          @connection.session "farkle"
+        }.to raise_error(SessionNameException)
+      end
+
+      ####################################################################
+      # test conditions for when a connection is not connected to a broker
+      ####################################################################
+      describe "when closed" do
+
+        before(:each) do
+          @connection_impl.should_receive(:isOpen).
+            and_return(false)
+        end
+
+        it "returns false when not connected to a broker" do
+          open = @connection.open?
+
+          open.should == false
+        end
+
+        it "should raise an error when creating a session on a closed connection" do
+          expect {
+            @connection.create_session
+          }.to raise_error(RuntimeError)
+        end
+
+        it "raises an error when creating a transactional session on a closed connection" do
+          expect {
+            @connection.create_session :transactional => true
+          }.to raise_error(RuntimeError)
+        end
+
+        it "raises an error when creating a named session on a closed connection" do
+          expect {
+            @connection.create_session :name => "test", :transactional => true
+          }.to raise_error(RuntimeError)
+        end
+
+        it "returns a null username when not connected" do
+          username = @connection.authenticated_username
+
+          username.should be_nil
+        end
+
+      end
+
+      #########################################################
+      # test conditions for when a connection must be connected
+      #########################################################
+      describe "when connected" do
+
+        before(:each) do
+          @connection_impl.should_receive(:isOpen).
+            and_return(true)
+        end
+
+        it "returns true when connected to a broker" do
+          open = @connection.open?
+
+          open.should == true
+        end
+
+        it "creates a session" do
+          @connection_impl.should_receive(:createSession).
+            and_return(@session_impl)
+
+          session = @connection.create_session
+
+          session.session_impl.should == @session_impl
+        end
+
+        it "creates a named session with a name when provided" do
+          @connection_impl.should_receive(:createSession).with("farkle").
+            and_return(@session_impl)
+
+          session = @connection.create_session :name => "farkle"
+
+          session.session_impl.should == @session_impl
+        end
+
+        it "creates a transactional session when specified" do
+          @connection_impl.should_receive(:createTransactionalSession).
+            and_return(@session_impl)
+
+          session = @connection.create_session :transactional => true
+
+          session.session_impl.should == @session_impl
+        end
+
+        it "creates a named transactional session when specified" do
+          @connection_impl.should_receive(:createTransactionalSession).
+            with("farkle").
+            and_return(@session_impl)
+
+          session = @connection.create_session :transactional => true, :name => "farkle"
+
+          session.session_impl.should == @session_impl
+        end
+
+        it "returns the authenticated username when connected" do
+          @connection_impl.should_receive(:getAuthenticatedUsername).
+            and_return("mcpierce")
+
+          username = @connection.authenticated_username
+
+          username.should == "mcpierce"
+        end
+
+      end
+
+    end
+
+  end
+
+end

Added: qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/duration_spec.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/duration_spec.rb?rev=1227786&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/duration_spec.rb (added)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/duration_spec.rb Thu Jan  5 19:45:01 2012
@@ -0,0 +1,56 @@
+#
+# 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 Messaging
+
+    describe Duration do
+
+      before(:each) do
+        @duration = Qpid::Messaging::Duration::SECOND
+      end
+
+      it "returns the underlying implementation" do
+        impl = @duration.duration_impl
+
+        impl.should_not be_nil
+      end
+
+      it "can create a duration with a millisecond value" do
+        duration = Qpid::Messaging::Duration.new 500
+
+        milliseconds = duration.milliseconds
+
+        milliseconds.should == 500
+      end
+
+      it "returns the time in milliseconds" do
+        milliseconds = @duration.milliseconds
+
+        milliseconds.should == 1000
+      end
+
+    end
+
+  end
+
+end

Added: qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/message_spec.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/message_spec.rb?rev=1227786&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/message_spec.rb (added)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/message_spec.rb Thu Jan  5 19:45:01 2012
@@ -0,0 +1,292 @@
+#
+# 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 Messaging
+
+    describe Message do
+
+      before(:each) do
+        @message = Qpid::Messaging::Message.new :content => "My content"
+      end
+
+      it "returns its implementation" do
+        impl = @message.message_impl
+
+        impl.class.should == Cqpid::Message
+      end
+
+      it "can set the reply to address" do
+        address = Qpid::Messaging::Address.new "my-queue", ""
+
+        @message.reply_to = address
+
+        reply_to = @message.reply_to
+
+        reply_to.name.should == address.name
+      end
+
+      it "should store the content when created" do
+        content = @message.content
+
+        content.should == "My content"
+      end
+
+      it "should properly encode a map when created" do
+        message = Qpid::Messaging::Message.new :content => {"foo" => "bar"}
+
+        content      = message.content
+        content_type = message.content_type
+
+        content_type.should == "amqp/map"
+        content.class == Hash
+        content["foo"].should == "bar"
+      end
+
+      it "should properly encode a list when created" do
+        message = Qpid::Messaging::Message.new :content => ["foo", "bar"]
+
+        content      = message.content
+        content_type = message.content_type
+
+        content_type.should == "amqp/list"
+        content.class == Array
+        content.should include("foo")
+        content.should include("bar")
+      end
+
+      it "should store the subject" do
+        @message.subject = "new-subject"
+
+        subject = @message.subject
+
+        subject.should == "new-subject"
+      end
+
+      it "should update the content type" do
+        @message.content_type = "amqp/audio"
+
+        content_type = @message.content_type
+
+        content_type.should == "amqp/audio"
+      end
+
+      it "should store the message id" do
+        @message.message_id = "foo"
+
+        id = @message.message_id
+
+        id.should == "foo"
+      end
+
+      it "should store the user id" do
+        @message.user_id = "foo"
+
+        id = @message.user_id
+
+        id.should == "foo"
+      end
+
+      it "should store the correlation id" do
+        @message.correlation_id = "message1"
+
+        id = @message.correlation_id
+
+        id.should == "message1"
+      end
+
+      it "should store the priority" do
+        @message.priority = 7
+
+        priority = @message.priority
+
+        priority.should == 7
+      end
+
+      it "should accept a Duration as the time to live" do
+        @message.ttl = Qpid::Messaging::Duration::SECOND
+
+        ttl = @message.ttl
+
+        ttl.milliseconds.should == Qpid::Messaging::Duration::SECOND.milliseconds
+      end
+
+      it "should accept an integer value as the time to live" do
+        @message.ttl = 15000
+
+        ttl = @message.ttl
+
+        ttl.milliseconds.should == 15000
+      end
+
+      it "should update the durable flag" do
+        @message.durable = true
+
+        durable = @message.durable
+
+        durable.should == true
+      end
+
+      it "should update the redelivered flag" do
+        @message.redelivered = true
+
+        redelivered = @message.redelivered
+
+        redelivered.should == true
+      end
+
+      it "should store a property" do
+        property = @message[:test_property]
+
+        property.should == nil
+
+        @message[:test_property] = "test_value1"
+
+        property = @message[:test_property]
+
+        property.should == "test_value1"
+      end
+
+      it "should convert a symbol property value to a string" do
+        @message[:test_property] = :test_value2
+
+        property = @message[:test_property]
+
+        property.should == "test_value2"
+      end
+
+      it "should convert a symbol property name to a string" do
+        @message[:test_property] = "test_value3"
+
+        property = @message["test_property"]
+
+        property.should == "test_value3"
+      end
+
+      it "should store text content" do
+        @message.content = "This is the content."
+
+        content = @message.content
+
+        content.should == "This is the content."
+      end
+
+      it "should store list content" do
+        list = ["foo", "bar"]
+
+        @message.content = list
+
+        content      = @message.content
+        content_type = @message.content_type
+
+        content.should      == list
+        content_type.should == "amqp/list"
+      end
+
+      it "should convert symbol list elements to strings" do
+        @message.content = [:farkle]
+
+        content = @message.content.first
+
+        content.should == "farkle"
+      end
+
+      it "should store map content" do
+        map = {"foo" => "bar"}
+
+        @message.content = map
+
+        content      = @message.content
+        content_type = @message.content_type
+
+        content.should      == map
+        content_type.should == "amqp/map"
+      end
+
+      it "should convert symbol map elements to strings" do
+        @message.content = {:first_name => :qpid}
+
+        content = @message.content["first_name"]
+
+        content.should == "qpid"
+      end
+
+      describe "with content from the underlying implementation" do
+
+        before(:each) do
+          @message_impl = double("Cqpid::Message")
+          @message = Qpid::Messaging::Message.new :impl => @message_impl
+        end
+
+        it "should return simple text content" do
+          @message_impl.should_receive(:getContent).
+            and_return("my content")
+          @message_impl.should_receive(:getContentType).
+            and_return("")
+
+          content = @message.content
+
+          content.should == "my content"
+        end
+
+        it "should decode a list" do
+          list = ["first", "second"]
+
+          @message_impl.should_receive(:getContent).
+            and_return(list)
+          @message_impl.should_receive(:getContentType).
+            twice.
+            and_return("amqp/list")
+          Qpid::Messaging.stub!(:decode).
+            with(@message, "amqp/list").
+            and_return(list)
+
+          content = @message.content
+
+          content.should == list
+        end
+
+        it "should decode a map" do
+          map = {"first" => "second"}
+
+          @message_impl.should_receive(:getContent).
+            and_return(map)
+          @message_impl.should_receive(:getContentType).
+            twice.
+            and_return("amqp/map")
+          Qpid::Messaging.stub!(:decode).
+            with(@message, "amqp/map").
+            and_return(map)
+
+          content = @message.content
+
+          content.should == map
+        end
+
+
+      end
+
+    end
+
+  end
+
+end

Added: qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/receiver_spec.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/receiver_spec.rb?rev=1227786&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/receiver_spec.rb (added)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/receiver_spec.rb Thu Jan  5 19:45:01 2012
@@ -0,0 +1,170 @@
+#
+# 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 Messaging
+
+    describe Receiver do
+
+      before(:each) do
+        @message_impl  = double("Cqpid::Message")
+        @session       = double("Qpid::Messaging::Session")
+        @receiver_impl = double("Cqpid::Receiver")
+
+        @receiver = Qpid::Messaging::Receiver.new @session, @receiver_impl
+      end
+
+      it "returns the underlying implementation" do
+        impl = @receiver.receiver_impl
+
+        impl.should == @receiver_impl
+      end
+
+      it "gets a message with the default duration" do
+        @receiver_impl.should_receive(:get).
+          with(Qpid::Messaging::Duration::FOREVER.duration_impl).
+          and_return(@message_impl)
+
+        message = @receiver.get
+
+        message.message_impl.should == @message_impl
+      end
+
+      it "gets a message with a specified duration" do
+        @receiver_impl.should_receive(:get).
+          with(Qpid::Messaging::Duration::SECOND.duration_impl).
+          and_return(@message_impl)
+
+        message = @receiver.get Qpid::Messaging::Duration::SECOND
+
+        message.message_impl.should == @message_impl
+      end
+
+      it "returns nil when get receives no message" do
+        @receiver_impl.should_receive(:get).
+          with(Qpid::Messaging::Duration::MINUTE.duration_impl).
+          and_return(nil)
+
+        message = @receiver.get Qpid::Messaging::Duration::MINUTE
+
+        message.should be_nil
+      end
+
+      it "fetches a message with the default duration" do
+        @receiver_impl.should_receive(:fetch).
+          with(Qpid::Messaging::Duration::FOREVER.duration_impl).
+          and_return(@message_impl)
+
+        message = @receiver.fetch
+
+        message.message_impl.should == @message_impl
+      end
+
+      it "fetches a message with a specified duration" do
+        @receiver_impl.should_receive(:fetch).
+          with(Qpid::Messaging::Duration::SECOND.duration_impl).
+          and_return(@message_impl)
+
+        message = @receiver.fetch Qpid::Messaging::Duration::SECOND
+
+        message.message_impl.should == @message_impl
+      end
+
+      it "returns nil when fetch recieves no message" do
+        @receiver_impl.should_receive(:fetch).
+          with(Qpid::Messaging::Duration::MINUTE.duration_impl).
+          and_return(nil)
+
+        message = @receiver.fetch Qpid::Messaging::Duration::MINUTE
+
+        message.should be_nil
+      end
+
+      it "assigns capacity" do
+        @receiver_impl.should_receive(:setCapacity).
+          with(10)
+
+        @receiver.capacity = 10
+      end
+
+      it "returns the capacity" do
+        @receiver_impl.should_receive(:getCapacity).
+          and_return(10)
+
+        capacity = @receiver.capacity
+
+        capacity.should == 10
+      end
+
+      it "reports the number of available messages" do
+        @receiver_impl.should_receive(:getAvailable).
+          and_return(20)
+
+        available = @receiver.available
+
+        available.should == 20
+      end
+
+      it "reports the number of unsettled messages" do
+        @receiver_impl.should_receive(:getUnsettled).
+          and_return(25)
+
+        unsettled = @receiver.unsettled
+
+        unsettled.should == 25
+      end
+
+      it "closes" do
+        @receiver_impl.should_receive(:close)
+
+        @receiver.close
+      end
+
+      it "reports its closed status" do
+        @receiver_impl.should_receive(:isClosed).
+          and_return(true)
+
+        closed = @receiver.closed?
+
+        closed.should == true
+      end
+
+      it "returns its name" do
+        @receiver_impl.should_receive(:getName).
+          and_return("farkle")
+
+        name = @receiver.name
+
+        name.should == "farkle"
+      end
+
+      it "returns its related session" do
+        session = @receiver.session
+
+        session.should == @session
+      end
+
+    end
+
+  end
+
+end

Added: qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/sender_spec.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/sender_spec.rb?rev=1227786&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/sender_spec.rb (added)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/sender_spec.rb Thu Jan  5 19:45:01 2012
@@ -0,0 +1,135 @@
+#
+# 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 Messaging
+
+    describe Sender do
+
+      before(:each) do
+        @message      = double("Qpid::Messaging::Message")
+        @message_impl = double("Cqpid::Message")
+        @sender_impl  = double("Cqpid::Sender")
+        @session      = double("Qpid::Messaging::Session")
+
+        @sender = Qpid::Messaging::Sender.new @session, @sender_impl
+      end
+
+      it "returns its implementation" do
+        impl = @sender.sender_impl
+
+        impl.should == @sender_impl
+      end
+
+      it "sends a message" do
+        @message.should_receive(:message_impl).
+          and_return(@message_impl)
+        @sender_impl.should_receive(:send).
+          with(@message_impl, false)
+
+        @sender.send @message
+      end
+
+      it "sends a message with optional synch" do
+        @message.should_receive(:message_impl).
+          and_return(@message_impl)
+        @sender_impl.should_receive(:send).
+          with(@message_impl, true)
+
+        @sender.send @message, :sync => true
+      end
+
+      it "sends a message with an optional block" do
+        block_called = false
+
+        @message.should_receive(:message_impl).
+          and_return(@message_impl)
+        @sender_impl.should_receive(:send).
+          with(@message_impl, false)
+
+        @sender.send @message do |message|
+          block_called = true if message == @message
+        end
+
+        block_called.should be_true
+      end
+
+      it "closes" do
+        @sender_impl.should_receive(:close)
+
+        @sender.close
+      end
+
+      it "returns its name" do
+        @sender_impl.should_receive(:getName).
+          and_return("farkle")
+
+        name = @sender.name
+
+        name.should == "farkle"
+      end
+
+      it "sets its capacity" do
+        @sender_impl.should_receive(:setCapacity).
+          with(100)
+
+        @sender.capacity = 100
+      end
+
+      it "returns its capacity" do
+        @sender_impl.should_receive(:getCapacity).
+          and_return(25)
+
+        capacity = @sender.capacity
+
+        capacity.should == 25
+      end
+
+      it "returns the number of unsettled messages" do
+        @sender_impl.should_receive(:getUnsettled).
+          and_return(15)
+
+        unsettled = @sender.unsettled
+
+        unsettled.should == 15
+      end
+
+      it "returns the number of available message slots" do
+        @sender_impl.should_receive(:getAvailable).
+          and_return(50)
+
+        available = @sender.available
+
+        available.should == 50
+      end
+
+      it "returns a reference to its session" do
+        session = @sender.session
+
+        session.should == @session
+      end
+
+    end
+
+  end
+
+end

Added: qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/session_spec.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/session_spec.rb?rev=1227786&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/session_spec.rb (added)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid/session_spec.rb Thu Jan  5 19:45:01 2012
@@ -0,0 +1,353 @@
+#
+# 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 Messaging
+
+    describe Session do
+
+      before(:each) do
+        @connection    = double("Qpid::Messaging::Connection")
+        @session_impl  = double("Cqpid::Session")
+        @session       = Qpid::Messaging::Session.new @connection, @session_impl
+        @sender_impl   = double("Cqpid::Sender")
+        @receiver_impl = double("Cqpid::Receiver")
+      end
+
+      it "returns its implementation" do
+        impl = @session.session_impl
+
+        impl.should == @session_impl
+      end
+
+      it "returns its connection" do
+        connection = @session.connection
+
+        connection.should == @connection
+      end
+
+      it "creates a Sender from an Address" do
+        address = Qpid::Messaging::Address.new "my-queu", "", :create => :always
+
+        @session_impl.should_receive(:createSender).
+          with(address.address_impl).
+          and_return(@sender_impl)
+        @sender_impl.should_receive(:getName).
+          and_return("my-queue")
+
+        sender = @session.create_sender address
+
+        sender.sender_impl.should == @sender_impl
+      end
+
+      it "creates a Sender from an address string" do
+        address = "my-queue;{create:true}"
+
+        @session_impl.should_receive(:createSender).
+          with(address).
+          and_return(@sender_impl)
+        @sender_impl.should_receive(:getName).
+          and_return("my-queue")
+
+        sender = @session.create_sender address
+
+        sender.sender_impl.should == @sender_impl
+      end
+
+      #######################################
+      # scenarios involing an existing Sender
+      #######################################
+      describe "when retrieving a Sender by name" do
+
+        before(:each) do
+          address = "my-queue;{create:always}"
+          @name   = "my-queue"
+
+          @session_impl.should_receive(:createSender).
+            with(address).
+            and_return(@sender_impl)
+          @sender_impl.should_receive(:getName).
+            and_return(@name)
+
+          @sender = @session.create_sender address
+        end
+
+        it "works when the name is valid" do
+          sender = @session.sender @name
+
+          sender.should == @sender
+        end
+
+        it "raises an error when the name is invalid" do
+          expect {
+            @session.sender @name.reverse
+          }.to raise_error(Qpid::Messaging::KeyError)
+        end
+
+     end
+
+      it "creates a Receiver from an Address" do
+        address = Qpid::Messaging::Address.new "my-queue", ""
+
+        @session_impl.should_receive(:createReceiver).
+          with(address.address_impl).
+          and_return(@receiver_impl)
+        @receiver_impl.should_receive(:getName).
+          and_return("my-queue")
+
+        receiver = @session.create_receiver address
+
+        receiver.receiver_impl.should == @receiver_impl
+      end
+
+      it "creates a Receiver from an address string" do
+        address = "my-queue"
+
+        @session_impl.should_receive(:createReceiver).
+          with(address).
+          and_return(@receiver_impl)
+        @receiver_impl.should_receive(:getName).
+          and_return("my-queue")
+
+        receiver = @session.create_receiver address
+
+        receiver.receiver_impl.should == @receiver_impl
+      end
+
+      #########################################
+      # scenarios involving an existing Receiver
+      ##########################################
+      describe "when retrieving a Receiver by name" do
+
+        before(:each) do
+          address = "my-queue"
+          @name   = "my-queue"
+
+          @session_impl.should_receive(:createReceiver).
+            with(address).
+            and_return(@receiver_impl)
+          @receiver_impl.should_receive(:getName).
+            and_return(@name)
+
+          @receiver = @session.create_receiver address
+        end
+
+        it "works with a valid name" do
+          receiver = @session.receiver @name
+
+          receiver.should == @receiver
+        end
+
+        it "raises an error when the name is invalid" do
+          expect {
+            @session.receiver @name.reverse
+          }.to raise_error(Qpid::Messaging::KeyError)
+        end
+
+      end
+
+      it "closes the session" do
+        @session_impl.should_receive(:close)
+
+        @session.close
+      end
+
+      it "commits a pending transaction" do
+        @session_impl.should_receive(:commit)
+
+        @session.commit
+      end
+
+      it "rolls back an uncommitted transaction" do
+        @session_impl.should_receive(:rollback)
+
+        @session.rollback
+      end
+
+      it "acknowledges all received messages" do
+        @session_impl.should_receive(:acknowledge).
+          with(false)
+
+        @session.acknowledge
+      end
+
+      it "acknowledges all messages synchronously" do
+        @session_impl.should_receive(:acknowledge).
+          with(true)
+
+        @session.acknowledge :sync => true
+      end
+
+      it "acknowledges all messages asynchronously" do
+        @session_impl.should_receive(:acknowledge).
+          with(false)
+
+        @session.acknowledge :sync => false
+      end
+
+      ######################################
+      # Scenarios involving a single message
+      ######################################
+      describe "with a single message" do
+
+        before(:each) do
+          @message = Qpid::Messaging::Message.new :content => "Testing"
+        end
+
+        it "can acknowledge asynchronously by default" do
+          @session_impl.should_receive(:acknowledge).
+            with(@message.message_impl, false)
+
+          @session.acknowledge :message => @message
+        end
+
+        it "can acknowledge synchronously" do
+          @session_impl.should_receive(:acknowledge).
+            with(@message.message_impl, true)
+
+          @session.acknowledge :message => @message, :sync => true
+        end
+
+        it "can acknowledge asynchronously" do
+          @session_impl.should_receive(:acknowledge).
+            with(@message.message_impl, false)
+
+          @session.acknowledge :message => @message, :sync => false
+        end
+
+        it "can reject it" do
+          @session_impl.should_receive(:reject).
+            with(@message.message_impl)
+
+          @session.reject @message
+        end
+
+        it "can release it" do
+          @session_impl.should_receive(:release).
+            with(@message.message_impl)
+
+          @session.release @message
+        end
+
+      end
+
+      it "does not block by default when synchronizating with the broker" do
+        @session_impl.should_receive(:sync).
+          with(false)
+
+        @session.sync
+      end
+
+      it "can block while synchronizing with the broker" do
+        @session_impl.should_receive(:sync).
+          with(true)
+
+        @session.sync :block => true
+      end
+
+      it "can not block while synchronizing with the broker" do
+        @session_impl.should_receive(:sync).
+          with(false)
+
+        @session.sync :block => false
+      end
+
+      it "returns the number of messages that are receivable" do
+        @session_impl.should_receive(:getReceivable).
+          and_return(15)
+
+        receivable = @session.receivable
+
+        receivable.should == 15
+      end
+
+      it "returns the number of unsettled messages" do
+        @session_impl.should_receive(:getUnsettledAcks).
+          and_return(25)
+
+        unsettled = @session.unsettled_acks
+
+        unsettled.should == 25
+      end
+
+      it "waits forever by default for the next Receiver with messages" do
+        @session_impl.should_receive(:nextReceiver).
+          with(Qpid::Messaging::Duration::FOREVER.duration_impl).
+          and_return(@receiver_impl)
+
+        receiver = @session.next_receiver
+
+        receiver.receiver_impl.should == @receiver_impl
+      end
+
+      it "uses the specified time when waiting for the next Receiver with messages" do
+        @session_impl.should_receive(:nextReceiver).
+          with(Qpid::Messaging::Duration::SECOND.duration_impl).
+          and_return(@receiver_impl)
+
+        receiver = @session.next_receiver Qpid::Messaging::Duration::SECOND
+
+        receiver.receiver_impl.should == @receiver_impl
+      end
+
+      it "returns nil when no Receiver has messages within the timeout period" do
+        @session_impl.should_receive(:nextReceiver).
+          with(Qpid::Messaging::Duration::MINUTE.duration_impl).
+          and_return(nil)
+
+        receiver = @session.next_receiver Qpid::Messaging::Duration::MINUTE
+
+        receiver.should be_nil
+      end
+
+      it "returns true when there are errors on the session" do
+        @session_impl.should_receive(:hasError).
+          and_return(true)
+
+        errors = @session.errors?
+
+        errors.should be_true
+      end
+
+      it "returns false when there are no errors on the session" do
+        @session_impl.should_receive(:hasError).
+          and_return(false)
+
+        errors = @session.errors?
+
+        errors.should be_false
+      end
+
+      it "causes exceptions to be raised when there are errors" do
+        @session_impl.should_receive(:checkError).
+          and_raise(RuntimeError)
+
+        expect {
+          @session.errors
+        }.to raise_error(RuntimeError)
+      end
+
+    end
+
+  end
+
+end

Added: qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb?rev=1227786&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb (added)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb Thu Jan  5 19:45:01 2012
@@ -0,0 +1,21 @@
+#
+# 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 'qpid'
+require 'cqpid'



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message