You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2010/09/30 13:00:05 UTC
svn commit: r1003007 - in /incubator/deltacloud/trunk/tests/mock:
api.feature instances.feature respond_to.feature
step_definitions/api_steps.rb step_definitions/instances_steps.rb
step_definitions/respond_to_steps.rb support/env.rb
Author: mfojtik
Date: Thu Sep 30 11:00:04 2010
New Revision: 1003007
URL: http://svn.apache.org/viewvc?rev=1003007&view=rev
Log:
Fixed Cucumber features to reflect changes in 0.9.0 release
Added:
incubator/deltacloud/trunk/tests/mock/respond_to.feature
incubator/deltacloud/trunk/tests/mock/step_definitions/respond_to_steps.rb
Modified:
incubator/deltacloud/trunk/tests/mock/api.feature
incubator/deltacloud/trunk/tests/mock/instances.feature
incubator/deltacloud/trunk/tests/mock/step_definitions/api_steps.rb
incubator/deltacloud/trunk/tests/mock/step_definitions/instances_steps.rb
incubator/deltacloud/trunk/tests/mock/support/env.rb
Modified: incubator/deltacloud/trunk/tests/mock/api.feature
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/tests/mock/api.feature?rev=1003007&r1=1003006&r2=1003007&view=diff
==============================================================================
--- incubator/deltacloud/trunk/tests/mock/api.feature (original)
+++ incubator/deltacloud/trunk/tests/mock/api.feature Thu Sep 30 11:00:04 2010
@@ -26,7 +26,14 @@ Feature: Accessing API entry points
Given URI /api exists
And authentification is not required for this URI
When client access this URI
- Then client should get list of valid entry points
+ Then client should get list of valid entry points:
+ | realms |
+ | instances |
+ | images |
+ | instance_states |
+ | hardware_profiles |
+ | storage_snapshots |
+ | storage_volumes |
And each link should have 'rel' attribute with valid name
And each link should have 'href' attribute with valid URL
When client follow this attribute
@@ -37,5 +44,5 @@ Feature: Accessing API entry points
And authentification is not required for this URI
When client access this URI
Then client should get list of features inside 'instances':
- | hardware_profiles |
| user_name |
+ | hardware_profiles |
Modified: incubator/deltacloud/trunk/tests/mock/instances.feature
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/tests/mock/instances.feature?rev=1003007&r1=1003006&r2=1003007&view=diff
==============================================================================
--- incubator/deltacloud/trunk/tests/mock/instances.feature (original)
+++ incubator/deltacloud/trunk/tests/mock/instances.feature Thu Sep 30 11:00:04 2010
@@ -154,10 +154,10 @@ Feature: Managing instances
Scenario: Destroying created instance
Given URI /api/instances exists
And authentification is required for this URI
- When client want to 'stop' created instance
+ When client want to 'stop' first instance
And client follow link in actions
- Then client should get created instance
+ Then client should get this instance
And this instance should be in 'STOPPED' state
- When client want to 'destroy' created instance
+ When client want to 'destroy' first instance
And client follow link in actions
And this instance should be destroyed
Added: incubator/deltacloud/trunk/tests/mock/respond_to.feature
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/tests/mock/respond_to.feature?rev=1003007&view=auto
==============================================================================
--- incubator/deltacloud/trunk/tests/mock/respond_to.feature (added)
+++ incubator/deltacloud/trunk/tests/mock/respond_to.feature Thu Sep 30 11:00:04 2010
@@ -0,0 +1,71 @@
+Feature: Returning valid responses with various queries
+
+ Scenario: User will get XML version if there is no Accept or format parameter
+ Given URI /api exists
+ And authentification is not required for this URI
+ And client perform an HTTP request for this URI
+ Then client should get valid XML response
+
+ Scenario: User wants to get XML version of API using Accept header
+ Given URI /api exists
+ And authentification is not required for this URI
+ When client use Accept header:
+ | application/xml;q=0.9 |
+ And client perform an HTTP request for this URI
+ Then client should get valid XML response
+
+ Scenario: User wants to get HTML version of API using Accept header
+ Given URI /api exists
+ And authentification is not required for this URI
+ When client use Accept header:
+ | application/xhtml+html;q=0.9 |
+ And client perform an HTTP request for this URI
+ Then client should get valid HTML response
+
+ Scenario: User wants to get JSON version of API
+ Given URI /api exists
+ And authentification is not required for this URI
+ When client use Accept header:
+ | application/json;q=0.9 |
+ And client perform an HTTP request for this URI
+ Then client should get valid JSON response
+
+ Scenario: User wants to get XML version of API with format parameter
+ Given URI /api exists
+ And authentification is not required for this URI
+ When client use Accept header:
+ | application/xhtml+html;q=0.9 |
+ And client accept this URI with parameters:
+ | format | xml |
+ And client perform an HTTP request for this URI
+ Then client should get valid XML response
+
+ Scenario: User wants to get JSON version of API with format parameter
+ Given URI /api exists
+ And authentification is not required for this URI
+ When client use Accept header:
+ | application/xhtml+html;q=0.9 |
+ And client accept this URI with parameters:
+ | format | json |
+ And client perform an HTTP request for this URI
+ Then client should get valid JSON response
+
+ Scenario: User set Accept to json but force format to XML using format parameter
+ Given URI /api exists
+ And authentification is not required for this URI
+ When client use Accept header:
+ | application/json;q=0.9 |
+ And client accept this URI with parameters:
+ | format | xml |
+ And client perform an HTTP request for this URI
+ Then client should get valid XML response
+
+ # Extensions are ignored, so this doesn't affect content-negotiation
+ Scenario: User wants to get XML version of API with format parameter and set extension
+ Given URI /api exists
+ And authentification is not required for this URI
+ When client wants to get URI '/api.xml'
+ When client use Accept header:
+ | application/xhtml+html;q=0.9 |
+ And client perform an HTTP request for this URI
+ Then client should get valid HTML response
Modified: incubator/deltacloud/trunk/tests/mock/step_definitions/api_steps.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/tests/mock/step_definitions/api_steps.rb?rev=1003007&r1=1003006&r2=1003007&view=diff
==============================================================================
--- incubator/deltacloud/trunk/tests/mock/step_definitions/api_steps.rb (original)
+++ incubator/deltacloud/trunk/tests/mock/step_definitions/api_steps.rb Thu Sep 30 11:00:04 2010
@@ -6,8 +6,17 @@ Given /^URI ([\w\/\-_]+) exists$/ do |ur
end
Given /^URI ([\w\/\-_]+) exists in (.+) format$/ do |uri, format|
- @uri = "#{uri}.#{format.downcase}"
- get @uri, {}
+ @no_header = true
+ case format.downcase
+ when 'xml':
+ header 'Accept', 'application/xml;q=9'
+ when 'json'
+ header 'Accept', 'application/json;q=9'
+ when 'html'
+ header 'Accept', 'application/xml+xhtml;q=9'
+ end
+ @uri = uri
+ get uri, {}
last_response.status.should_not == 404
last_response.status.should_not == 500
end
@@ -49,14 +58,6 @@ Then /^this URI should be available in (
@no_header = false
end
-Then /^client should get list of valid entry points$/ do
- links = []
- output_xml.xpath('/api/link').each do |entry_point|
- links << entry_point['rel']
- end
- @entry_points.should == links.sort
-end
-
Then /^each (\w+) should have '(.+)' attribute with valid (.+)$/ do |el, attr, t|
case el
when 'link':
Modified: incubator/deltacloud/trunk/tests/mock/step_definitions/instances_steps.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/tests/mock/step_definitions/instances_steps.rb?rev=1003007&r1=1003006&r2=1003007&view=diff
==============================================================================
--- incubator/deltacloud/trunk/tests/mock/step_definitions/instances_steps.rb (original)
+++ incubator/deltacloud/trunk/tests/mock/step_definitions/instances_steps.rb Thu Sep 30 11:00:04 2010
@@ -31,15 +31,14 @@ When /^client want to '(\w+)' first inst
end
When /^client follow link in actions$/ do
- unless @instance_url
- l = output_xml.xpath("/instances/instance[1]/actions/link[@rel = '#{@action}']").first
+
+ @instance ||= output_xml.xpath("/instance").first
+ l = @instance.xpath('actions/link[@rel="'+@action+'"]').first
+
+ if @action.eql?('destroy')
+ delete l[:href], { :id => @instance.xpath('@id').first.text }
else
- l = @instance.xpath('actions/link[@rel="'+@action+'"]').first
- end
- unless @action=='destroy'
post l[:href], { :id => @instance.xpath('@id').first.text }
- else
- delete l[:href], { :id => @instance.xpath('@id').first.text }
end
last_response.status.should_not == 500
end
@@ -100,9 +99,10 @@ Then /^client should get created instanc
end
When /^this instance should be destroyed$/ do
- # TODO: Fix this bug in mock driver ?
- #get @instance_url, {}
- #last_response.status.should == 404
+ puts @instance[:href].to_s
+ get @instance[:href].to_s, {}
+ last_response.status.should == 404
+ output_xml.xpath('/error').first[:status].should == '404'
end
Then /^client should get HTML form$/ do
Added: incubator/deltacloud/trunk/tests/mock/step_definitions/respond_to_steps.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/tests/mock/step_definitions/respond_to_steps.rb?rev=1003007&view=auto
==============================================================================
--- incubator/deltacloud/trunk/tests/mock/step_definitions/respond_to_steps.rb (added)
+++ incubator/deltacloud/trunk/tests/mock/step_definitions/respond_to_steps.rb Thu Sep 30 11:00:04 2010
@@ -0,0 +1,33 @@
+When /^client use (\w+) header:$/ do |name, table|
+ accept_header = table.raw.flatten.sort
+ @no_header = true
+ header name, accept_header.first.strip
+end
+
+When /^client perform an HTTP request for this URI$/ do
+ @params ||= {}
+ get @uri, @params
+end
+
+Then /^client should get valid (HTML|JSON|XML|PNG) response$/ do |format|
+ format = format.strip.downcase
+ if format.eql?('html')
+ last_response.content_type.should =~ /text\/html/
+ elsif format.eql?('xml')
+ last_response.content_type.should =~ /application\/xml/
+ Nokogiri::XML(last_response.body).xpath('/api').size.should_not == 0
+ elsif format.eql?('json')
+ last_response.content_type.should =~ /application\/json/
+ JSON::parse(last_response.body).class.to_s.should == 'Hash'
+ end
+end
+
+When /^client accept this URI with parameters:$/ do |table|
+ p = table.raw.flatten.sort
+ @params ||= {}
+ @params[p.first.to_sym] = p.last
+end
+
+When /^client wants to get URI '(.*)'$/ do |uri|
+ @uri = uri
+end
Modified: incubator/deltacloud/trunk/tests/mock/support/env.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/tests/mock/support/env.rb?rev=1003007&r1=1003006&r2=1003007&view=diff
==============================================================================
--- incubator/deltacloud/trunk/tests/mock/support/env.rb (original)
+++ incubator/deltacloud/trunk/tests/mock/support/env.rb Thu Sep 30 11:00:04 2010
@@ -1,10 +1,9 @@
SERVER_DIR = File::expand_path(File::join(File::dirname(__FILE__), "../../../server"))
Dir.chdir(SERVER_DIR)
-
-require 'sinatra'
-require 'rack/test'
+require 'rubygems'
require 'nokogiri'
require '../server/server'
+require 'rack/test'
Sinatra::Application.set :environment, :test
Sinatra::Application.set :root, SERVER_DIR
@@ -14,12 +13,18 @@ CONFIG = {
:password => 'mockpassword'
}
+ENV['RACK_ENV'] = 'test'
+
World do
+ include Rack::Test::Methods
+
def app
@app = Rack::Builder.new do
- set :logging, true
- set :raise_errors, true
+ set :environment => :test
+ set :loggining => true
+ set :raise_errors => true
+ set :show_exceptions => true
run Sinatra::Application
end
end
@@ -30,10 +35,9 @@ World do
Before do
unless @no_header
- header 'Accept', 'application/xml'
+ header 'Accept', 'application/xml;q=9'
end
end
- include Rack::Test::Methods
end