You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/11/28 13:52:44 UTC
[PATCH core 4/4] CIMI: Added Cucumber features for MachineImage
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/Rakefile | 4 +
server/tests/cimi/features/machine_images.feature | 20 +++++++
server/tests/cimi/features/machines.feature | 18 ++++--
.../cimi/features/step_definitions/common_steps.rb | 61 ++++++++++++++++++++
.../features/step_definitions/machines_steps.rb | 30 +---------
server/tests/cimi/features/support/env.rb | 20 +++++++
6 files changed, 120 insertions(+), 33 deletions(-)
create mode 100644 server/tests/cimi/features/machine_images.feature
create mode 100644 server/tests/cimi/features/step_definitions/common_steps.rb
create mode 100644 server/tests/cimi/features/step_definitions/machine_images_steps.rb
diff --git a/server/Rakefile b/server/Rakefile
index 0d52f81..1668474 100644
--- a/server/Rakefile
+++ b/server/Rakefile
@@ -55,6 +55,10 @@ begin
t.cucumber_opts = "tests/cimi/features/machines.feature --format pretty"
t.rcov = false
end
+ Cucumber::Rake::Task.new(:machine_images) do |t|
+ t.cucumber_opts = "tests/cimi/features/machine_images.feature --format pretty"
+ t.rcov = false
+ end
end
rescue LoadError
end
diff --git a/server/tests/cimi/features/machine_images.feature b/server/tests/cimi/features/machine_images.feature
new file mode 100644
index 0000000..f855eac
--- /dev/null
+++ b/server/tests/cimi/features/machine_images.feature
@@ -0,0 +1,20 @@
+Feature: Managing Machines Images
+ In order to interact with the provider
+ We must first be provided a URL to the main entry point (CEP).
+
+Scenario: Listing Machine Images collection
+ Given Cloud Entry Point URL is provided
+ And client retrieve the Cloud Entry Point
+ When client lists Machine Images collection
+ Then client should get list of all Machine Images
+
+Scenario: Querying Machine Image
+ Given Cloud Entry Point URL is provided
+ And client retrieve the Cloud Entry Point
+ When client query for 'img1' Machine Image entity
+ Then client should verify that this Machine Image exists
+ And client should verify that this Machine Image has set
+ | *image_location | mock://img1 |
+ | description | Fedora 10 |
+ | name | img1 |
+ | uri | http://example.org/cimi/machine_images/img1 |
diff --git a/server/tests/cimi/features/machines.feature b/server/tests/cimi/features/machines.feature
index f3264d6..badf427 100644
--- a/server/tests/cimi/features/machines.feature
+++ b/server/tests/cimi/features/machines.feature
@@ -17,19 +17,25 @@ Feature: Managing Machines
Scenario: Querying created Machine
Given Cloud Entry Point URL is provided
And client retrieve the Cloud Entry Point
- When client query for 'sampleMachine1' Machine
- And client should verify that this machine exists
+ When client query for 'sampleMachine1' Machine entity
+ Then client should verify that this machine exists
+ And client should verify that this Machine has set
+ | name | sampleMachine1 ||
+ | description | sampleMachine1Description ||
+ | cpu | 1 ||
+ | memory | quantity | 1740 |
+ | state | RUNNING ||
Scenario: Stopping Machine
Given Cloud Entry Point URL is provided
And client retrieve the Cloud Entry Point
- When client executes stop operation on Machine 'sampleMAchine1'
- Then client should be able to query this Machine
+ When client executes stop operation on Machine 'sampleMachine1'
+ Then client should be able to query for 'sampleMachine1' Machine entity
And client should verify that this machine is stopped
Scenario: Starting Machine
Given Cloud Entry Point URL is provided
And client retrieve the Cloud Entry Point
- When client executes start operation on Machine 'sampleMAchine1'
- Then client should be able to query this Machine
+ When client executes start operation on Machine 'sampleMachine1'
+ Then client should be able to query for 'sampleMachine1' Machine entity
And client should verify that this machine is started
diff --git a/server/tests/cimi/features/step_definitions/common_steps.rb b/server/tests/cimi/features/step_definitions/common_steps.rb
new file mode 100644
index 0000000..9131171
--- /dev/null
+++ b/server/tests/cimi/features/step_definitions/common_steps.rb
@@ -0,0 +1,61 @@
+World(Rack::Test::Methods)
+
+Given /^Cloud Entry Point URL is provided$/ do
+ get '/cimi'
+ last_response.status.should == 301
+ last_response.location.should == "http://example.org/cimi/cloudEntryPoint"
+end
+
+Given /^client retrieve the Cloud Entry Point$/ do
+ get "/cimi/cloudEntryPoint"
+ header 'Accept', 'application/xml'
+ last_response.status.should == 200
+end
+
+When /^client lists ([\w ]+) collection$/ do |col_name|
+ authorize 'mockuser', 'mockpassword'
+ header 'Accept', 'application/xml'
+ get "/cimi/%s" % col_name.to_collection_uri
+ last_response.status.should == 200
+ puts last_response.body
+end
+
+Then /^client should get list of all ([\w ]+)$/ do |col_name|
+ root_name = "#{col_name.to_class_name}Collection"
+ last_xml_response.root.name.should == root_name
+ (last_xml_response/"#{root_name}/name").size.should == 1
+ (last_xml_response/"#{root_name}/name").first.text.should == 'default'
+ (last_xml_response/"#{root_name}/uri").size.should == 1
+ (last_xml_response/"#{root_name}/uri").first.text.should == last_request.url
+ (last_xml_response/"#{root_name}/#{col_name.to_class_name}").size.should == 3
+ (last_xml_response/"#{root_name}/#{col_name.to_class_name}").each do |machine_img|
+ machine_img[:href].should_not be_nil
+ machine_img[:href].should =~ /http:\/\/example\.org\/cimi\/#{col_name.to_collection_uri}\/img(\d)/
+ end
+end
+
+When /^client( should be able to)? query for '(\w+)' ([\w ]+) entity$/ do |s, entity_id, entity_name|
+ authorize 'mockuser', 'mockpassword'
+ header 'Accept', 'application/xml'
+ get "/cimi/%s/%s" % [entity_name.to_entity_uri, entity_id]
+ last_response.status.should == 200
+ puts last_response.body
+ @entity_id = entity_id
+end
+
+Then /^client should verify that this ([\w ]+) exists$/ do |entity_name|
+ root_name = entity_name.to_class_name
+ last_xml_response.root.name.should == root_name
+ @entity = last_xml_response
+end
+
+Then /^client should verify that this ([\w ]+) has set$/ do |entity, attrs|
+ model = CIMI::Model.const_get(entity.to_entity_name).from_xml(last_response.body)
+ attrs.rows_hash.each do |key, value|
+ if key =~ /^\*/
+ model.send(key.gsub(/^\*/, '').intern).href.should == value
+ else
+ model.send(key.intern).to_s.should == value
+ end
+ end
+end
diff --git a/server/tests/cimi/features/step_definitions/machine_images_steps.rb b/server/tests/cimi/features/step_definitions/machine_images_steps.rb
new file mode 100644
index 0000000..e69de29
diff --git a/server/tests/cimi/features/step_definitions/machines_steps.rb b/server/tests/cimi/features/step_definitions/machines_steps.rb
index 54c63a0..d8a6b87 100644
--- a/server/tests/cimi/features/step_definitions/machines_steps.rb
+++ b/server/tests/cimi/features/step_definitions/machines_steps.rb
@@ -1,17 +1,3 @@
-World(Rack::Test::Methods)
-
-Given /^Cloud Entry Point URL is provided$/ do
- get '/cimi'
- last_response.status.should == 301
- last_response.location.should == "http://example.org/cimi/cloudEntryPoint"
-end
-
-Given /^client retrieve the Cloud Entry Point$/ do
- get "/cimi/cloudEntryPoint"
- header 'Accept', 'application/xml'
- last_response.status.should == 200
-end
-
When /^client specifies a Machine Image$/ do |machine_image|
header 'Accept', 'application/xml'
authorize 'mockuser', 'mockpassword'
@@ -48,25 +34,15 @@ When /^client specifies a new Machine using$/ do |machine|
end
Then /^client should be able to create this Machine$/ do
- pending "NOTE: There is an inconsistency between Primer and CIMI spec\n"
+ pending "\nNOTE: There is an inconsistency between Primer and CIMI spec\n" +
+ "The Primer says that client should send just pointners MachineConf and MachineImg\n"+
+ "The CIMI says that full XML need to be provided in order to create a Machine\n\n"
@machine = CIMI::Model::Machine.from_xml(@builder.to_xml)
authorize 'mockuser', 'mockpassword'
post '/cimi/machines', @machine
last_response.status.should == 201
end
-When /^client query for '(\w+)' Machine$/ do |machine_id|
- header 'Accept', 'application/xml'
- authorize 'mockuser', 'mockpassword'
- get "/cimi/machines/%s" % machine_id
-end
-
-Then /^client should verify that this machine exists$/ do
- last_xml_response.root.name == 'Machine'
- last_response.status == 200
- @new_machine = last_xml_response
-end
-
Then /^client should be able to query this Machine$/ do
get "/cimi/machines/%s" % (@new_machine/'')
end
diff --git a/server/tests/cimi/features/support/env.rb b/server/tests/cimi/features/support/env.rb
index 2cd7f73..f55e811 100644
--- a/server/tests/cimi/features/support/env.rb
+++ b/server/tests/cimi/features/support/env.rb
@@ -16,6 +16,26 @@ def last_xml_response
Nokogiri::XML(last_response.body)
end
+class String
+
+ def to_class_name
+ to_entity_name.singularize
+ end
+
+ def to_entity_name
+ self.tr(' ', '')
+ end
+
+ def to_collection_uri
+ self.tr(' ', '_').downcase
+ end
+
+ def to_entity_uri
+ to_collection_uri.pluralize
+ end
+
+end
+
def app
Sinatra::Application
end
--
1.7.4.4