https://www.aeolusproject.org/redmine/issues/3248
This commit contains cucumber feature and step
definitions
Also adds invalid_provider Factory definition
---
src/features/provider_api.feature | 20 ++++----
.../step_definitions/provider_api_steps.rb | 45 ++++++++++++++++++++
src/features/step_definitions/provider_steps.rb | 9 ++++
src/spec/factories/provider.rb | 4 ++
4 files changed, 68 insertions(+), 10 deletions(-)
diff --git a/src/features/provider_api.feature b/src/features/provider_api.feature
index 66d4ac8..5f113b8 100644
--- a/src/features/provider_api.feature
+++ b/src/features/provider_api.feature
@@ -38,16 +38,16 @@ Feature: Manage Providers via API
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
-# And the provider should be created
-#
-# Scenario: Create a new provider with bad request
-# When I create provider with incorrect data
-# Then I should recieve Bad Request message
-# And the provider should not be created
-#
+ Scenario: Create a new provider
+ When I create provider with correct data via XML
+ Then I should recieve OK message
+ And the provider should be created
+
+ Scenario: Create a new provider with bad request
+ When I create provider with incorrect data via XML
+ Then I should recieve Bad Request message
+ And the provider should not be created
+
# Scenario: Update a provider
# Given there is a provider
# When I update that provider with correct data
diff --git a/src/features/step_definitions/provider_api_steps.rb
b/src/features/step_definitions/provider_api_steps.rb
index ede69aa..ec6058c 100644
--- a/src/features/step_definitions/provider_api_steps.rb
+++ b/src/features/step_definitions/provider_api_steps.rb
@@ -45,3 +45,48 @@ Then /^I should recieve Not Found error$/ do
xml_body.xpath('//error').size.should be_eql(1)
end
+When /^I create provider with correct data via XML$/ do
+ header 'Accept', 'application/xml'
+ header 'Content-Type', 'application/xml'
+
+ @provider = FactoryGirl.build(:mock_provider)
+
+ xml_provider = %Q[<?xml version="1.0" encoding="UTF-8"?>
+ <provider>
+ <name>#{(a)provider.name}</name>
+ <url>#{(a)provider.url}</url>
+
<provider_type_id>#{(a)provider.provider_type_id}</provider_type_id>
+ </provider>
+ ]
+
+ post api_providers_path, xml_provider
+end
+
+Then /^I should recieve OK message$/ do
+ response = last_response
+ response.headers['Content-Type'].should include('application/xml')
+ response.status.should be_eql(200)
+end
+
+When /^I create provider with incorrect data via XML$/ do
+ header 'Accept', 'application/xml'
+ header 'Content-Type', 'application/xml'
+
+ @provider = FactoryGirl.build(:invalid_provider)
+
+ xml_provider = %Q[<?xml version="1.0" encoding="UTF-8"?>
+ <provider>
+ <name>#{(a)provider.name}</name>
+ <url>#{(a)provider.url}</url>
+
<provider_type_id>#{(a)provider.provider_type_id}</provider_type_id>
+ </provider>
+ ]
+
+ post api_providers_path, xml_provider
+end
+
+Then /^I should recieve Bad Request message$/ do
+ response = last_response
+ response.headers['Content-Type'].should include('application/xml')
+ response.status.should be_eql(400)
+end
diff --git a/src/features/step_definitions/provider_steps.rb
b/src/features/step_definitions/provider_steps.rb
index c3d552b..9717280 100644
--- a/src/features/step_definitions/provider_steps.rb
+++ b/src/features/step_definitions/provider_steps.rb
@@ -31,6 +31,14 @@ def stub_framework(bool)
Provider.any_instance.stub(:valid_framework?).and_return(bool)
end
+Then /^the provider should be created$/ do
+ Provider.find_by_name_and_url((a)provider.name, @provider.url).should_not be_nil
+end
+
+Then /^the provider should not be created$/ do
+ Provider.find_by_name_and_url((a)provider.name, @provider.url).should be_nil
+end
+
Given /^there should not exist a provider named "([^\"]*)"$/ do |name|
Provider.find_by_name(name).should be_nil
end
@@ -166,3 +174,4 @@ Then /^provider "([^"]*)" should have all instances
stopped$/ do |arg1|
p = Provider.find_by_name(arg1)
p.instances_to_terminate.should be_empty
end
+
diff --git a/src/spec/factories/provider.rb b/src/spec/factories/provider.rb
index a85b73b..044e0ae 100644
--- a/src/spec/factories/provider.rb
+++ b/src/spec/factories/provider.rb
@@ -22,6 +22,10 @@ FactoryGirl.define do
url { |p| "http://www." + p.name + ".com/api" }
end
+ factory :invalid_provider, :parent => :mock_provider do
+ name { '' }
+ end
+
factory :mock_provider, :parent => :provider do
provider_type {ProviderType.find_by_deltacloud_driver("mock")}
url 'http://localhost:3002/api'
--
1.7.7.6