You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by lu...@apache.org on 2010/07/09 01:38:46 UTC

svn commit: r962237 - in /incubator/deltacloud/trunk/server/libexec: ./ tests/ tests/xmls/

Author: lutter
Date: Thu Jul  8 23:38:46 2010
New Revision: 962237

URL: http://svn.apache.org/viewvc?rev=962237&view=rev
Log:
Added unit tests

Added:
    incubator/deltacloud/trunk/server/libexec/tests/deltacloud_test.rb
    incubator/deltacloud/trunk/server/libexec/tests/flavors_test.rb
    incubator/deltacloud/trunk/server/libexec/tests/images_test.rb
    incubator/deltacloud/trunk/server/libexec/tests/instances_test.rb
    incubator/deltacloud/trunk/server/libexec/tests/realms_test.rb
    incubator/deltacloud/trunk/server/libexec/tests/storage_snapshots_test.rb
    incubator/deltacloud/trunk/server/libexec/tests/storage_volumes_test.rb
Removed:
    incubator/deltacloud/trunk/server/libexec/run_tests.sh
    incubator/deltacloud/trunk/server/libexec/tests/flavors.rb
    incubator/deltacloud/trunk/server/libexec/tests/instance-states.rb
    incubator/deltacloud/trunk/server/libexec/tests/realms.rb
    incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors-m1-small.xml
    incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors-unknown-testing.xml
    incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors-x86_64.xml
    incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors.xml
    incubator/deltacloud/trunk/server/libexec/tests/xmls/instance-states.xml
    incubator/deltacloud/trunk/server/libexec/tests/xmls/realms-us.xml
    incubator/deltacloud/trunk/server/libexec/tests/xmls/realms.xml
Modified:
    incubator/deltacloud/trunk/server/libexec/Rakefile

Modified: incubator/deltacloud/trunk/server/libexec/Rakefile
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/Rakefile?rev=962237&r1=962236&r2=962237&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/Rakefile (original)
+++ incubator/deltacloud/trunk/server/libexec/Rakefile Thu Jul  8 23:38:46 2010
@@ -18,12 +18,19 @@
 # Add your own tasks in files placed in lib/tasks ending in .rake,
 # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
 
-require(File.join(File.dirname(__FILE__), 'config', 'boot'))
-
 require 'rake'
 require 'rake/testtask'
-require 'rake/rdoctask'
-
-require 'tasks/rails'
 
-#require 'torquebox/tasks'
+desc "Run basic unit tests"
+Rake::TestTask.new("test") { |t|
+  t.test_files = FileList[
+    'tests/flavors_test.rb',
+    'tests/realms_test.rb',
+    'tests/images_test.rb',
+    'tests/instances_test.rb',
+    'tests/storage_volumes_test.rb',
+    'tests/storage_snapshots_test.rb',
+  ]
+  t.verbose = false
+  t.warning = false
+}

