https://www.aeolusproject.org/redmine/issues/3239
This commit contains only cucumber feature and step definitions
---
src/features/provider_api.feature | 18 +++++-----
.../step_definitions/provider_api_steps.rb | 35 ++++++++++++++++++-
src/features/step_definitions/provider_steps.rb | 9 +++++
3 files changed, 51 insertions(+), 11 deletions(-)
diff --git a/src/features/provider_api.feature b/src/features/provider_api.feature
index eb2af2b..66d4ac8 100644
--- a/src/features/provider_api.feature
+++ b/src/features/provider_api.feature
@@ -29,15 +29,15 @@ Feature: Manage Providers via API
When I request a list of providers returned as XML
Then I should receive list of providers as XML
-# Scenario: Get details for provider as XML
-# Given there is a provider
-# When I ask for details of that provider as XML
-# Then I should recieve details of that provider as XML
-#
-# Scenario: Get details for non existing provider
-# When I ask for details of non existing provider
-# Then I should recieve Not Found error
-#
+ Scenario: Get details for provider as XML
+ Given there is a provider
+ When I ask for details of that provider as XML
+ Then I should recieve details of that provider as XML
+
+ Scenario: Get details for non existing provider
+ When I ask for details of non existing provider as XML
+ Then I should recieve Not Found error
+
# Scenario: Create a new provider
# When I create provider with correct data
# Then I should recieve OK message
diff --git a/src/features/step_definitions/provider_api_steps.rb
b/src/features/step_definitions/provider_api_steps.rb
index 71ffb47..ede69aa 100644
--- a/src/features/step_definitions/provider_api_steps.rb
+++ b/src/features/step_definitions/provider_api_steps.rb
@@ -6,11 +6,42 @@ end
When /^I request a list of providers returned as XML$/ do
header 'Accept', 'application/xml'
- get providers_path
+ get api_providers_path
end
-# TODO: complete tests for list of providers
Then /^I should receive list of providers as XML$/ do
response = last_response
response.headers['Content-Type'].should include('application/xml')
+ response.status.should be_eql(200)
+ xml_body = Nokogiri::XML(response.body)
+ xml_body.xpath('//providers/provider').size.should be_eql(3)
end
+
+When /^I ask for details of that provider as XML$/ do
+ header 'Accept', 'application/xml'
+ get api_provider_path((a)provider.id)
+end
+
+Then /^I should recieve details of that provider as XML$/ do
+ response = last_response
+ response.headers['Content-Type'].should include('application/xml')
+ response.status.should be_eql(200)
+ xml_body = Nokogiri::XML(response.body)
+ xml_body.xpath('//provider').size.should be_eql(1)
+end
+
+When /^I ask for details of non existing provider as XML$/ do
+ header 'Accept', 'application/xml'
+ provider = Provider.find_by_id(1)
+ provider.delete if provider
+ get api_provider_path(1)
+end
+
+Then /^I should recieve Not Found error$/ do
+ response = last_response
+ response.headers['Content-Type'].should include('application/xml')
+ response.status.should be_eql(404)
+ xml_body = Nokogiri::XML(response.body)
+ xml_body.xpath('//error').size.should be_eql(1)
+end
+
diff --git a/src/features/step_definitions/provider_steps.rb
b/src/features/step_definitions/provider_steps.rb
index a521ffe..c3d552b 100644
--- a/src/features/step_definitions/provider_steps.rb
+++ b/src/features/step_definitions/provider_steps.rb
@@ -39,10 +39,19 @@ Given /^there is not a provider named "([^"]*)"$/ do
|name|
destroy_provider(name)
end
+Given /^there is not (?:a )?provider with id "([^"]*)"$/ do |id|
+ provider = Provider.find_by_id(id.to_i)
+ if provider then provider.destroy end
+end
+
Given /^there is a provider named "([^\"]*)"$/ do |name|
@provider = FactoryGirl.create(:mock_provider, :name => name)
end
+Given /^there is a provider$/ do
+ @provider = FactoryGirl.create(:mock_provider)
+end
+
Given /^provider "([^"]*)" is not accessible$/ do |arg1|
stub_framework(false)
end
--
1.7.7.6