diff options
author | Ted Ross <tross@apache.org> | 2012-01-31 20:50:15 +0000 |
---|---|---|
committer | Ted Ross <tross@apache.org> | 2012-01-31 20:50:15 +0000 |
commit | f1e420a981aea9f88bf7fb7e2899c9e007b2a0bb (patch) | |
tree | 64cbfc63aefdbd9f7794286737542be68b53256c /qpid/cpp | |
parent | ccc58115dbb83eb6605b1b36a7363fa38c1713f1 (diff) | |
download | qpid-python-f1e420a981aea9f88bf7fb7e2899c9e007b2a0bb.tar.gz |
QPID-3791 - Cucumber-based integration tests for the Ruby binding.
Committed patch from Darryl Pierce.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1238807 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp')
18 files changed, 429 insertions, 17 deletions
diff --git a/qpid/cpp/bindings/qpid/ruby/Rakefile b/qpid/cpp/bindings/qpid/ruby/Rakefile index 852264574b..df0b3970b6 100644 --- a/qpid/cpp/bindings/qpid/ruby/Rakefile +++ b/qpid/cpp/bindings/qpid/ruby/Rakefile @@ -32,6 +32,7 @@ require "rake/extensiontask" require "rake/rdoctask" require "rake/testtask" +require "cucumber/rake/task" require "spec/rake/spectask" CLOBBER.include("pkg") @@ -50,15 +51,15 @@ HOMEPAGE = "http://qpid.apache.org" SUMMARY = "Qpid is an enterprise messaging framework." desc "Default: run all tests." -task :default => :"test:all" +task :default => :test + +desc "Runs all tests." +task :test => :"test:all" #--------------- # Testing tasks. #--------------- -desc "Run all tests (alias for test:all)." -task :test => :"test:all" - namespace :test do desc "Run RSpec tests." @@ -72,20 +73,11 @@ namespace :test do end desc "Run all tests (default)." - task :all => [:spec, :integrations] - - desc "Run unit tests." - Rake::TestTask.new(:units) do |t| - t.libs << "." - t.pattern = "test/test*.rb" - t.verbose = true - end + task :all => [:spec, :features] - desc "Run integration tests." - Rake::TestTask.new(:integrations) do |t| - t.libs << "." - t.pattern = "test/integration/*.rb" - t.verbose = true + Cucumber::Rake::Task.new(:features) do |t| + t.libs = ["lib", "ext/nonblockio"] + t.cucumber_opts = "--format progress" end end diff --git a/qpid/cpp/bindings/qpid/ruby/features/closing_a_connection.feature b/qpid/cpp/bindings/qpid/ruby/features/closing_a_connection.feature new file mode 100644 index 0000000000..a57bf764c4 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/features/closing_a_connection.feature @@ -0,0 +1,13 @@ +Feature: Closing an open connection + When working with a broker + As a producer or consumer + I want to close a connection + + Scenario: The connection is already closed + Given a closed connection + Then calling close does not raise an exception + + Scenario: The connection is open + Given an open connection + And the connection is closed + Then the connection is in the closed state
\ No newline at end of file diff --git a/qpid/cpp/bindings/qpid/ruby/features/closing_a_session.feature b/qpid/cpp/bindings/qpid/ruby/features/closing_a_session.feature new file mode 100644 index 0000000000..9ff9858e96 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/features/closing_a_session.feature @@ -0,0 +1,13 @@ +Feature: Closing an open session + While working with a session + As a producer or consumer + I want to close the session + + Scenario: The connection has already been closed + Given an open session with a closed connection + Then closing the session does not raise an error + + Scenario: Closing an active session + Given an open session + Then closing the session does not raise an error + And the connection is in the open state diff --git a/qpid/cpp/bindings/qpid/ruby/features/connecting_to_a_broker.feature b/qpid/cpp/bindings/qpid/ruby/features/connecting_to_a_broker.feature new file mode 100644 index 0000000000..95db50be8e --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/features/connecting_to_a_broker.feature @@ -0,0 +1,13 @@ +Feature: Connecting to a broker + In order to interaction on an AMQP network + As a producer or consumer + I want to connect to a broker + + Scenario: Connections are closed by default + Given a new connection + Then the connection is in the closed state + + Scenario: Opening a connection + Given a new connection + And the connection is opened + Then the connection is in the open state diff --git a/qpid/cpp/bindings/qpid/ruby/features/creating_a_receiver.feature b/qpid/cpp/bindings/qpid/ruby/features/creating_a_receiver.feature new file mode 100644 index 0000000000..f509f49115 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/features/creating_a_receiver.feature @@ -0,0 +1,29 @@ +Feature: Creating a receiver + When working with a messaging environment + As a consumer + I want to create a Receiver for consuming messages + + Scenario: The session is closed + Given a closed session + Then creating a receiver with "my-queue" raises an exception + + Scenario: The connection is closed + Given an open session with a closed connection + Then creating a receiver with "my-queue" raises an exception + + Scenario: The address is malformed + Given an open session + Then creating a receiver with "my-queue;{foo:bar}" raises an exception + + Scenario: The address string is valid but the queue does not exist + Given an open session + Then creating a receiver for a nonexistent queue raises an exception + + Scenario: The address string is fine + Given an open session + Then creating a receiver with "my-queue;{create:always}" succeeds + + Scenario: Using an Address object + Given an open session + And an Address with the name "create-receiver-test" and subject "foo" and option "create" set to "always" + Then creating a receiver with an Address succeeds diff --git a/qpid/cpp/bindings/qpid/ruby/features/creating_a_sender.feature b/qpid/cpp/bindings/qpid/ruby/features/creating_a_sender.feature new file mode 100644 index 0000000000..ac75543c2d --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/features/creating_a_sender.feature @@ -0,0 +1,25 @@ +Feature: Creating a sender + When working with a session + As a producer + I want to create a Sender for sending messages + + Scenario: The session is closed + Given a closed session + Then creating a sender with "my-queue;{create:always}" raises an exception + + Scenario: The connection is closed + Given an open session with a closed connection + Then creating a sender with "my-queue;{create:always}" raises an exception + + Scenario: The address is malformed + Given an open session + Then creating a sender with "my-queue;{foo:bar}" raises an exception + + Scenario: The address string is valid + Given an open session + Then creating a sender with "my-queue;{create:always}" succeeds + + Scenario: Using an Address object + Given an open session + And an Address with the name "my-queue" and subject "my-subject" and option "create" set to "always" + Then creating a sender with an Address succeeds diff --git a/qpid/cpp/bindings/qpid/ruby/features/creating_a_session.feature b/qpid/cpp/bindings/qpid/ruby/features/creating_a_session.feature new file mode 100644 index 0000000000..aa8226edef --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/features/creating_a_session.feature @@ -0,0 +1,12 @@ +Feature: Creating a session + When working with a broker + As a producer or consumer + I want to create a session + + Scenario: The connection is closed + Given a closed connection + Then creating a session raises an exception + + Scenario: The connection is open + Given an open connection + Then creating a session works diff --git a/qpid/cpp/bindings/qpid/ruby/features/getting_the_connections_authenticated_username.feature b/qpid/cpp/bindings/qpid/ruby/features/getting_the_connections_authenticated_username.feature new file mode 100644 index 0000000000..2382b975da --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/features/getting_the_connections_authenticated_username.feature @@ -0,0 +1,8 @@ +Feature: Getting the authenticated username from an open connection. + When connected to a broker + As a producer or consumer + I can retrieve the username used to authenticate + + Scenario: When connected anonymously + Given an open connection + Then the authenticated username should be "anonymous" diff --git a/qpid/cpp/bindings/qpid/ruby/features/receiving_a_message.feature b/qpid/cpp/bindings/qpid/ruby/features/receiving_a_message.feature new file mode 100644 index 0000000000..b68a78c337 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/features/receiving_a_message.feature @@ -0,0 +1,28 @@ +Feature: Receving a message + When working with a broker + As a message consumer + I need to be able to receive messages + + Scenario: Receiving after the session is closed + Given a sender and receiver for "my-queue;{create:always}" + And the message "this is a test" is sent + And the session is closed + Then getting the next message raises an error + + Scenario: Receiving after the connection is closed + Given a sender and receiver for "my-queue;{create:always}" + And the message "this is a test" is sent + And the connection is closed + Then getting the next message raises an error + + Scenario: No message is received on an empty queue + Given an existing receiver for "my-queue;{create:always}" + And the receiver has no pending messages + Then getting the next message raises an error + + Scenario: A message is pending + Given a sender and receiver for "my-queue;{create:always}" + And the receiver has a capacity of 1 + And the message "this is a test" is sent + Then the receiver should have 1 message available + And the receiver should receive a message with "this is a test" diff --git a/qpid/cpp/bindings/qpid/ruby/features/sending_a_message.feature b/qpid/cpp/bindings/qpid/ruby/features/sending_a_message.feature new file mode 100644 index 0000000000..b1127d3664 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/features/sending_a_message.feature @@ -0,0 +1,21 @@ +Feature: Sending a message + When working with a broker + As a producer + I want to send messages using an existing Sender + + Scenario: The session is closed + Given an open session + And creating a sender with "my-queue;{create:always}" succeeds + And the session is closed + Then sending the message "This is a test" should raise an error + + Scenario: The connection is closed + Given an open session + And creating a sender with "my-queue;{create:always}" succeeds + And the connection is closed + Then sending the message "This is a test" should raise an error + + Scenario: The message sends successfully + Given an open session + And creating a sender with "my-queue;{create:always}" succeeds + Then sending the message "This is a test" succeeds
\ No newline at end of file diff --git a/qpid/cpp/bindings/qpid/ruby/features/session_returns_its_connection.feature b/qpid/cpp/bindings/qpid/ruby/features/session_returns_its_connection.feature new file mode 100644 index 0000000000..fe3dd0fe35 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/features/session_returns_its_connection.feature @@ -0,0 +1,12 @@ +Feature: A session returns its connection + With an action session + As a producer or consumer + I can retrieve the underlying connection for the session + + Scenario: The connection is closed + Given an open session with a closed connection + Then the connection for the session is in the closed state + + Scenario: The connection is open + Given an open session + Then the connection for the session is in the open state diff --git a/qpid/cpp/bindings/qpid/ruby/features/sessions_have_names.feature b/qpid/cpp/bindings/qpid/ruby/features/sessions_have_names.feature new file mode 100644 index 0000000000..9afaa569d2 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/features/sessions_have_names.feature @@ -0,0 +1,8 @@ +Feature: Session have a name + When using a session + As a producer or consumer + I can name a session and then later retrieve it by name + + Scenario: Naming a session + Given an existing session named "test-session" + Then the session can be retrieved by the name "test-session" diff --git a/qpid/cpp/bindings/qpid/ruby/features/step_definitions/address_steps.rb b/qpid/cpp/bindings/qpid/ruby/features/step_definitions/address_steps.rb new file mode 100644 index 0000000000..e5071ca4e6 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/features/step_definitions/address_steps.rb @@ -0,0 +1,5 @@ +Given /^an Address with the name "([^"]*)" and subject "([^"]*)" and option "([^"]*)" set to "([^"]*)"$/ do |name, subject, key, value| + options = Hash.new + options["#{key}"] = "#{value}" + @address = Qpid::Messaging::Address.new "#{name}", "#{subject}", options +end diff --git a/qpid/cpp/bindings/qpid/ruby/features/step_definitions/connection_steps.rb b/qpid/cpp/bindings/qpid/ruby/features/step_definitions/connection_steps.rb new file mode 100644 index 0000000000..b4146ac1fb --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/features/step_definitions/connection_steps.rb @@ -0,0 +1,74 @@ +# close all connections +After do + @connection.close if @connection +end + +Given /^a new connection$/ do + @connection = Qpid::Messaging::Connection.new unless @connection +end + +Given /^an open connection$/ do + steps %Q{ + Given a new connection + } + @connection.open +end + +Given /^a closed connection$/ do + steps %Q{ + Given a new connection + } + @connection.close if @connection.open? +end + +Then /^the connection is in the (open|closed) state$/ do |state| + @connection.open?.should == false if state == "closed" + @connection.open?.should == true if state == "open" +end + +Given /^the connection is opened$/ do + @connection.open +end + +Given /^the connection is closed$/ do + @connection.close +end + +Then /^creating a session raises an exception$/ do + lambda { + @session = @connection.create_session + }.should raise_error +end + +Then /^creating a session works$/ do + steps %Q{ + Given a session exists with the name "nameless" + } + @session.should_not be_nil +end + +Given /^an existing session named "([^"]*)"$/ do |name| + steps %Q{ + Given an open connection + And a session exists with the name "#{name}" + } +end + +Given /^a session exists with the name "([^"]*)"$/ do |name| + @session = @connection.create_session :name => "#{name}" +end + +Then /^the session can be retrieved by the name "([^"]*)"$/ do |name| + session = @connection.session "#{name}" + session.should_not be_nil +end + +Then /^calling close does not raise an exception$/ do + lambda { + @connection.close + }.should_not raise_error +end + +Then /^the authenticated username should be "([^"]*)"$/ do |username| + @connection.authenticated_username.should == "#{username}" +end diff --git a/qpid/cpp/bindings/qpid/ruby/features/step_definitions/receiver_steps.rb b/qpid/cpp/bindings/qpid/ruby/features/step_definitions/receiver_steps.rb new file mode 100644 index 0000000000..8157fb7735 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/features/step_definitions/receiver_steps.rb @@ -0,0 +1,42 @@ +Given /^an existing receiver for "([^"]*)"$/ do |address| + steps %Q{ + Given an open session + Then creating a receiver with "#{address}" succeeds + } +end + +Given /^the receiver has no pending messages$/ do + available = @receiver.available + available.should == 0 +end + +Then /^getting the next message raises an error$/ do + lambda { + @message = @receiver.get Qpid::Messaging::Duration::IMMEDIATE + }.should raise_error +end + +Given /^a sender and receiver for "([^"]*)"$/ do |address| + steps %Q{ + Given an open session + Then creating a sender with "#{address}" succeeds + Then creating a receiver with "#{address}" succeeds + } +end + +Then /^the receiver should receive a message with "([^"]*)"$/ do |content| + @message = @receiver.fetch Qpid::Messaging::Duration::IMMEDIATE + + @message.should_not be_nil + @message.content.should == "#{content}" +end + +Given /^the receiver has a capacity of (\d+)$/ do |capacity| + @receiver.capacity = capacity.to_i +end + +Then /^the receiver should have (\d+) message available$/ do |available| + # TODO we shouldn't need to sleep a second in order to have this update + sleep 1 + @receiver.available.should == available.to_i +end diff --git a/qpid/cpp/bindings/qpid/ruby/features/step_definitions/sender_steps.rb b/qpid/cpp/bindings/qpid/ruby/features/step_definitions/sender_steps.rb new file mode 100644 index 0000000000..3ff081c7d2 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/features/step_definitions/sender_steps.rb @@ -0,0 +1,15 @@ +Given /^the message "([^"]*)" is sent$/ do |content| + @sender.send Qpid::Messaging::Message.new :content => "#{content}" +end + +Then /^sending the message "([^"]*)" should raise an error$/ do |content| + lambda { + steps %Q{ + Then sending the message "#{content}" succeeds + } + }.should raise_error +end + +Then /^sending the message "([^"]*)" succeeds$/ do |content| + @sender.send Qpid::Messaging::Message.new :content => "#{content}" +end diff --git a/qpid/cpp/bindings/qpid/ruby/features/step_definitions/session_steps.rb b/qpid/cpp/bindings/qpid/ruby/features/step_definitions/session_steps.rb new file mode 100644 index 0000000000..f97e423ee9 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/features/step_definitions/session_steps.rb @@ -0,0 +1,80 @@ +Given /^a closed session/ do + steps %Q{ + Given an open connection + Then creating a session works + } + @connection.close +end + +Then /^creating a sender with "([^"]*)" raises an exception$/ do |address| + lambda { + steps %Q{ + @sender = @session.create_sender "#{address}" + } + }.should raise_error +end + +Then /^creating a receiver with "([^"]*)" raises an exception$/ do |address| + lambda { + steps %Q{ + @sender = @session.create_sender "#{address}" + } + }.should raise_error +end + +Given /^an open session with a closed connection$/ do + steps %Q{ + Given an open connection + Then creating a session works + } + @session.connection.close +end + +Given /^an open session$/ do + steps %Q{ + Given an open connection + Then creating a session works + } +end + +Given /^the session is closed$/ do + @session.close +end + +Then /^creating a sender with "([^"]*)" succeeds$/ do |address| + @sender = @session.create_sender "#{address}" + @sender.should_not be_nil +end + +Then /^creating a sender with an Address succeeds$/ do + @sender = @session.create_receiver @address + @sender.should_not be_nil +end + +Then /^creating a receiver for a nonexistent queue raises an exception$/ do + lambda { + steps %Q{ + Then creating a receiver with "queue-#{Time.new.to_i}" succeeds + } + }.should raise_error +end + +Then /^creating a receiver with "([^"]*)" succeeds$/ do |address| + @receiver = @session.create_receiver "#{address}" + @receiver.should_not be_nil +end + +Then /^creating a receiver with an Address succeeds$/ do + @receiver = @session.create_receiver @address + @receiver.should_not be_nil +end + +Then /^closing the session does not raise an error$/ do + lambda { + @session.close + }.should_not raise_error +end + +Then /^the connection for the session is in the (open|closed) state$/ do |state| + @session.connection.open?.should == false if state == "closed" +end diff --git a/qpid/cpp/bindings/qpid/ruby/features/support/env.rb b/qpid/cpp/bindings/qpid/ruby/features/support/env.rb new file mode 100644 index 0000000000..1d15f56fc9 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/features/support/env.rb @@ -0,0 +1,22 @@ +# +# 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. +# + +$LOAD_PATH.unshift(File.dirname(__FILE__) + "/../../lib") + +require 'qpid' |