You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by ma...@redhat.com on 2011/12/13 15:24:37 UTC

[PATCH 3/3] Adds cucumber scenario and steps for CIMI::Volumes

From: marios <ma...@redhat.com>


Signed-off-by: marios <ma...@redhat.com>
---
 server/Rakefile                                    |    4 +
 .../features/step_definitions/volumes_steps.rb     |   77 ++++++++++++++++++++
 server/tests/cimi/features/volumes.feature         |   32 ++++++++
 3 files changed, 113 insertions(+), 0 deletions(-)
 create mode 100644 server/tests/cimi/features/step_definitions/volumes_steps.rb
 create mode 100644 server/tests/cimi/features/volumes.feature

diff --git a/server/Rakefile b/server/Rakefile
index 50ea60a..5eacf16 100644
--- a/server/Rakefile
+++ b/server/Rakefile
@@ -63,6 +63,10 @@ begin
       t.cucumber_opts = "tests/cimi/features/machine_images.feature --format pretty"
       t.rcov = false
     end
+    Cucumber::Rake::Task.new(:volumes) do |t|
+      t.cucumber_opts = "tests/cimi/features/volumes.feature --format pretty"
+      t.rcov = false
+   end
   end
 rescue LoadError
 end
diff --git a/server/tests/cimi/features/step_definitions/volumes_steps.rb b/server/tests/cimi/features/step_definitions/volumes_steps.rb
new file mode 100644
index 0000000..922cb04
--- /dev/null
+++ b/server/tests/cimi/features/step_definitions/volumes_steps.rb
@@ -0,0 +1,77 @@
+When /^client specifies a Volume Configuration$/ do |volume_config|
+  header 'Accept', 'application/xml'
+  authorize 'mockuser', 'mockpassword'
+  get volume_config.raw[0][1]
+  last_response.status.should==200
+  @volume_config = CIMI::Model::VolumeConfiguration.from_xml(last_response.body)
+  @volume_config.class.should == CIMI::Model::VolumeConfiguration
+  @volume_config.attribute_values[:capacity].quantity.should == "2"
+  @volume_config.uri.should == volume_config.raw[0][1]
+end
+
+When /^client specifies a new Volume using$/ do |volume|
+  @volume_config.should_not be_nil
+  volume_name = volume.raw[0][1]
+  volume_description = volume.raw[1][1]
+  @builder = Nokogiri::XML::Builder.new do |xml|
+    xml.Volume(:xmlns => CMWG_NAMESPACE) {
+      xml.name volume_name
+      xml.description volume_description
+      xml.volumeTemplate {
+        xml.volumeConfig( :href => @volume_config.uri )
+      }
+    }
+  end
+end
+
+Then /^client should be able to create this Volume$/ do
+  authorize 'mockuser', 'mockpassword'
+  header 'Content-Type', 'application/xml'
+  post '/cimi/volumes', @builder.to_xml
+  last_response.status.should == 200
+  @@created_volume = CIMI::Model::Volume.from_xml(last_response.body)
+end
+
+When /^client GET the Volumes Collection$/ do
+  authorize 'mockuser', 'mockpassword'
+  header 'Content-Type', 'application/xml'
+  get "/cimi/volumes"
+  last_response.status.should == 200
+  @@volume_collection = VolumeCollection.from_xml(last_response.body)
+end
+
+Then /^client should get a list of volumes$/ do
+  @@volume_collection.uri.end_with?("/cimi/volumes").should == true
+  @@volume_collection.attribute_values.has_key?(:volumes).should == true
+end
+
+Then /^list of volumes should contain newly created volume$/ do
+  volumes = @@volume_collection.attribute_values[:volumes].map{|v| v.href.split("/").last}
+  volumes.include?(@@created_volume.name).should == true
+end
+
+When /^client GET the newly created Volume in json format$/ do
+  authorize 'mockuser', 'mockpassword'
+  get "/cimi/volumes/#{@@created_volume.name}?format=json"
+  last_response.status.should == 200
+  @@retrieved_volume = CIMI::Model::Volume.from_json(last_response.body)
+end
+
+Then /^client should verify that this Volume was created correctly$/ do |capacity|
+  @@retrieved_volume.name.should == @@created_volume.name
+  @@retrieved_volume.uri.should == @@created_volume.uri
+  @@retrieved_volume.capacity[:quantity].should == capacity.raw[0][1]
+end
+
+When /^client deletes the newly created Volume$/ do
+  authorize 'mockuser', 'mockpassword'
+  delete "/cimi/volumes/#{@@created_volume.name}"
+  last_response.status.should == 200
+end
+
+Then /^client should verify the volume was deleted$/ do
+  authorize 'mockuser', 'mockpassword'
+  get "/cimi/volumes/#{@@created_volume.name}"
+  last_response.status.should == 404
+end
+
diff --git a/server/tests/cimi/features/volumes.feature b/server/tests/cimi/features/volumes.feature
new file mode 100644
index 0000000..c8d5282
--- /dev/null
+++ b/server/tests/cimi/features/volumes.feature
@@ -0,0 +1,32 @@
+Feature: CIMI Volumes Collection
+  The URI of the Volumes collection is given in the Cloud Entry Point.
+
+Scenario: Create a new Volume entity
+  Given Cloud Entry Point URL is provided
+  And client retrieve the Cloud Entry Point
+  When client specifies a Volume Configuration
+    | volumeConfig | http://example.com/cimi/volume_configurations/2 |
+  And client specifies a new Volume using
+    | name | cucumber_volume |
+    | description | created in a cucumber scenario |
+  Then client should be able to create this Volume
+
+Scenario: Query the Volume collection
+  Given Cloud Entry Point URL is provided
+  And client retrieve the Cloud Entry Point
+  When client GET the Volumes Collection
+  Then client should get a list of volumes
+  And list of volumes should contain newly created volume
+
+Scenario: Query the newly created Volume
+  Given Cloud Entry Point URL is provided
+  And client retrieve the Cloud Entry Point
+  When client GET the newly created Volume in json format
+  Then client should verify that this Volume was created correctly
+    | capacity | 2 |
+
+Scenario: Delete the newly created Volume
+  Given Cloud Entry Point URL is provided
+  And client retrieve the Cloud Entry Point
+  When client deletes the newly created Volume
+  Then client should verify the volume was deleted
-- 
1.7.6.4