Added: incubator/deltacloud/trunk/server/libexec/tests/deltacloud_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/tests/deltacloud_test.rb?rev=962237&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/tests/deltacloud_test.rb (added)
+++ incubator/deltacloud/trunk/server/libexec/tests/deltacloud_test.rb Thu Jul  8 23:38:46 2010
@@ -0,0 +1,60 @@
+require 'rubygems'
+require 'test/unit'
+require 'rack/test'
+require 'base64'
+require 'nokogiri'
+require 'pp'
+require 'sinatra'
+
+ENV['API_DRIVER']='mock'
+ENV['API_HOST']='localhost'
+
+require 'server'
+
+set :environment => :test
+
+module DeltacloudTest
+    include Rack::Test::Methods
+
+    def app
+      Sinatra::Application
+    end
+
+    def test_if_response_is_valid
+      get '/api/'+@collection+'.xml', @params, rack_headers
+      assert last_response.ok?
+    end
+
+    def test_if_http_status_is_correct_with_wrong_credentials
+      return if ['flavors', 'realms'].include?(@collection)
+      wrong_header = rack_headers
+      wrong_header['HTTP_AUTHORIZATION'] = authorization('wronguser', 'wrongpassword')
+      get '/api/'+@collection+'.xml', @params, wrong_header
+      assert_equal 403, last_response.status
+    end
+
+    def test_if_index_operation_proper_root_element
+      get '/api/'+@collection+'.xml', @params, rack_headers
+      doc = Nokogiri::XML.parse(last_response.body)
+      assert_equal @collection.gsub('_', '-'), doc.root.name
+    end
+
+    def test_html_response
+      get '/api/'+@collection+'.html', @params, rack_headers
+      doc = Nokogiri::HTML.parse(last_response.body)
+      assert_equal 'html', doc.root.name
+    end
+
+    def authorization(username, password)
+      "Basic " + Base64.encode64("#{username}:#{password}")
+    end
+
+    def rack_headers
+      return { 
+        'HTTP_AUTHORIZATION' => authorization('mockuser', 'mockpassword'), 
+        'SERVER_PORT' => '4040', 
+        'Accept' => 'application/xml;q=1' 
+      }
+    end
+
+end

Added: incubator/deltacloud/trunk/server/libexec/tests/flavors_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/tests/flavors_test.rb?rev=962237&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/tests/flavors_test.rb (added)
+++ incubator/deltacloud/trunk/server/libexec/tests/flavors_test.rb Thu Jul  8 23:38:46 2010
@@ -0,0 +1,65 @@
+require 'tests/deltacloud_test'
+
+class FlavorsTest < Test::Unit::TestCase
+
+  def initialize(*args)
+    @collection = 'flavors'
+    @operations = [:index, :show]
+    @options = [:id, :architecture, :memory, :storage]
+    @params = {}
+    super(*args)
+  end
+
+  def test_if_flavors_are_not_empty
+    get '/api/flavors.xml', @params, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_not_equal 0, doc.xpath('/flavors/flavor').size
+  end
+
+  [:id, :architecture, :memory, :storage].each do |option|
+    method_name = :"test_if_flavors_index_contain_#{option}"
+    send :define_method, method_name do
+      get '/api/flavors.xml', @params, rack_headers
+      doc = Nokogiri::XML.parse(last_response.body)
+      flavor = doc.xpath('/flavors/flavor[1]').first
+      assert_not_nil flavor.xpath(option.to_s).first
+    end
+  end
+
+  [:id, :architecture, :memory, :storage].each do |option|
+    method_name = :"test_if_flavor_show_contain_#{option}"
+    send :define_method, method_name do
+      get '/api/flavors/m1-small.xml', @params, rack_headers
+      doc = Nokogiri::XML.parse(last_response.body)
+      flavor = doc.xpath('/flavor').first
+      assert_not_nil flavor.xpath(option.to_s).first
+    end
+  end
+
+  def test_flavors_filtering_by_architecture
+    @params[:architecture] = 'i386'
+    get '/api/flavors.xml', @params, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_equal 1, doc.xpath('/flavors/flavor').size
+    assert_equal @params[:architecture], doc.xpath('/flavors/flavor/architecture').first.text
+  end
+
+  def test_flavors_filtering_by_id
+    get '/api/flavors.xml', { :id => 'm1-small'}, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_equal 1, doc.xpath('/flavors/flavor').size
+    assert_equal 'm1-small', doc.xpath('/flavors/flavor/id').first.text
+  end
+
+  def test_flavors_filtering_by_id_and_architecture
+    get '/api/flavors.xml', { :architecture => 'x86_64', :id => 'c1-xlarge'}, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_equal 1, doc.xpath('/flavors/flavor').size
+    assert_equal 'c1-xlarge', doc.xpath('/flavors/flavor/id').first.text
+    assert_equal 'x86_64', doc.xpath('/flavors/flavor/architecture').first.text
+  end
+
+  include DeltacloudTest
+
+end
+

