diff options
Diffstat (limited to 'cpp')
21 files changed, 1621 insertions, 1685 deletions
diff --git a/cpp/bindings/qpid/ruby/Rakefile b/cpp/bindings/qpid/ruby/Rakefile index 07cfff9844..e742324932 100644 --- a/cpp/bindings/qpid/ruby/Rakefile +++ b/cpp/bindings/qpid/ruby/Rakefile @@ -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] diff --git a/cpp/bindings/qpid/ruby/lib/qpid/address.rb b/cpp/bindings/qpid/ruby/lib/qpid/address.rb index 73b61bb1c7..266d8668d6 100644 --- a/cpp/bindings/qpid/ruby/lib/qpid/address.rb +++ b/cpp/bindings/qpid/ruby/lib/qpid/address.rb @@ -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*. + # [: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*. + # [: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. + # [: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*. + # [: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*. # - # 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 diff --git a/cpp/bindings/qpid/ruby/lib/qpid/connection.rb b/cpp/bindings/qpid/ruby/lib/qpid/connection.rb index 37086c95ba..12669bc947 100644 --- a/cpp/bindings/qpid/ruby/lib/qpid/connection.rb +++ b/cpp/bindings/qpid/ruby/lib/qpid/connection.rb @@ -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 diff --git a/cpp/bindings/qpid/ruby/lib/qpid/duration.rb b/cpp/bindings/qpid/ruby/lib/qpid/duration.rb index c1f44e9281..1544075d70 100644 --- a/cpp/bindings/qpid/ruby/lib/qpid/duration.rb +++ b/cpp/bindings/qpid/ruby/lib/qpid/duration.rb @@ -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 diff --git a/cpp/bindings/qpid/ruby/lib/qpid/message.rb b/cpp/bindings/qpid/ruby/lib/qpid/message.rb index 9b1b68c7c3..edef0ac2a0 100644 --- a/cpp/bindings/qpid/ruby/lib/qpid/message.rb +++ b/cpp/bindings/qpid/ruby/lib/qpid/message.rb @@ -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 - - # Sets the durability. + def ttl; Qpid::Messaging::Duration.new @message_impl.getTtl.getMilliseconds; end + + # 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 diff --git a/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb b/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb index 886364d397..100ee4ea76 100644 --- a/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb +++ b/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb @@ -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 diff --git a/cpp/bindings/qpid/ruby/spec/qpid/address_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid/address_spec.rb new file mode 100644 index 0000000000..e4672e4e47 --- /dev/null +++ b/cpp/bindings/qpid/ruby/spec/qpid/address_spec.rb @@ -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 diff --git a/cpp/bindings/qpid/ruby/spec/qpid/connection_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid/connection_spec.rb new file mode 100644 index 0000000000..a2f5b7e898 --- /dev/null +++ b/cpp/bindings/qpid/ruby/spec/qpid/connection_spec.rb @@ -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 diff --git a/cpp/bindings/qpid/ruby/test/test_address.rb b/cpp/bindings/qpid/ruby/spec/qpid/duration_spec.rb index f54e93aa3d..4980b6ffe7 100644 --- a/cpp/bindings/qpid/ruby/test/test_address.rb +++ b/cpp/bindings/qpid/ruby/spec/qpid/duration_spec.rb @@ -17,23 +17,40 @@ # under the License. # -$:.unshift File.join(File.dirname(__FILE__), "..", "lib") +require 'spec_helper' -require 'test/unit' -require 'flexmock/test_unit' +module Qpid -require 'cqpid' -require 'qpid/address' + module Messaging -class TestAddress < Test::Unit::TestCase + describe Duration do - def test_constructor - result = Qpid::Messaging::Address.new "name", "subject", {:foo => :bar}, "type" + 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 - assert_equal "name", result.name - assert_equal "subject", result.subject - assert_equal "type", result._type end end - diff --git a/cpp/bindings/qpid/ruby/spec/qpid/message_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid/message_spec.rb new file mode 100644 index 0000000000..e34e58f563 --- /dev/null +++ b/cpp/bindings/qpid/ruby/spec/qpid/message_spec.rb @@ -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 diff --git a/cpp/bindings/qpid/ruby/spec/qpid/receiver_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid/receiver_spec.rb new file mode 100644 index 0000000000..81ae935dcb --- /dev/null +++ b/cpp/bindings/qpid/ruby/spec/qpid/receiver_spec.rb @@ -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 diff --git a/cpp/bindings/qpid/ruby/spec/qpid/sender_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid/sender_spec.rb new file mode 100644 index 0000000000..fa3a2a5b1f --- /dev/null +++ b/cpp/bindings/qpid/ruby/spec/qpid/sender_spec.rb @@ -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 diff --git a/cpp/bindings/qpid/ruby/spec/qpid/session_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid/session_spec.rb new file mode 100644 index 0000000000..0b103a31e6 --- /dev/null +++ b/cpp/bindings/qpid/ruby/spec/qpid/session_spec.rb @@ -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 diff --git a/cpp/bindings/qpid/ruby/test/lib/setup.rb b/cpp/bindings/qpid/ruby/spec/spec_helper.rb index c4901ed907..90084963f4 100644 --- a/cpp/bindings/qpid/ruby/test/lib/setup.rb +++ b/cpp/bindings/qpid/ruby/spec/spec_helper.rb @@ -17,13 +17,5 @@ # under the License. # -$:.unshift File.join(File.dirname(__FILE__), "..", "lib") - require 'qpid' - -def create_session url, session_name - conn = Qpid::Messaging::Connection.new url - conn.open - conn.create_session session_name -end - +require 'cqpid' diff --git a/cpp/bindings/qpid/ruby/test/test_connection.rb b/cpp/bindings/qpid/ruby/test/test_connection.rb deleted file mode 100644 index 936d8389d8..0000000000 --- a/cpp/bindings/qpid/ruby/test/test_connection.rb +++ /dev/null @@ -1,262 +0,0 @@ -# -# 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. -# - -$:.unshift File.join(File.dirname(__FILE__), "..", "lib") - -require 'test/unit' -require 'flexmock/test_unit' - -require 'cqpid' -require 'qpid/connection' - -class TestConnection < Test::Unit::TestCase - - def setup - @connection_impl = flexmock("connection_impl") - @other_connection = flexmock("other_connection") - @other_connection_impl = flexmock("other_connection_impl") - @cqpid_connection = flexmock(Cqpid::Connection) - - @session = flexmock("session") - @session_name = "test-session" - - @url = "localhost" - @options = {} - - @connection = Qpid::Messaging::Connection.new :url => @url, :options => @options, :impl => @connection_impl - end - - def test_initialize - @cqpid_connection. - should_receive(:new). - once. - with("localhost", {}). - and_return(@connection_impl) - - result = Qpid::Messaging::Connection.new - - assert_same @connection_impl, result.connection_impl - end - - def test_initialize_with_username_and_password - @cqpid_connection. - should_receive(:new). - once.with("localhost", - {"username" => "username", - "password" => "password"}). - and_return(@connection_impl) - @connection_impl. - should_receive(:open). - once - - result = Qpid::Messaging::Connection.new(:name => "localhost", - :options => { - :username => "username", - :password => "password" - }) - result.open - - assert_same @connection_impl, result.connection_impl - end - - def test_initialize_with_hostname - result = Qpid::Messaging::Connection.new("localhost") - - assert_not_nil result - end - - def test_open - @connection_impl. - should_receive(:open). - once - - @connection.open - - assert_same @connection_impl, @connection.connection_impl - end - - def test_check_open_when_open - @connection_impl. - should_receive(:isOpen). - once. - and_return(true) - - assert @connection.open? - end - - def test_check_open_before_connection - result = Qpid::Messaging::Connection.new("hostname") - - assert !result.open? - end - - def test_check_open_when_closed - @connection_impl. - should_receive(:isOpen). - once. - and_return(false) - - assert !@connection.open? - end - - def test_close - @connection_impl. - should_receive(:close) - - @connection.close - end - - def test_create_session_without_name - @connection_impl. - should_receive(:isOpen). - once. - and_return(true). - should_receive(:createSession). - once. - with(""). - and_return(@session) - - result = @connection.create_session - - assert_not_nil result - assert_same @session, result.session_impl - end - - def test_create_session - @connection_impl. - should_receive(:isOpen). - once. - and_return(true). - should_receive(:createSession). - once. - with(@session_name). - and_return(@session) - - result = @connection.create_session :name => @session_name - - assert_not_nil result - assert_same @session, result.session_impl - end - - def test_create_session_raises_exception_when_closed - @connection_impl. - should_receive(:isOpen). - once. - and_return(false) - - assert_raise(RuntimeError) {@connection.create_session @session_name} - end - - def test_create_transactional_session - @connection_impl. - should_receive(:isOpen). - once. - and_return(true). - should_receive(:createTransactionalSession). - once. - with(""). - and_return(@session) - - result = @connection.create_session :transactional => true - - assert_not_nil result - assert_same @session, result.session_impl - end - - def test_authenticated_username_when_not_connected - @connection_impl. - should_receive(:isOpen). - once. - and_return(false) - - result = @connection.authenticated_username - - assert_nil result - end - - def test_authenticated_username - @connection_impl. - should_receive(:isOpen). - once. - and_return(true). - should_receive(:getAuthenticatedUsername). - once. - and_return("farkle") - - result = @connection.authenticated_username - - assert_equal "farkle", result - end - - def test_get_session_with_invalid_name - @connection_impl. - should_receive(:getSession). - once. - with(@session_name). - and_return(nil) - - result = @connection.session @session_name - - assert_nil result - end - - # APIs inherited from Handle - - def test_is_valid - @connection_impl. - should_receive(:isValid). - once. - and_return(true) - - assert @connection.valid? - end - - def test_is_null - @connection_impl. - should_receive(:isNull). - once. - and_return(false) - - assert !@connection.null? - end - - def test_session_with_invalid_session - @connection_impl. - should_receive(:getSession). - with("farkle"). - and_raise(::RuntimeError) - - assert_raise(Qpid::Messaging::SessionNameException) {@connection.session "Farkle"} - end - - def test_swap - @other_connection. - should_receive(:connection_impl). - once. - and_return(@other_connection_impl) - @connection_impl. - should_receive(:swap). - once. - with(@other_connection_impl) - - @connection.swap @other_connection - end - -end - diff --git a/cpp/bindings/qpid/ruby/test/test_encoding.rb b/cpp/bindings/qpid/ruby/test/test_encoding.rb deleted file mode 100644 index 060975a1d5..0000000000 --- a/cpp/bindings/qpid/ruby/test/test_encoding.rb +++ /dev/null @@ -1,146 +0,0 @@ -# -# 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. -# - -$:.unshift File.join(File.dirname(__FILE__), "..", "lib") - -require 'test/unit' -require 'flexmock/test_unit' - -require 'cqpid' -require 'qpid/encoding' - -class TestEncoding < Test::Unit::TestCase - - def setup - @cqpid = flexmock(Cqpid) - - @message = flexmock("message") - @message_impl = flexmock("message_impl") - - @encoded = {"foo" => "bar"} - end - - def test_encode_map_with_symbols - @message. - should_receive(:message_impl). - once. - and_return(@message_impl) - @cqpid. - should_receive(:encode). - once. - with({"foo" => "bar"}, @message_impl). - and_return(@encoded) - - result = Qpid::Messaging.encode({:foo => :bar}, @message) - - assert_same @encoded, result - end - - def test_encode_list_with_symbols - @message. - should_receive(:message_impl). - once. - and_return(@message_impl) - @cqpid. - should_receive(:encode). - once. - with(["foo", "bar"], @message_impl). - and_return(@encoded) - - result = Qpid::Messaging.encode([:foo, :bar], @message) - - assert_same @encoded, result - end - - def test_encode_with_content_type - @message. - should_receive(:message_impl). - once. - and_return(@message_impl) - @cqpid. - should_receive(:encode). - once. - with({"foo" => "bar"}, @message_impl). - and_return(@encoded) - - result = Qpid::Messaging.encode({:foo => :bar}, @message) - - assert_same @encoded, result - end - - def test_encode - @message. - should_receive(:message_impl). - once. - and_return(@message_impl) - @cqpid. - should_receive(:encode). - once. - with({"foo" => "bar"}, @message_impl). - and_return(@encoded) - - result = Qpid::Messaging.encode({"foo" => "bar"}, @message) - - assert_same @encoded, result - end - - def test_decode_for_map - decoded = {"foo" => "bar"} - @message. - should_receive(:content_type). - once. - and_return("amqp/map") - @message. - should_receive(:message_impl). - once. - and_return(@message_impl) - @cqpid. - should_receive(:decodeMap). - once. - with(@message_impl). - and_return(decoded) - - result = Qpid::Messaging.decode(@message) - - assert_same decoded, result - end - - def test_decode_for_list - decoded = ["foo", "bar"] - @message. - should_receive(:content_type). - once. - and_return("amqp/list") - @message. - should_receive(:message_impl). - once. - and_return(@message_impl) - @cqpid. - should_receive(:decodeList). - once. - with(@message_impl). - and_return(decoded) - - result = Qpid::Messaging.decode(@message) - - assert_same decoded, result - end - -end - diff --git a/cpp/bindings/qpid/ruby/test/test_message.rb b/cpp/bindings/qpid/ruby/test/test_message.rb deleted file mode 100644 index 3fc705bf7e..0000000000 --- a/cpp/bindings/qpid/ruby/test/test_message.rb +++ /dev/null @@ -1,353 +0,0 @@ -# -# 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. -# - -$:.unshift File.join(File.dirname(__FILE__), "..", "lib") - -require 'test/unit' -require 'flexmock/test_unit' - -require 'qpid' - -class TestMessage < Test::Unit::TestCase - - def setup - @address = flexmock("address") - @address_impl = flexmock("address_impl") - - @messaging = flexmock(Qpid::Messaging) - @message_impl = flexmock("message") - @message = Qpid::Messaging::Message.new({}, @message_impl) - end - - def test_message_impl - assert_same @message_impl, @message.message_impl - end - - def test_set_reply_to - @address. - should_receive(:address_impl). - once. - and_return(@address_impl) - @message_impl. - should_receive(:setReplyTo). - once. - with(@address_impl) - - @message.reply_to = @address - end - - def test_get_reply_to - @message_impl. - should_receive(:getReplyTo). - once. - and_return(@address_impl) - - result = @message.reply_to - - assert_not_nil result - assert_same @address_impl, result.address_impl - end - - def test_set_subject - @message_impl. - should_receive(:setSubject). - once. - with("New Subject") - - @message.subject = "New Subject" - end - - def test_get_subject - @message_impl. - should_receive(:getSubject). - once. - and_return("Old Subject") - - assert_equal "Old Subject", @message.subject - end - - def test_set_content_type - @message_impl. - should_receive(:setContentType). - once. - and_return("amqp/map") - - @message.content_type = "amqp/map" - end - - def test_get_content_type - @message_impl. - should_receive(:getContentType). - once. - and_return("amqp/list") - - assert_equal "amqp/list", @message.content_type - end - - def test_set_message_id - @message_impl. - should_receive(:setMessageId). - once. - with("717") - - @message.message_id = "717" - end - - def test_get_message_id - @message_impl. - should_receive(:getMessageId). - once. - and_return("1965") - - assert_equal "1965", @message.message_id - end - - def test_set_user_id - @message_impl. - should_receive(:setUserId). - once. - with("129") - - @message.user_id = "129" - end - - def test_get_user_id - @message_impl. - should_receive(:getUserId). - once. - and_return("1971") - - assert_equal "1971", @message.user_id - end - - def test_set_correlation_id - @message_impl. - should_receive(:setCorrelationId). - once. - with("320") - - @message.correlation_id = "320" - end - - def test_get_correlation_id - @message_impl. - should_receive(:getCorrelationId). - once. - and_return("1996") - - assert_equal "1996", @message.correlation_id - end - - def test_set_priority - @message_impl. - should_receive(:setPriority). - once. - with(9) - - @message.priority = 9 - end - - def test_get_priority - @message_impl. - should_receive(:getPriority). - once. - and_return(21) - - assert_equal 21, @message.priority - end - - def test_set_ttl - @message_impl. - should_receive(:setTtl). - once. - with(Qpid::Messaging::Duration::FOREVER) - - @message.ttl = Qpid::Messaging::Duration::FOREVER - end - - def test_get_ttl - @message_impl. - should_receive(:getTtl). - once. - and_return(Qpid::Messaging::Duration::SECOND) - - assert_equal Qpid::Messaging::Duration::SECOND, @message.ttl - end - - def test_set_durable - @message_impl. - should_receive(:setDurable). - once. - with(true) - - @message.durable = true - end - - def test_set_not_durable - @message_impl. - should_receive(:setDurable). - once. - with(false) - - @message.durable = false - end - - def test_get_durable - @message_impl. - should_receive(:getDurable). - once. - and_return(true) - - assert @message.durable - end - - def test_set_redelivered - @message_impl. - should_receive(:setRedelivered). - once. - with(true) - - @message.redelivered = true - end - - def test_set_not_redelivered - @message_impl. - should_receive(:setRedelivered). - once. - with(false) - - @message.redelivered = false - end - - def test_get_redelivered - @message_impl. - should_receive(:getRedelivered). - once. - and_return(false) - - assert !@message.redelivered - end - - def test_get_properties - properties = {"foo" => "bar"} - @message_impl. - should_receive(:getProperties). - once. - and_return(properties) - - result = @message.properties - - assert_equal properties, result - end - - def test_get_property - @message_impl. - should_receive(:getProperties). - once. - and_return({"foo" => "bar"}) - - result = @message["foo"] - - assert_equal "bar", result - end - - def test_set_property - @message_impl. - should_receive(:setProperty). - once. - with("foo", "bar") - - @message["foo"] = "bar" - end - - def test_set_content - @message_impl. - should_receive(:setContent). - once. - with("foo") - - @message.content = "foo" - assert_equal "foo", @message.content - end - - def test_set_content_with_array - content = ["one", "two", "three"] - - @messaging. - should_receive(:encode). - once. - with(content, @message, "amqp/list") - - @message.content = content - assert_same content, @message.content - end - - def test_set_content_with_map - content = {:foo => "bar", :dog => "cat"} - - @messaging. - should_receive(:encode). - once. - with(content, @message, "amqp/map") - - @message.content = content - assert_same content, @message.content - end - - def test_get_content - @message_impl. - should_receive(:getContent). - and_return("foo") - @message_impl. - should_receive(:getContentType). - and_return(String) - - assert_equal "foo", @message.content - end - - def test_get_content_with_array - decoded = ["foo", "bar"] - - @message_impl. - should_receive(:getContent). - and_return("[foo,bar]") - @message_impl. - should_receive(:getContentType). - and_return("amqp/list") - @messaging. - should_receive(:decode). - once. - with(@message, "amqp/list"). - and_return(decoded) - - result = @message.content - assert_same decoded, result - end - - def test_get_content_size - @message_impl. - should_receive(:getContentSize). - once. - and_return(68) - - assert_equal 68, @message.content_size - end - -end - diff --git a/cpp/bindings/qpid/ruby/test/test_receiver.rb b/cpp/bindings/qpid/ruby/test/test_receiver.rb deleted file mode 100644 index fdce91e695..0000000000 --- a/cpp/bindings/qpid/ruby/test/test_receiver.rb +++ /dev/null @@ -1,203 +0,0 @@ -# -# 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. -# - -$:.unshift File.join(File.dirname(__FILE__), "..", "lib") - -require 'test/unit' -require 'flexmock/test_unit' - -require 'qpid/receiver' - -class TestReceiver < Test::Unit::TestCase - - def setup - @session = flexmock("session") - @session_impl = flexmock("session_impl") - - @Message_class = flexmock(Qpid::Messaging::Message) - @Messaging_module = flexmock(Qpid::Messaging) - @message_impl = flexmock("message_impl") - @message = flexmock("message") - - @receiver_impl = flexmock("receiver") - @other_receiver = flexmock("other_receiver") - @other_receiver_impl = flexmock("other_receiver_impl") - @receiver = Qpid::Messaging::Receiver.new @session, @receiver_impl - end - - def test_receiver_impl - assert_same @receiver_impl, @receiver.receiver_impl - end - - def test_get - @receiver_impl. - should_receive(:get). - once. - with_any_args. - and_return(@message_impl) - - result = @receiver.get - - assert_not_nil result - assert_same @message_impl, result.message_impl - end - - def test_get_with_duration - @receiver_impl. - should_receive(:get). - once. - with_any_args. - and_return(@message_impl) - - result = @receiver.get Qpid::Messaging::Duration::MINUTE - - assert_not_nil result - assert_same @message_impl, result.message_impl - end - - def test_get_with_no_message_received - @receiver_impl. - should_receive(:get). - once. - with_any_args. - and_return(nil) - - result = @receiver.get Qpid::Messaging::Duration::SECOND - - assert_nil result - end - - def test_fetch - @receiver_impl. - should_receive(:fetch). - once. - with_any_args. - and_return(@message_impl) - - result = @receiver.fetch - - assert_not_nil result - assert_same @message_impl, result.message_impl - end - - def test_fetch_with_duration - @receiver_impl. - should_receive(:fetch). - once. - with_any_args. - and_return(@message_impl) - - result = @receiver.fetch Qpid::Messaging::Duration::MINUTE - - assert_not_nil result - assert_same @message_impl, result.message_impl - end - - def test_fetch_with_no_message_received - @receiver_impl. - should_receive(:fetch). - once. - with_any_args. - and_return(nil) - - result = @receiver.fetch Qpid::Messaging::Duration::SECOND - - assert_nil result - end - - def test_set_capacity - @receiver_impl. - should_receive(:setCapacity). - once. - with(15) - - @receiver.capacity = 15 - end - - def test_get_capacity - @receiver_impl. - should_receive(:getCapacity). - once. - and_return(17) - - assert_equal 17, @receiver.capacity - end - - def test_get_available - @receiver_impl. - should_receive(:getAvailable). - once. - and_return(2) - - assert_equal 2, @receiver.available - end - - def test_get_unsettled - @receiver_impl. - should_receive(:getUnsettled). - once. - and_return(12) - - assert_equal 12, @receiver.unsettled - end - - def test_close - @receiver_impl. - should_receive(:close). - once - - @receiver.close - end - - def test_closed_when_open - @receiver_impl. - should_receive(:isClosed). - once. - and_return(false) - - assert !@receiver.closed? - end - - def test_closed - @receiver_impl. - should_receive(:isClosed). - once. - and_return(true) - - assert @receiver.closed? - end - - def test_get_name - @receiver_impl. - should_receive(:getName). - once. - and_return("my-queue") - - assert_equal "my-queue", @receiver.name - end - - def test_get_session - result = @receiver.session - - assert_not_nil result - assert_same @session, result - end - -end - diff --git a/cpp/bindings/qpid/ruby/test/test_sender.rb b/cpp/bindings/qpid/ruby/test/test_sender.rb deleted file mode 100644 index 61da9e5771..0000000000 --- a/cpp/bindings/qpid/ruby/test/test_sender.rb +++ /dev/null @@ -1,148 +0,0 @@ -# -# 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. -# - -$:.unshift File.join(File.dirname(__FILE__), "..", "lib") - -require 'test/unit' -require 'flexmock/test_unit' - -require 'qpid/sender' - -class TestSender < Test::Unit::TestCase - - def setup - @messaging = flexmock(Qpid::Messaging) - @message = flexmock("message") - - @session = flexmock("session") - @session_impl = flexmock("session_impl") - - @sender_impl = flexmock("sender_impl") - @other_sender_impl = flexmock("other_sender_impl") - @sender = Qpid::Messaging::Sender.new @session, @sender_impl - @other_sender = flexmock("other_sender") - end - - def test_send - message_impl = "message_impl" - content = {:foo => :bar} - @message. - should_receive(:message_impl). - once. - and_return(message_impl) - @sender_impl. - should_receive(:send). - once. - with(message_impl, false) - - @sender.send @message - end - - def test_send_and_dont_block - message_impl = "message_impl" - content = {:foo => :bar} - @message. - should_receive(:message_impl). - once. - and_return(message_impl) - @sender_impl. - should_receive(:send). - once. - with(message_impl, false) - - @sender.send @message, :sync => false - end - - def test_send_and_block - message_impl = "message_impl" - content = {:foo => :bar} - @message. - should_receive(:message_impl). - once. - and_return(message_impl) - @sender_impl. - should_receive(:send). - once. - with(message_impl, true) - - @sender.send @message, :sync => true - end - - def test_close - @sender_impl. - should_receive(:close). - once - - @sender.close - end - - def test_set_capacity - @sender_impl. - should_receive(:setCapacity). - once. - with(17) - - @sender.capacity = 17 - end - - def test_get_capacity - @sender_impl. - should_receive(:getCapacity). - once. - and_return(12) - - assert_equal 12, @sender.capacity - end - - def test_unsettled - @sender_impl. - should_receive(:getUnsettled). - once. - and_return(5) - - assert_equal 5, @sender.unsettled - end - - def test_available - @sender_impl. - should_receive(:getAvailable). - once. - and_return(15) - - assert_equal 15, @sender.available - end - - def test_name - @sender_impl. - should_receive(:getName). - once. - and_return("myname") - - assert_equal "myname", @sender.name - end - - def test_session - result = @sender.session - - assert_not_nil result - assert_same @session, result - end - -end - diff --git a/cpp/bindings/qpid/ruby/test/test_session.rb b/cpp/bindings/qpid/ruby/test/test_session.rb deleted file mode 100644 index 7084f652b4..0000000000 --- a/cpp/bindings/qpid/ruby/test/test_session.rb +++ /dev/null @@ -1,434 +0,0 @@ -# -# 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. -# - -$:.unshift File.join(File.dirname(__FILE__), "..", "lib") - -require 'test/unit' -require 'flexmock/test_unit' - -require 'qpid/errors' -require 'qpid/duration' -require 'qpid/session' - -class TestSession < Test::Unit::TestCase - - def setup - @session_impl = flexmock("session_impl") - @other_session = flexmock("other_session") - @other_session_impl = flexmock("other_session_impl") - @sender = flexmock("sender") - - @Connection_class = flexmock(Qpid::Messaging::Connection) - @connection_impl = flexmock("connection_impl") - @connection = flexmock("connection") - - @Receiver_class = flexmock(Qpid::Messaging::Receiver) - @receiver = flexmock("receiver") - @receiver_impl = flexmock("receiver_impl") - - @address = flexmock("address") - @address_impl = flexmock("address_impl") - - @Sender_class = flexmock(Qpid::Messaging::Sender) - @sender = flexmock("sender") - @sender_impl = flexmock("sender_impl") - - @message = flexmock("message") - @message_impl = flexmock("message_impl") - - @duration = flexmock("duration") - @duration_impl = flexmock("duration_impl") - - @session = Qpid::Messaging::Session.new(@connection, @session_impl) - end - - def test_create_sender_with_Address - @address. - should_receive(:class). - once. - and_return(Qpid::Messaging::Address). - should_receive(:address_impl). - once. - and_return(@address_impl) - @session_impl. - should_receive(:createSender). - once. - with(@address_impl). - and_return(@sender_impl) - @sender_impl. - should_receive(:getName). - once. - and_return("foo") - - result = @session.create_sender @address - - assert_not_nil result - end - - def test_create_sender - @session_impl. - should_receive(:createSender). - once. - with_any_args. - and_return(@sender_impl) - @sender_impl. - should_receive(:getName). - once. - and_return("my-queue") - - result = @session.create_sender("my-queue") - - assert_not_nil result - assert_same result.sender_impl, @sender_impl - end - - def test_create_sender_with_address_string - @session_impl. - should_receive(:createSender). - once. - with("my-queue;{create:always}"). - and_return(@sender_impl) - @sender_impl. - should_receive(:getName). - once. - and_return("foo") - - result = @session.create_sender "my-queue;{create:always}" - - assert_same @sender_impl, result.sender_impl - end - - def test_create_receiver - @address. - should_receive(:class). - once. - and_return(Qpid::Messaging::Address). - should_receive(:address_impl). - once. - and_return(@address_impl) - @session_impl. - should_receive(:createReceiver). - once. - with(@address_impl). - and_return(@receiver_impl) - @receiver_impl. - should_receive(:getName). - once. - and_return("my-queue") - - result = @session.create_receiver(@address) - - assert_equal @receiver_impl, result.receiver_impl - end - - def test_create_receiver_with_address_string - @session_impl. - should_receive(:createReceiver). - once. - with("my-queue"). - and_return(@receiver_impl) - @receiver_impl. - should_receive(:getName). - once. - and_return("my-queue") - - result = @session.create_receiver("my-queue") - - assert_same @receiver_impl, result.receiver_impl - end - - def test_close - @session_impl. - should_receive(:close). - once - - @session.close - end - - def test_commit - @session_impl. - should_receive(:commit). - once - - @session.commit - end - - def test_rollback - @session_impl. - should_receive(:rollback). - once - - @session.rollback - end - - def test_acknowledge_with_no_args - @session_impl. - should_receive(:acknowledge). - once. - with(false) - - @session.acknowledge - end - - def test_acknowledge_and_sync - @session_impl. - should_receive(:acknowledge). - once. - with(true) - - @session.acknowledge :sync => true - end - - def test_acknowledge_and_dont_sync - @session_impl. - should_receive(:acknowledge). - once. - with(false) - - @session.acknowledge :sync => false - end - - def test_acknowledge_message_without_sync - @message. - should_receive(:message_impl). - once. - and_return(@message_impl) - @session_impl. - should_receive(:acknowledge). - once. - with(@message_impl, false) - - @session.acknowledge :message => @message - end - - def test_acknowledge_message_and_sync - @message. - should_receive(:message_impl). - once. - and_return(@message_impl) - @session_impl. - should_receive(:acknowledge). - once. - with(@message_impl, true) - - @session.acknowledge :message => @message, :sync => true - end - - def test_acknowledge_message_and_dont_sync - @message. - should_receive(:message_impl). - once. - and_return(@message_impl) - @session_impl. - should_receive(:acknowledge). - once. - with(@message_impl, false) - - @session.acknowledge :message => @message, :sync => false - end - - def test_reject_message - @message. - should_receive(:message_impl). - once. - and_return(@message_impl) - @session_impl. - should_receive(:reject). - once. - with(@message_impl) - - @session.reject @message - end - - def test_release_message - @message. - should_receive(:message_impl). - once. - and_return(@message_impl) - @session_impl. - should_receive(:release). - once. - with(@message_impl) - - @session.release @message - end - - def test_sync_without_block - @session_impl. - should_receive(:sync). - once - - @session.sync - end - - def test_sync_and_block - @session_impl. - should_receive(:sync). - once. - with(true) - - @session.sync :block => true - end - - def test_sync_and_dont_block - @session_impl. - should_receive(:sync). - once. - with(false) - - @session.sync :block => false - end - - def test_receivable - @session_impl. - should_receive(:getReceivable). - once. - and_return(5) - - assert_equal 5, @session.receivable - end - - def test_unsettled_acks - @session_impl. - should_receive(:getUnsettledAcks). - once. - and_return(17) - - assert_equal 17, @session.unsettled_acks - end - - def test_next_receiver_with_no_duration - @session_impl. - should_receive(:nextReceiver). - once. - with(Qpid::Messaging::Duration::FOREVER.duration_impl). - and_return(@receiver_impl) - - result = @session.next_receiver - - assert_same @receiver_impl, result.receiver_impl - end - - def test_next_receiver_with_duration - @duration. - should_receive(:duration_impl). - once. - and_return(@duration_impl) - @session_impl. - should_receive(:nextReceiver). - once. - with(@duration_impl). - and_return(@receiver_impl) - - result = @session.next_receiver @duration - - assert_same @receiver_impl, result.receiver_impl - end - - def test_sender_with_invalid_name - assert_raises(Qpid::Messaging::KeyError) { @session.sender "farkle" } - end - - def test_get_sender - @session_impl. - should_receive(:createSender). - once. - with("my-queue"). - and_return(@sender_impl) - @sender_impl. - should_receive(:getName). - once. - and_return("my-queue") - - sender = @session.create_sender "my-queue" - result = @session.sender "my-queue" - - assert_not_nil sender - assert_same sender, result - end - - def test_get_receiver - @session_impl. - should_receive(:createReceiver). - once. - with("my-queue"). - and_return(@receiver_impl) - @receiver_impl. - should_receive(:getName). - once. - and_return("my-queue") - - receiver = @session.create_receiver "my-queue" - result = @session.receiver "my-queue" - - assert_not_nil receiver - assert_same receiver, result - end - - def test_get_receiver_with_invalid_name - assert_raise(Qpid::Messaging::KeyError) { @session.receiver "farkle" } - end - - def test_connection - @connection. - should_receive(:connection_impl). - once. - and_return(@connection_impl) - - result = @session.connection - - assert_same @connection_impl, result.connection_impl - end - - def test_error_with_none - @session_impl. - should_receive(:hasError). - once. - and_return(false) - - assert !@session.errors? - end - - def test_error - @session_impl. - should_receive(:hasError). - once. - and_return(true) - - assert @session.errors? - end - - def test_errors - @session_impl. - should_receive(:checkError). - once. - and_raise(Exception, "Expected") - - assert_raises(Exception) { @session.errors } - end - - def test_errors_without_exceptions - @session_impl. - should_receive(:checkError). - once - - assert_nothing_raised { @session.errors } - end - -end diff --git a/cpp/bindings/qpid/ruby/test/ts_bindings.rb b/cpp/bindings/qpid/ruby/test/ts_bindings.rb deleted file mode 100644 index 7aa410c8f8..0000000000 --- a/cpp/bindings/qpid/ruby/test/ts_bindings.rb +++ /dev/null @@ -1,30 +0,0 @@ -# -# 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. -# - -$:.unshift File.join(File.dirname(__FILE__), "..", "lib") - -require 'test/unit' -require 'test_encoding' -require 'test_address' -require 'test_message' -require 'test_sender' -require 'test_receiver' -require 'test_session' -require 'test_connection' - |