Added: incubator/deltacloud/trunk/server/libexec/tests/images_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/tests/images_test.rb?rev=962237&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/tests/images_test.rb (added)
+++ incubator/deltacloud/trunk/server/libexec/tests/images_test.rb Thu Jul  8 23:38:46 2010
@@ -0,0 +1,95 @@
+require 'tests/deltacloud_test'
+
+class ImagesTest < Test::Unit::TestCase 
+
+  def initialize(*args)
+    @collection = 'images'
+    @operations = [:index, :show]
+    @params = {}
+    super(*args)
+  end
+
+  def test_if_images_are_not_empty
+    get '/api/images.xml', @params, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_not_equal 0, doc.xpath('/images/image').size
+  end
+
+  [:id, :owner_id, :name, :description, :architecture].each do |option|
+    method_name = :"test_if_images_index_contain_#{option}"
+    send :define_method, method_name do
+      get '/api/images.xml', @params, rack_headers
+      doc = Nokogiri::XML.parse(last_response.body)
+      flavor = doc.xpath('/images/image[1]').first
+      assert_not_nil flavor.xpath(option.to_s).first
+    end
+  end
+
+  [:id, :owner_id, :name, :description, :architecture].each do |option|
+    method_name = :"test_if_image_show_contain_#{option}"
+    send :define_method, method_name do
+      get '/api/images/img1.xml', @params, rack_headers
+      doc = Nokogiri::XML.parse(last_response.body)
+      flavor = doc.xpath('/image').first
+      assert_not_nil flavor.xpath(option.to_s).first
+    end
+  end
+
+  def test_images_filtering_by_id
+    @params={ :id => 'img1' }
+    get '/api/images.xml', @params, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_equal 1, doc.xpath('/images/image').size
+    assert_equal @params[:id], doc.xpath('/images/image/id').first.text
+  end
+
+  def test_images_filtering_by_owner_id
+    @params={ :owner_id => 'fedoraproject' }
+    get '/api/images.xml', @params, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_equal 2, doc.xpath('/images/image').size
+    assert_equal @params[:owner_id], doc.xpath('/images/image/owner_id')[0].text
+    assert_equal @params[:owner_id], doc.xpath('/images/image/owner_id')[1].text
+  end
+
+  def test_images_filtering_by_architecture
+    @params={ :architecture => 'i386' }
+    get '/api/images.xml', @params, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_equal 2, doc.xpath('/images/image').size
+    assert_equal @params[:architecture], doc.xpath('/images/image/architecture')[0].text
+    assert_equal @params[:architecture], doc.xpath('/images/image/architecture')[1].text
+  end
+
+  def test_images_filtering_by_id_and_owner_id
+    @params={ :id => 'img1', :owner_id => 'fedoraproject' }
+    get '/api/images.xml', @params, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_equal 1, doc.xpath('/images/image').size
+    assert_equal @params[:owner_id], doc.xpath('/images/image/owner_id')[0].text
+    assert_equal @params[:id], doc.xpath('/images/image/id')[0].text
+  end
+
+  def test_images_filtering_by_id_and_owner_id_and_architecture
+    @params={ :id => 'img1', :owner_id => 'fedoraproject', :architecture => 'x86_64' }
+    get '/api/images.xml', @params, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_equal 1, doc.xpath('/images/image').size
+    assert_equal @params[:owner_id], doc.xpath('/images/image/owner_id')[0].text
+    assert_equal @params[:id], doc.xpath('/images/image/id')[0].text
+    assert_equal @params[:architecture], doc.xpath('/images/image/architecture')[0].text
+  end
+
+  def test_images_filtering_by_id_and_architecture
+    @params={ :id => 'img1', :architecture => 'x86_64' }
+    get '/api/images.xml', @params, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_equal 1, doc.xpath('/images/image').size
+    assert_equal @params[:id], doc.xpath('/images/image/id')[0].text
+    assert_equal @params[:architecture], doc.xpath('/images/image/architecture')[0].text
+  end
+
+  include DeltacloudTest
+  
+end
+

Added: incubator/deltacloud/trunk/server/libexec/tests/instances_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/tests/instances_test.rb?rev=962237&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/tests/instances_test.rb (added)
+++ incubator/deltacloud/trunk/server/libexec/tests/instances_test.rb Thu Jul  8 23:38:46 2010
@@ -0,0 +1,137 @@
+require 'tests/deltacloud_test'
+
+class InstancesTest < Test::Unit::TestCase 
+
+  def initialize(*args)
+    @collection = 'instances'
+    @operations = [:index, :show]
+    @options = [:id, :architecture, :memory, :storage]
+    @params = {}
+    self.temp_inst_id = 'inst2'
+    super(*args)
+  end
+
+  attr_accessor :temp_inst_id
+
+  def test_if_instances_are_not_empty
+    get '/api/instances.xml', @params, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_not_equal 0, doc.xpath('/instances/instance').size
+  end
+
+  [:id, :name, :owner_id, :image, :flavor, :realm, :state, :actions, :'public-addresses', :'private-addresses'].each do |option|
+    method_name = :"test_if_instances_index_contain_#{option}"
+    send :define_method, method_name do
+      get '/api/instances.xml', @params, rack_headers
+      doc = Nokogiri::XML.parse(last_response.body)
+      instance = doc.xpath('/instances/instance[1]').first
+      assert_not_nil instance.xpath(option.to_s).first
+    end
+  end
+
+  [:id, :name, :owner_id, :image, :flavor, :realm, :state, :actions, :'public-addresses', :'private-addresses'].each do |option|
+    method_name = :"test_if_instance_show_contain_#{option}"
+    send :define_method, method_name do
+      get '/api/instances/inst1.xml', @params, rack_headers
+      doc = Nokogiri::XML.parse(last_response.body)
+      instance = doc.xpath('/instance').first
+      assert_not_nil instance.xpath(option.to_s).first
+    end
+  end
+
+  def test_instances_filtering_by_id
+    get '/api/instances.xml', { :id => 'inst1'}, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_equal 1, doc.xpath('/instances/instance').size
+    assert_equal 'inst1', doc.xpath('/instances/instance/id').first.text
+  end
+
+  def test_instances_filtering_by_state
+    get '/api/instances.xml', { :state => 'RUNNING'}, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    doc.xpath('/instances/instance').each do |instance|
+      assert_equal 'RUNNING', instance.xpath('state').first.text
+    end
+  end
+
+  def test_instances_filtering_by_unknown_state
+    get '/api/instances.xml', { :state => '_TEST_UNKNOWN_STATE'}, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_equal 0, doc.xpath('/instances/instance').size
+  end
+
+  def test_001_create_instance
+    @params = {
+      :name     => '_test-instance',
+      :image_id => 'img1'
+    }
+
+    post '/api/instances.xml', @params, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+
+    self.temp_inst_id = doc.xpath('/instance/id').text
+
+    assert_equal @params[:name], doc.xpath('/instance/name').first.text
+    image_href = doc.xpath('/instance/image').first[:href].to_s
+    image_id = image_href.gsub(/.*\/(\w+)$/, '\1')
+    assert_equal @params[:image_id], image_id
+  end
+
+  def test_create_instance_with_flavor_id
+
+    @params = {
+      :name     => '_test-instance',
+      :image_id => 'img1',
+      :flavor_id => 'm1-xlarge'
+    }
+
+    post '/api/instances.xml', @params, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    flavor_href = doc.xpath('/instance/flavor').first[:href].to_s
+    flavor_id = flavor_href.gsub(/.*\/([\w\-]+)$/, '\1')
+    assert_equal @params[:flavor_id], flavor_id
+  end
+
+  def test_create_instance_with_realm_id
+
+    @params = {
+      :name     => '_test-instance',
+      :image_id => 'img1',
+      :realm_id => 'us'
+    }
+
+    post '/api/instances.xml', @params, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    realm_href = doc.xpath('/instance/realm').first[:href].to_s
+    realm_id = realm_href.gsub(/.*\/([\w\-]+)$/, '\1')
+    assert_equal @params[:realm_id], realm_id
+  end
+
+  def test_002_stop_instance
+    post '/api/instances/'+self.temp_inst_id+'/stop.xml', rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_equal 'STOPPED', doc.xpath('/instance/state').first.text
+  end
+
+  def test_003_start_instance
+    post '/api/instances/'+self.temp_inst_id+'/start.xml', rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_equal 'RUNNING', doc.xpath('/instance/state').first.text
+  end
+
+  def test_004_reboot_instance
+    post '/api/instances/'+self.temp_inst_id+'/reboot.xml', rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_equal 'RUNNING', doc.xpath('/instance/state').first.text
+  end
+
+  def test_005_destroy_instance
+    delete '/api/instances/'+self.temp_inst_id+'.xml', {}, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert last_response.ok?
+  end
+
+  include DeltacloudTest
+  
+end
+

Added: incubator/deltacloud/trunk/server/libexec/tests/realms_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/tests/realms_test.rb?rev=962237&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/tests/realms_test.rb (added)
+++ incubator/deltacloud/trunk/server/libexec/tests/realms_test.rb Thu Jul  8 23:38:46 2010
@@ -0,0 +1,57 @@
+require 'tests/deltacloud_test'
+
+class RealmsTest < Test::Unit::TestCase 
+
+  def initialize(*args)
+    @collection = 'realms'
+    @operations = [:index, :show]
+    @options = [:id, :name, :state]
+    @params = {}
+    super(*args)
+  end
+
+  def test_if_realms_are_not_empty
+    get '/api/realms.xml', @params, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_not_equal 0, doc.xpath('/realms/realm').size
+  end
+
+  [:id, :name, :state].each do |option|
+    method_name = :"test_if_realms_index_contain_#{option}"
+    send :define_method, method_name do
+      get '/api/realms.xml', @params, rack_headers
+      doc = Nokogiri::XML.parse(last_response.body)
+      flavor = doc.xpath('/realms/realm[1]').first
+      assert_not_nil flavor.xpath(option.to_s).first
+    end
+  end
+
+  [:id, :name, :state].each do |option|
+    method_name = :"test_if_realm_show_contain_#{option}"
+    send :define_method, method_name do
+      get '/api/realms/us.xml', @params, rack_headers
+      doc = Nokogiri::XML.parse(last_response.body)
+      flavor = doc.xpath('/realm').first
+      assert_not_nil flavor.xpath(option.to_s).first
+    end
+  end
+
+  def test_realms_filtering_by_state
+    @params[:state] = 'AVAILABLE'
+    get '/api/realms.xml', @params, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_equal 2, doc.xpath('/realms/realm').size
+    assert_equal @params[:state], doc.xpath('/realms/realm/state').first.text
+  end
+
+  def test_realms_filtering_by_id
+    get '/api/realms.xml', { :id => 'us'}, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_equal 1, doc.xpath('/realms/realm').size
+    assert_equal 'us', doc.xpath('/realms/realm/id').first.text
+  end
+
+  include DeltacloudTest
+  
+end
+

Added: incubator/deltacloud/trunk/server/libexec/tests/storage_snapshots_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/tests/storage_snapshots_test.rb?rev=962237&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/tests/storage_snapshots_test.rb (added)
+++ incubator/deltacloud/trunk/server/libexec/tests/storage_snapshots_test.rb Thu Jul  8 23:38:46 2010
@@ -0,0 +1,49 @@
+require 'tests/deltacloud_test'
+
+class StorageSnapshotsTest < Test::Unit::TestCase 
+
+  def initialize(*args)
+    @collection = 'storage_snapshots'
+    @operations = [:index, :show]
+    @options = [:id, :architecture, :memory, :storage]
+    @params = {}
+    super(*args)
+  end
+
+  def test_if_storage_snapshots_are_not_empty
+    get '/api/storage_snapshots.xml', @params, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_not_equal 0, doc.xpath('/storage-snapshots/storage-snapshot').size
+  end
+
+  [:id, :created, :state, :'storage-volume'].each do |option|
+    method_name = :"test_if_storage_snapshots_index_contain_#{option}"
+    send :define_method, method_name do
+      get '/api/storage_snapshots.xml', @params, rack_headers
+      doc = Nokogiri::XML.parse(last_response.body)
+      storage_volume = doc.xpath('/storage-snapshots/storage-snapshot[1]').first
+      assert_not_nil storage_volume.xpath(option.to_s).first
+    end
+  end
+
+  [:id, :created, :state, :'storage-volume'].each do |option|
+    method_name = :"test_if_storage_volume_show_contain_#{option}"
+    send :define_method, method_name do
+      get '/api/storage_snapshots/snap3.xml', @params, rack_headers
+      doc = Nokogiri::XML.parse(last_response.body)
+      storage_volume = doc.xpath('/storage-snapshot').first
+      assert_not_nil storage_volume.xpath(option.to_s).first
+    end
+  end
+
+  def test_storage_snapshots_filtering_by_id
+    get '/api/storage_snapshots.xml', { :id => 'snap3'}, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_equal 1, doc.xpath('/storage-snapshots/storage-snapshot').size
+    assert_equal 'snap3', doc.xpath('/storage-snapshots/storage-snapshot/id').first.text
+  end
+
+  include DeltacloudTest
+  
+end
+

Added: incubator/deltacloud/trunk/server/libexec/tests/storage_volumes_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/tests/storage_volumes_test.rb?rev=962237&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/tests/storage_volumes_test.rb (added)
+++ incubator/deltacloud/trunk/server/libexec/tests/storage_volumes_test.rb Thu Jul  8 23:38:46 2010
@@ -0,0 +1,49 @@
+require 'tests/deltacloud_test'
+
+class StorageVolumesTest < Test::Unit::TestCase 
+
+  def initialize(*args)
+    @collection = 'storage_volumes'
+    @operations = [:index, :show]
+    @options = [:id, :architecture, :memory, :storage]
+    @params = {}
+    super(*args)
+  end
+
+  def test_if_storage_volumes_are_not_empty
+    get '/api/storage_volumes.xml', @params, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_not_equal 0, doc.xpath('/storage-volumes/storage-volume').size
+  end
+
+  [:id, :created, :capacity, :device, :state].each do |option|
+    method_name = :"test_if_storage_volumes_index_contain_#{option}"
+    send :define_method, method_name do
+      get '/api/storage_volumes.xml', @params, rack_headers
+      doc = Nokogiri::XML.parse(last_response.body)
+      storage_volume = doc.xpath('/storage-volumes/storage-volume[1]').first
+      assert_not_nil storage_volume.xpath(option.to_s).first
+    end
+  end
+
+  [:id, :created, :capacity, :device, :state].each do |option|
+    method_name = :"test_if_storage_volume_show_contain_#{option}"
+    send :define_method, method_name do
+      get '/api/storage_volumes/vol2.xml', @params, rack_headers
+      doc = Nokogiri::XML.parse(last_response.body)
+      storage_volume = doc.xpath('/storage-volume').first
+      assert_not_nil storage_volume.xpath(option.to_s).first
+    end
+  end
+
+  def test_storage_volumes_filtering_by_id
+    get '/api/storage_volumes.xml', { :id => 'vol2'}, rack_headers
+    doc = Nokogiri::XML.parse(last_response.body)
+    assert_equal 1, doc.xpath('/storage-volumes/storage-volume').size
+    assert_equal 'vol2', doc.xpath('/storage-volumes/storage-volume/id').first.text
+  end
+
+  include DeltacloudTest
+  
+end
+