From: Ladislav Martincik <[email protected]>

---
 server/Rakefile                                    |   10 +-
 server/tests/api_test.rb                           |   38 ----
 server/tests/drivers/mock/api_test.rb              |   38 ++++
 .../tests/drivers/mock/hardware_profiles_test.rb   |  120 +++++++++++
 server/tests/drivers/mock/images_test.rb           |  112 ++++++++++
 server/tests/drivers/mock/instance_states_test.rb  |   52 +++++
 server/tests/drivers/mock/instances_test.rb        |  223 ++++++++++++++++++++
 server/tests/drivers/mock/realms_test.rb           |   79 +++++++
 server/tests/drivers/mock/url_for_test.rb          |   51 +++++
 server/tests/hardware_profiles_test.rb             |  120 -----------
 server/tests/images_test.rb                        |  111 ----------
 server/tests/instance_states_test.rb               |   51 -----
 server/tests/instances_test.rb                     |  222 -------------------
 server/tests/realms_test.rb                        |   78 -------
 server/tests/url_for_test.rb                       |   50 -----
 15 files changed, 676 insertions(+), 679 deletions(-)
 delete mode 100644 server/tests/api_test.rb
 create mode 100644 server/tests/drivers/mock/api_test.rb
 create mode 100644 server/tests/drivers/mock/hardware_profiles_test.rb
 create mode 100644 server/tests/drivers/mock/images_test.rb
 create mode 100644 server/tests/drivers/mock/instance_states_test.rb
 create mode 100644 server/tests/drivers/mock/instances_test.rb
 create mode 100644 server/tests/drivers/mock/realms_test.rb
 create mode 100644 server/tests/drivers/mock/url_for_test.rb
 delete mode 100644 server/tests/hardware_profiles_test.rb
 delete mode 100644 server/tests/images_test.rb
 delete mode 100644 server/tests/instance_states_test.rb
 delete mode 100644 server/tests/instances_test.rb
 delete mode 100644 server/tests/realms_test.rb
 delete mode 100644 server/tests/url_for_test.rb

diff --git a/server/Rakefile b/server/Rakefile
index a086fdb..eb0b767 100644
--- a/server/Rakefile
+++ b/server/Rakefile
@@ -30,15 +30,7 @@ end
 
 desc "Run basic unit tests"
 Rake::TestTask.new("test") { |t|
-  t.test_files = FileList[
-    'tests/api_test.rb',
-    'tests/hardware_profiles_test.rb',
-    'tests/realms_test.rb',
-    'tests/images_test.rb',
-    'tests/instances_test.rb',
-    'tests/instance_states_test.rb',
-    'tests/url_for_test.rb'
-  ]
+  t.test_files = FileList.new('tests/**/*_test.rb')
   t.verbose = true
   t.warning = false
 }
diff --git a/server/tests/api_test.rb b/server/tests/api_test.rb
deleted file mode 100644
index 9fbf04f..0000000
--- a/server/tests/api_test.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-$:.unshift File.join(File.dirname(__FILE__), '..')
-require 'tests/common'
-
-module DeltacloudUnitTest
-  class ApiTest < Test::Unit::TestCase
-    include Rack::Test::Methods
-
-    def app
-      Sinatra::Application
-    end
-
-    def test_it_returns_entry_points
-      do_xml_request '/api'
-      (last_xml_response/'/api/link').to_a.size.should > 0
-    end
-
-    def test_it_has_correct_attributes_set
-      do_xml_request '/api'
-      (last_xml_response/'/api/link').each do |link|
-        link.attributes.keys.sort.should == [ 'href', 'rel' ]
-      end
-    end
-
-    def test_it_responses_to_html
-      do_request '/api', {}, false, { :format => :html }
-      last_response.status.should == 200
-      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
-    end
-
-    def test_it_responses_to_json
-      do_request '/api', {}, false, { :format => :json }
-      last_response.status.should == 200
-      JSON::parse(last_response.body).class.should == Hash
-      JSON::parse(last_response.body)['api'].class.should == Hash
-    end
-
-  end
-end
diff --git a/server/tests/drivers/mock/api_test.rb 
b/server/tests/drivers/mock/api_test.rb
new file mode 100644
index 0000000..a7c451b
--- /dev/null
+++ b/server/tests/drivers/mock/api_test.rb
@@ -0,0 +1,38 @@
+$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
+require 'tests/common'
+
+module DeltacloudUnitTest
+  class ApiTest < Test::Unit::TestCase
+    include Rack::Test::Methods
+
+    def app
+      Sinatra::Application
+    end
+
+    def test_it_returns_entry_points
+      do_xml_request '/api'
+      (last_xml_response/'/api/link').length.should > 0
+    end
+
+    def test_it_has_correct_attributes_set
+      do_xml_request '/api'
+      (last_xml_response/'/api/link').each do |link|
+        link.attributes.keys.sort.should == [ 'href', 'rel' ]
+      end
+    end
+
+    def test_it_responses_to_html
+      do_request '/api', {}, false, { :format => :html }
+      last_response.status.should == 200
+      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
+    end
+
+    def test_it_responses_to_json
+      do_request '/api', {}, false, { :format => :json }
+      last_response.status.should == 200
+      JSON::parse(last_response.body).class.should == Hash
+      JSON::parse(last_response.body)['api'].class.should == Hash
+    end
+
+  end
+end
diff --git a/server/tests/drivers/mock/hardware_profiles_test.rb 
b/server/tests/drivers/mock/hardware_profiles_test.rb
new file mode 100644
index 0000000..8cdf5e1
--- /dev/null
+++ b/server/tests/drivers/mock/hardware_profiles_test.rb
@@ -0,0 +1,120 @@
+$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
+require 'tests/common'
+
+module DeltacloudUnitTest
+  class HardwareProfilesTest < Test::Unit::TestCase
+    include Rack::Test::Methods
+
+    def app
+      Sinatra::Application
+    end
+
+    def test_it_returns_hardware_profiles
+      do_xml_request '/api/hardware_profiles'
+      (last_xml_response/'hardware_profiles/hardware_profile').length.should > 0
+    end
+
+    def test_it_has_correct_attributes_set
+      do_xml_request '/api/hardware_profiles'
+      (last_xml_response/'hardware_profiles/hardware_profile').each do 
|profile|
+        profile.attributes.keys.sort.should == [ 'href', 'id' ]
+      end
+    end
+
+    def test_hardware_profiles_have_name
+      do_xml_request '/api/hardware_profiles'
+      (last_xml_response/'hardware_profiles/hardware_profile').each do 
|profile|
+        (profile/'name').text.should_not == nil
+      end
+    end
+
+    def test_hardware_profiles_have_unique_name
+      do_xml_request '/api/hardware_profiles'
+      names = []
+      (last_xml_response/'hardware_profiles/hardware_profile').each do 
|profile|
+        names << (profile/'name').text
+      end
+      names.should == names.uniq
+    end
+
+    def test_hardware_profiles_have_unique_id
+      do_xml_request '/api/hardware_profiles'
+      ids = []
+      (last_xml_response/'hardware_profiles/hardware_profile').each do 
|profile|
+        ids << profile['id']
+      end
+      ids.should == ids.uniq
+    end
+
+    def test_m1_xlarge_profile_has_correct_attributes
+      do_xml_request '/api/hardware_profiles'
+      profile = 
(last_xml_response/'hardware_profiles/hardware_profi...@id="m1-xlarge"]')
+      test_profile_properties(profile)
+    end
+
+    def test_it_returns_valid_hardware_profile
+      do_xml_request '/api/hardware_profiles/m1-xlarge'
+      profile = (last_xml_response/'hardware_profile')
+      test_profile_properties(profile)
+    end
+
+    def test_it_responses_to_json
+      do_request '/api/hardware_profiles', {}, false, { :format => :json }
+      JSON::parse(last_response.body).class.should == Hash
+      JSON::parse(last_response.body)['hardware_profiles'].class.should == 
Array
+
+      do_request '/api/hardware_profiles/m1-xlarge', {}, false, { :format => 
:json }
+      last_response.status.should == 200
+      JSON::parse(last_response.body).class.should == Hash
+      JSON::parse(last_response.body)['hardware_profile'].class.should == Hash
+    end
+
+    def test_it_responses_to_html
+      do_request '/api/hardware_profiles', {}, false, { :format => :html }
+      last_response.status.should == 200
+      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
+
+      do_request '/api/hardware_profiles/m1-xlarge', {}, false, { :format => 
:html }
+      last_response.status.should == 200
+      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
+    end
+
+    def test_it_returns_error_on_wrong_name
+      do_request '/api/hardware_profiles/m1-unknown-wrongname', {}, false, { 
:format => :html }
+      last_response.status.should == 404
+      do_xml_request '/api/hardware_profiles/m1-unknown-wrongname'
+      last_response.status.should == 404
+      do_request '/api/hardware_profiles/m1-unknown-wrongname', {}, false, { 
:format => :json }
+      last_response.status.should == 404
+    end
+
+    private
+
+    def test_profile_properties(profile)
+      (profile/'property').each do |properties|
+        properties.attributes.keys.sort.should == [ 'kind', 'name', 'unit', 
'value' ]
+      end
+
+      (profile/'proper...@name="architecture"]').first['kind'].should == 
'fixed'
+      (profile/'proper...@name="architecture"]').first['unit'].should == 
'label'
+
+      (profile/'proper...@name="memory"]').first['kind'].should == 'range'
+      (profile/'proper...@name="memory"]').first['unit'].should == 'MB'
+      (profile/'proper...@name="memory"]/range').length.should == 1
+      
(profile/'proper...@name="memory"]/range').first.attributes.keys.sort.should == 
[ 'first', 'last' ]
+
+      (profile/'proper...@name="cpu"]').first['kind'].should == 'fixed'
+      (profile/'proper...@name="cpu"]').first['unit'].should == 'count'
+
+      (profile/'proper...@name="storage"]').first['kind'].should == 'enum'
+      (profile/'proper...@name="storage"]').first['unit'].should == 'GB'
+      (profile/'proper...@name="storage"]/enum').length.should == 1
+      (profile/'proper...@name="storage"]/enum/entry').length.should == 3
+      (profile/'proper...@name="storage"]/enum/entry').each do |entry|
+        entry.attributes.keys.should == [ 'value' ]
+        entry['value'].should_not == nil
+      end
+    end
+
+  end
+end
diff --git a/server/tests/drivers/mock/images_test.rb 
b/server/tests/drivers/mock/images_test.rb
new file mode 100644
index 0000000..be2a51f
--- /dev/null
+++ b/server/tests/drivers/mock/images_test.rb
@@ -0,0 +1,112 @@
+$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
+require 'tests/common'
+
+module DeltacloudUnitTest
+  class HardwareProfilesTest < Test::Unit::TestCase
+    include Rack::Test::Methods
+
+    def app
+      Sinatra::Application
+    end
+
+    def test_it_require_authentication
+      require_authentication?('/api/images').should == true
+    end
+
+    def test_it_returns_images
+      do_xml_request '/api/images', {}, true
+      (last_xml_response/'images/image').length.should > 0
+    end
+
+    def test_it_has_correct_attributes_set
+      do_xml_request '/api/images', {}, true
+      (last_xml_response/'images/image').each do |image|
+        image.attributes.keys.sort.should == [ 'href', 'id' ]
+      end
+    end
+
+    def test_img1_has_correct_attributes
+      do_xml_request '/api/images', {}, true
+      image = (last_xml_response/'images/ima...@id="img1"]')
+      test_image_attributes(image)
+    end
+
+    def test_it_returns_valid_image
+      do_xml_request '/api/images/img1', {}, true
+      image = (last_xml_response/'image')
+      test_image_attributes(image)
+    end
+
+    def test_it_has_unique_ids
+      do_xml_request '/api/images', {}, true
+      ids = []
+      (last_xml_response/'images/image').each do |image|
+        ids << image['id'].to_s
+      end
+      ids.sort.should == ids.sort.uniq
+    end
+
+    def test_it_has_valid_urls
+      do_xml_request '/api/images', {}, true
+      ids = []
+      images = (last_xml_response/'images/image')
+      images.each do |image|
+        do_xml_request image['href'].to_s, {}, true
+        (last_xml_response/'image').first['href'].should == image['href'].to_s
+      end
+    end
+
+    def test_it_can_filter_using_owner_id
+      do_xml_request '/api/images', { :owner_id => 'mockuser' }, true
+      (last_xml_response/'images/image').length.should == 1
+      (last_xml_response/'images/image/owner_id').first.text.should == 
'mockuser'
+    end
+
+    def test_it_can_filter_using_unknown_owner_id
+      do_xml_request '/api/images', { :architecture => 'unknown_user' }, true
+      (last_xml_response/'images/image').length.should == 0
+    end
+
+    def test_it_can_filter_using_architecture
+      do_xml_request '/api/images', { :architecture => 'x86_64' }, true
+      (last_xml_response/'images/image').length.should == 1
+      (last_xml_response/'images/image/architecture').first.text.should == 
'x86_64'
+    end
+
+    def test_it_can_filter_using_unknown_architecture
+      do_xml_request '/api/images', { :architecture => 'unknown_arch' }, true
+      (last_xml_response/'images/image').length.should == 0
+    end
+
+    def test_it_responses_to_json
+      do_request '/api/images', {}, true, { :format => :json }
+      JSON::parse(last_response.body).class.should == Hash
+      JSON::parse(last_response.body)['images'].class.should == Array
+
+      do_request '/api/images/img1', {}, true, { :format => :json }
+      last_response.status.should == 200
+      JSON::parse(last_response.body).class.should == Hash
+      JSON::parse(last_response.body)['image'].class.should == Hash
+    end
+
+    def test_it_responses_to_html
+      do_request '/api/images', {}, true, { :format => :html }
+      last_response.status.should == 200
+      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
+
+      do_request '/api/images/img1', {}, true, { :format => :html }
+      last_response.status.should == 200
+      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
+    end
+
+    private
+
+    def test_image_attributes(image)
+      (image/'name').text.should_not nil
+      (image/'owner_id').text.should_not nil
+      (image/'description').text.should_not nil
+      (image/'architecture').text.should_not nil
+    end
+
+  end
+end
diff --git a/server/tests/drivers/mock/instance_states_test.rb 
b/server/tests/drivers/mock/instance_states_test.rb
new file mode 100644
index 0000000..04fb431
--- /dev/null
+++ b/server/tests/drivers/mock/instance_states_test.rb
@@ -0,0 +1,52 @@
+$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
+require 'tests/common'
+
+module DeltacloudUnitTest
+  class RealmsTest < Test::Unit::TestCase
+    include Rack::Test::Methods
+
+    def app
+      Sinatra::Application
+    end
+
+    def test_it_not_require_authentication
+      require_authentication?('/api/realms').should_not == true
+    end
+
+    def test_it_returns_instance_states
+      do_xml_request '/api/instance_states', {}, true
+      (last_xml_response/'states/state').length.should > 0
+    end
+
+    def test_each_state_has_transition
+      do_xml_request '/api/instance_states', {}, true
+      (last_xml_response/'states/state').each do |state|
+        next if state['name'].eql?('finish') # Finnish state doesn't have 
transitions
+        (state/'transition').length.should > 0
+        (state/'transition').each do |transition|
+          transition['to'].should_not == nil
+        end
+      end
+    end
+
+    def test_it_responses_to_json
+      do_request '/api/instance_states', {}, false, { :format => :json }
+      JSON::parse(last_response.body).class.should == Array
+      JSON::parse(last_response.body).first['transitions'].class.should == 
Array
+      JSON::parse(last_response.body).first['name'].should == 'start'
+    end
+
+    def test_it_responses_to_html
+      do_request '/api/instance_states', {}, false, { :format => :html }
+      last_response.status.should == 200
+      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
+    end
+
+    def test_it_responses_to_png
+      do_request '/api/instance_states', { :format => 'png' }, false
+      last_response.status.should == 200
+      last_response.headers['Content-Type'].should == 'image/png'
+    end
+
+  end
+end
diff --git a/server/tests/drivers/mock/instances_test.rb 
b/server/tests/drivers/mock/instances_test.rb
new file mode 100644
index 0000000..afd42eb
--- /dev/null
+++ b/server/tests/drivers/mock/instances_test.rb
@@ -0,0 +1,223 @@
+$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
+require 'tests/common'
+
+module DeltacloudUnitTest
+  class InstancesTest < Test::Unit::TestCase
+    include Rack::Test::Methods
+
+    def app
+      Sinatra::Application
+    end
+
+    def test_it_require_authentication
+      require_authentication?('/api/instances').should == true
+    end
+
+    def test_it_returns_instances
+      do_xml_request '/api/instances', {}, true
+      (last_xml_response/'instances/instance').length.should > 0
+    end
+
+    def test_it_has_correct_attributes_set
+      do_xml_request '/api/images', {}, true
+      (last_xml_response/'images/image').each do |image|
+        image.attributes.keys.sort.should == [ 'href', 'id' ]
+      end
+    end
+
+    def test_it_has_unique_ids
+      do_xml_request '/api/instances', {}, true
+      ids = []
+      (last_xml_response/'instances/instance').each do |image|
+        ids << image['id'].to_s
+      end
+      ids.sort.should == ids.sort.uniq
+    end
+
+    def test_inst1_has_correct_attributes
+      do_xml_request '/api/instances', {}, true
+      instance = (last_xml_response/'instances/instan...@id="inst1"]')
+      test_instance_attributes(instance)
+    end
+
+    def test_it_returns_valid_realm
+      do_xml_request '/api/instances/inst1', {}, true
+      instance = (last_xml_response/'instance')
+      test_instance_attributes(instance)
+    end
+
+    def test_it_responses_to_json
+      do_request '/api/instances', {}, true, { :format => :json }
+      JSON::parse(last_response.body).class.should == Hash
+      JSON::parse(last_response.body)['instances'].class.should == Array
+
+      do_request '/api/instances/inst1', {}, true, { :format => :json }
+      last_response.status.should == 200
+      JSON::parse(last_response.body).class.should == Hash
+      JSON::parse(last_response.body)['instance'].class.should == Hash
+    end
+
+    def test_it_responses_to_html
+      do_request '/api/instances', {}, true, { :format => :html }
+      last_response.status.should == 200
+      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
+
+      do_request '/api/instances/inst1', {}, true, { :format => :html }
+      last_response.status.should == 200
+      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
+    end
+
+    def test_it_create_a_new_instance_using_image_id
+      params = {
+        :image_id => 'img1'
+      }
+      header 'Accept', accept_header(:xml)
+      post '/api/instances', params, authenticate
+      last_response.status.should == 201
+      last_response.headers['Location'].should_not == nil
+      do_xml_request last_response.headers['Location'], {}, true
+      (last_xml_response/'instance/name').should_not == nil
+      add_created_instance (last_xml_response/'instance').first['id']
+      test_instance_attributes(last_xml_response/'instance')
+    end
+
+    def test_it_create_a_new_instance_using_image_id_and_name
+      params = {
+        :image_id => 'img1',
+        :name => "unit_test_instance1"
+      }
+      header 'Accept', accept_header(:xml)
+      post '/api/instances', params, authenticate(:format => :xml)
+      last_response.status.should == 201
+      last_response.headers['Location'].should_not == nil
+      do_xml_request last_response.headers['Location'], {}, true
+      (last_xml_response/'instance/name').text.should == 'unit_test_instance1'
+      add_created_instance (last_xml_response/'instance').first['id']
+      test_instance_attributes(last_xml_response/'instance')
+    end
+
+    def test_it_create_a_new_instance_using_image_id_and_name_and_hwp
+      params = {
+        :image_id => 'img1',
+        :name => "unit_test_instance1",
+        :hwp_id => "m1-xlarge"
+      }
+      header 'Accept', accept_header(:xml)
+      post '/api/instances', params, authenticate(:format => :xml)
+      last_response.status.should == 201
+      last_response.headers['Location'].should_not == nil
+      do_xml_request last_response.headers['Location'], {}, true
+      (last_xml_response/'instance/name').text.should == 'unit_test_instance1'
+      (last_xml_response/'instance/hardware_profile').first['id'].should == 
'm1-xlarge'
+      add_created_instance (last_xml_response/'instance').first['id']
+      test_instance_attributes(last_xml_response/'instance')
+    end
+
+    def test_it_z0_stop_and_start_instance
+      $created_instances.each do |instance_id|
+        do_xml_request "/api/instances/#{instance_id}", {}, true
+        stop_url = 
(last_xml_response/'actions/li...@rel="stop"]').first['href']
+        stop_url.should_not == nil
+        post create_url(stop_url), { :format => 'xml' }, authenticate
+        last_response.status.should == 200
+        instance = Nokogiri::XML(last_response.body)
+        test_instance_attributes(instance)
+        (instance/'state').text.should == 'STOPPED'
+        do_xml_request "/api/instances/#{instance_id}", {}, true
+        start_url = 
(last_xml_response/'actions/li...@rel="start"]').first['href']
+        start_url.should_not == nil
+        post create_url(start_url), { :format => 'xml'}, authenticate
+        last_response.status.should == 200
+        instance = Nokogiri::XML(last_response.body)
+        test_instance_attributes(instance)
+        (instance/'state').text.should == 'RUNNING'
+      end
+    end
+
+    def test_z0_reboot_instance
+      $created_instances.each do |instance_id|
+        do_xml_request "/api/instances/#{instance_id}", {}, true
+        reboot_url = 
(last_xml_response/'actions/li...@rel="reboot"]').first['href']
+        reboot_url.should_not == nil
+        post create_url(reboot_url), { :format => "xml"}, authenticate
+        last_response.status.should == 200
+        instance = Nokogiri::XML(last_response.body)
+        test_instance_attributes(instance)
+        (instance/'state').text.should == 'RUNNING'
+      end
+    end
+
+    def test_z1_stop_created_instances
+      $created_instances.each do |instance_id|
+        do_xml_request "/api/instances/#{instance_id}", {}, true
+        stop_url = 
(last_xml_response/'actions/li...@rel="stop"]').first['href']
+        stop_url.should_not == nil
+        post create_url(stop_url), {}, authenticate
+        last_response.status.should == 200
+        instance = Nokogiri::XML(last_response.body)
+        test_instance_attributes(instance)
+        (instance/'state').text.should == 'STOPPED'
+      end
+    end
+
+    def test_z2_destroy_created_instances
+      $created_instances.each do |instance_id|
+        do_xml_request "/api/instances/#{instance_id}", {}, true
+        destroy_url = 
(last_xml_response/'actions/li...@rel="destroy"]').first['href']
+        destroy_url.should_not == nil
+        delete create_url(destroy_url), {}, authenticate
+        last_response.status.should == 302
+        do_xml_request last_response.headers['Location'], {}, true
+        (last_xml_response/'instances').should_not == nil
+        do_xml_request "/api/instances/#{instance_id}", {}, true
+        last_response.status.should == 404
+      end
+    end
+
+    private
+
+    def test_instance_attributes(instance)
+      (instance/'name').should_not == nil
+      (instance/'owner_id').should_not == nil
+      ['RUNNING', 'STOPPED'].include?((instance/'state').text).should == true
+
+      (instance/'public_addreses').should_not == nil
+      (instance/'public_addresses/address').to_a.size.should > 0
+      (instance/'public_addresses/address').first.text.should_not == ""
+
+      (instance/'private_addresses').should_not == nil
+      (instance/'private_addresses/address').to_a.size.should > 0
+      (instance/'private_addresses/address').first.text.should_not == ""
+
+      (instance/'actions/link').to_a.size.should > 0
+      (instance/'actions/link').each do |link|
+        link['href'].should_not == ""
+        link['rel'].should_not == ""
+        link['method'].should_not == ""
+        ['get', 'post', 'delete', 'put'].include?(link['method']).should == 
true
+      end
+
+      (instance/'image').size.should > 0
+      (instance/'image').first['href'].should_not == ""
+      (instance/'image').first['id'].should_not == ""
+      do_xml_request (instance/'image').first['href'], {}, true
+      (last_xml_response/'image').should_not == nil
+      (last_xml_response/'image').first['href'] == 
(instance/'image').first['href']
+
+      (instance/'realm').size.should > 0
+      (instance/'realm').first['href'].should_not == ""
+      (instance/'realm').first['id'].should_not == ""
+      do_xml_request (instance/'realm').first['href']
+      (last_xml_response/'realm').should_not == nil
+      (last_xml_response/'realm').first['href'] == 
(instance/'realm').first['href']
+
+      (instance/'hardware_profile').size.should > 0
+      (instance/'hardware_profile').first['href'].should_not == ""
+      (instance/'hardware_profile').first['id'].should_not == ""
+      do_xml_request (instance/'hardware_profile').first['href']
+      (last_xml_response/'hardware_profile').should_not == nil
+      (last_xml_response/'hardware_profile').first['href'] == 
(instance/'hardware_profile').first['href']
+    end
+
+  end
+end
diff --git a/server/tests/drivers/mock/realms_test.rb 
b/server/tests/drivers/mock/realms_test.rb
new file mode 100644
index 0000000..e96b8db
--- /dev/null
+++ b/server/tests/drivers/mock/realms_test.rb
@@ -0,0 +1,79 @@
+$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
+require 'tests/common'
+
+module DeltacloudUnitTest
+  class RealmsTest < Test::Unit::TestCase
+    include Rack::Test::Methods
+
+    def app
+      Sinatra::Application
+    end
+
+    def test_it_not_require_authentication
+      require_authentication?('/api/realms').should_not == true
+    end
+
+    def test_it_returns_realms
+      do_xml_request '/api/realms', {}, true
+      (last_xml_response/'realms/realm').length.should > 0
+    end
+
+    def test_it_has_correct_attributes_set
+      do_xml_request '/api/realms', {}, true
+      (last_xml_response/'realms/realm').each do |realm|
+        realm.attributes.keys.sort.should == [ 'href', 'id' ]
+      end
+    end
+
+    def test_us_has_correct_attributes
+      do_xml_request '/api/realms', {}, true
+      realm = (last_xml_response/'realms/rea...@id="us"]')
+      test_realm_attributes(realm)
+    end
+
+    def test_it_returns_valid_realm
+      do_xml_request '/api/realms/us', {}, true
+      realm = (last_xml_response/'realm')
+      test_realm_attributes(realm)
+    end
+
+    def test_it_has_unique_ids
+      do_xml_request '/api/realms', {}, true
+      ids = []
+      (last_xml_response/'realms/realm').each do |realm|
+        ids << realm['id'].to_s
+      end
+      ids.sort.should == ids.sort.uniq
+    end
+
+    def test_it_responses_to_json
+      do_request '/api/realms', {}, false, { :format => :json }
+      JSON::parse(last_response.body).class.should == Hash
+      JSON::parse(last_response.body)['realms'].class.should == Array
+
+      do_request '/api/realms/us', {}, false, { :format => :json }
+      last_response.status.should == 200
+      JSON::parse(last_response.body).class.should == Hash
+      JSON::parse(last_response.body)['realm'].class.should == Hash
+    end
+
+    def test_it_responses_to_html
+      do_request '/api/realms', {}, false, { :format => :html }
+      last_response.status.should == 200
+      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
+
+      do_request '/api/realms/us', {}, false, { :format => :html }
+      last_response.status.should == 200
+      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
+    end
+
+    private
+
+    def test_realm_attributes(realm)
+      (realm/'name').should_not == nil
+      (realm/'limit').should_not == nil
+      ['AVAILABLE'].include?((realm/'state').text).should == true
+    end
+
+  end
+end
diff --git a/server/tests/drivers/mock/url_for_test.rb 
b/server/tests/drivers/mock/url_for_test.rb
new file mode 100644
index 0000000..967f10c
--- /dev/null
+++ b/server/tests/drivers/mock/url_for_test.rb
@@ -0,0 +1,51 @@
+$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
+require 'tests/common'
+
+module DeltacloudUnitTest
+  class UrlForTest < Test::Unit::TestCase
+    include Rack::Test::Methods
+
+    def app
+      Sinatra::Application
+    end
+
+    def test_it_works_for_root
+      verify_url_for("/", "/")
+    end
+
+    def test_it_works_for_root_absolute
+      verify_url_for("/", "http://localhost/";, :full)
+    end
+
+    def test_it_works_with_spaces
+      verify_url_for("/url with spaces", "/url%20with%20spaces")
+    end
+
+    def test_it_works_when_given_absolute
+      verify_url_for("http://test.com";, "http://test.com";)
+    end
+
+    def test_it_works_when_not_at_root_context
+      verify_url_for("/", "context/", :path_only, {}, {"SCRIPT_NAME" => 
"context"})
+    end
+
+    def verify_url_for(url, expected_url, mode=:path_only, params={}, 
rack_env={})
+      # generate a unique url for each test
+      test_url = "/url_for_test/#{expected_url.hash}/#{Time.now.to_i}"
+      # Create our sinatra test endpoint
+      self.class.create_test_url_content(test_url, url, mode)
+
+      # verify the generated url matches what we expect
+      get test_url, params, rack_env
+      last_response.body.should == expected_url
+    end
+
+    def self.create_test_url_content(test_url, url_content, mode)
+      get test_url do
+        content_type "text/plain"
+          url_for(url_content, mode)
+      end
+    end
+
+  end
+end
diff --git a/server/tests/hardware_profiles_test.rb 
b/server/tests/hardware_profiles_test.rb
deleted file mode 100644
index 4a8f1d7..0000000
--- a/server/tests/hardware_profiles_test.rb
+++ /dev/null
@@ -1,120 +0,0 @@
-require 'tests/common'
-
-module DeltacloudUnitTest
-  class HardwareProfilesTest < Test::Unit::TestCase
-    include Rack::Test::Methods
-
-    def app
-      Sinatra::Application
-    end
-
-    def test_it_returns_hardware_profiles
-      do_xml_request '/api/hardware_profiles'
-      
(last_xml_response/'hardware_profiles/hardware_profile').to_a.size.should > 0
-    end
-
-    def test_it_has_correct_attributes_set
-      do_xml_request '/api/hardware_profiles'
-      (last_xml_response/'hardware_profiles/hardware_profile').each do 
|profile|
-        profile.attributes.keys.sort.should == [ 'href', 'id' ]
-      end
-    end
-
-    def test_hardware_profiles_have_name
-      do_xml_request '/api/hardware_profiles'
-      (last_xml_response/'hardware_profiles/hardware_profile').each do 
|profile|
-        (profile/'name').text.should_not == nil
-      end
-    end
-
-    def test_hardware_profiles_have_unique_name
-      do_xml_request '/api/hardware_profiles'
-      names = []
-      (last_xml_response/'hardware_profiles/hardware_profile').each do 
|profile|
-        names << (profile/'name').text
-      end
-      names.should == names.uniq
-    end
-
-    def test_hardware_profiles_have_unique_id
-      do_xml_request '/api/hardware_profiles'
-      ids = []
-      (last_xml_response/'hardware_profiles/hardware_profile').each do 
|profile|
-        ids << profile['id']
-      end
-      ids.should == ids.uniq
-    end
-
-    def test_m1_xlarge_profile_has_correct_attributes
-      do_xml_request '/api/hardware_profiles'
-      profile = 
(last_xml_response/'hardware_profiles/hardware_profi...@id="m1-xlarge"]')
-      test_profile_properties(profile)
-    end
-
-    def test_it_returns_valid_hardware_profile
-      do_xml_request '/api/hardware_profiles/m1-xlarge'
-      profile = (last_xml_response/'hardware_profile')
-      test_profile_properties(profile)
-    end
-
-    def test_it_responses_to_json
-      do_request '/api/hardware_profiles', {}, false, { :format => :json }
-      JSON::parse(last_response.body).class.should == Hash
-      JSON::parse(last_response.body)['hardware_profiles'].class.should == 
Array
-
-      do_request '/api/hardware_profiles/m1-xlarge', {}, false, { :format => 
:json }
-      last_response.status.should == 200
-      JSON::parse(last_response.body).class.should == Hash
-      JSON::parse(last_response.body)['hardware_profile'].class.should == Hash
-    end
-
-    def test_it_responses_to_html
-      do_request '/api/hardware_profiles', {}, false, { :format => :html }
-      last_response.status.should == 200
-      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
-
-      do_request '/api/hardware_profiles/m1-xlarge', {}, false, { :format => 
:html }
-      last_response.status.should == 200
-      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
-    end
-
-    def test_it_returns_error_on_wrong_name
-      do_request '/api/hardware_profiles/m1-unknown-wrongname', {}, false, { 
:format => :html }
-      last_response.status.should == 404
-      do_xml_request '/api/hardware_profiles/m1-unknown-wrongname'
-      last_response.status.should == 404
-      do_request '/api/hardware_profiles/m1-unknown-wrongname', {}, false, { 
:format => :json }
-      last_response.status.should == 404
-    end
-
-    private
-
-    def test_profile_properties(profile)
-      
-      (profile/'property').each do |properties|
-        properties.attributes.keys.sort.should == [ 'kind', 'name', 'unit', 
'value' ]
-      end
-
-      (profile/'proper...@name="architecture"]').first['kind'].should == 
'fixed'
-      (profile/'proper...@name="architecture"]').first['unit'].should == 
'label'
-      
-      (profile/'proper...@name="memory"]').first['kind'].should == 'range'
-      (profile/'proper...@name="memory"]').first['unit'].should == 'MB'
-      (profile/'proper...@name="memory"]/range').size.should == 1
-      
(profile/'proper...@name="memory"]/range').first.attributes.keys.sort.should == 
[ 'first', 'last' ]
-
-      (profile/'proper...@name="cpu"]').first['kind'].should == 'fixed'
-      (profile/'proper...@name="cpu"]').first['unit'].should == 'count'
-      
-      (profile/'proper...@name="storage"]').first['kind'].should == 'enum'
-      (profile/'proper...@name="storage"]').first['unit'].should == 'GB'
-      (profile/'proper...@name="storage"]/enum').size.should == 1
-      (profile/'proper...@name="storage"]/enum/entry').to_a.size.should == 3
-      (profile/'proper...@name="storage"]/enum/entry').each do |entry|
-        entry.attributes.keys.should == [ 'value' ]
-        entry['value'].should_not == nil
-      end
-    end
-
-  end
-end
diff --git a/server/tests/images_test.rb b/server/tests/images_test.rb
deleted file mode 100644
index 7649d2d..0000000
--- a/server/tests/images_test.rb
+++ /dev/null
@@ -1,111 +0,0 @@
-require 'tests/common'
-
-module DeltacloudUnitTest
-  class HardwareProfilesTest < Test::Unit::TestCase
-    include Rack::Test::Methods
-
-    def app
-      Sinatra::Application
-    end
-
-    def test_it_require_authentication
-      require_authentication?('/api/images').should == true
-    end
-
-    def test_it_returns_images
-      do_xml_request '/api/images', {}, true
-      (last_xml_response/'images/image').to_a.size.should > 0
-    end
-
-    def test_it_has_correct_attributes_set
-      do_xml_request '/api/images', {}, true
-      (last_xml_response/'images/image').each do |image|
-        image.attributes.keys.sort.should == [ 'href', 'id' ]
-      end
-    end
-
-    def test_img1_has_correct_attributes
-      do_xml_request '/api/images', {}, true
-      image = (last_xml_response/'images/ima...@id="img1"]')
-      test_image_attributes(image)
-    end
-
-    def test_it_returns_valid_image
-      do_xml_request '/api/images/img1', {}, true
-      image = (last_xml_response/'image')
-      test_image_attributes(image)
-    end
-
-    def test_it_has_unique_ids
-      do_xml_request '/api/images', {}, true
-      ids = []
-      (last_xml_response/'images/image').each do |image|
-        ids << image['id'].to_s
-      end
-      ids.sort.should == ids.sort.uniq
-    end
-
-    def test_it_has_valid_urls
-      do_xml_request '/api/images', {}, true
-      ids = []
-      images = (last_xml_response/'images/image')
-      images.each do |image|
-        do_xml_request image['href'].to_s, {}, true
-        (last_xml_response/'image').first['href'].should == image['href'].to_s
-      end
-    end
-
-    def test_it_can_filter_using_owner_id
-      do_xml_request '/api/images', { :owner_id => 'mockuser' }, true
-      (last_xml_response/'images/image').size.should == 1
-      (last_xml_response/'images/image/owner_id').first.text.should == 
'mockuser'
-    end
-
-    def test_it_can_filter_using_unknown_owner_id
-      do_xml_request '/api/images', { :architecture => 'unknown_user' }, true
-      (last_xml_response/'images/image').size.should == 0
-    end
-
-    def test_it_can_filter_using_architecture
-      do_xml_request '/api/images', { :architecture => 'x86_64' }, true
-      (last_xml_response/'images/image').size.should == 1
-      (last_xml_response/'images/image/architecture').first.text.should == 
'x86_64'
-    end
-
-    def test_it_can_filter_using_unknown_architecture
-      do_xml_request '/api/images', { :architecture => 'unknown_arch' }, true
-      (last_xml_response/'images/image').size.should == 0
-    end
-
-    def test_it_responses_to_json
-      do_request '/api/images', {}, true, { :format => :json }
-      JSON::parse(last_response.body).class.should == Hash
-      JSON::parse(last_response.body)['images'].class.should == Array
-
-      do_request '/api/images/img1', {}, true, { :format => :json }
-      last_response.status.should == 200
-      JSON::parse(last_response.body).class.should == Hash
-      JSON::parse(last_response.body)['image'].class.should == Hash
-    end
-
-    def test_it_responses_to_html
-      do_request '/api/images', {}, true, { :format => :html }
-      last_response.status.should == 200
-      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
-
-      do_request '/api/images/img1', {}, true, { :format => :html }
-      last_response.status.should == 200
-      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
-    end
-
-    private
-
-    def test_image_attributes(image)
-      (image/'name').text.should_not nil
-      (image/'owner_id').text.should_not nil
-      (image/'description').text.should_not nil
-      (image/'architecture').text.should_not nil
-    end
-
-  end
-end
diff --git a/server/tests/instance_states_test.rb 
b/server/tests/instance_states_test.rb
deleted file mode 100644
index 4c0d0e0..0000000
--- a/server/tests/instance_states_test.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-require 'tests/common'
-
-module DeltacloudUnitTest
-  class RealmsTest < Test::Unit::TestCase
-    include Rack::Test::Methods
-
-    def app
-      Sinatra::Application
-    end
-
-    def test_it_not_require_authentication
-      require_authentication?('/api/realms').should_not == true
-    end
-
-    def test_it_returns_instance_states
-      do_xml_request '/api/instance_states', {}, true
-      (last_xml_response/'states/state').to_a.size.should > 0
-    end
-
-    def test_each_state_has_transition
-      do_xml_request '/api/instance_states', {}, true
-      (last_xml_response/'states/state').each do |state|
-        next if state['name'].eql?('finish') # Finnish state doesn't have 
transitions
-        (state/'transition').to_a.size.should > 0
-        (state/'transition').each do |transition|
-          transition['to'].should_not == nil
-        end
-      end
-    end
-
-    def test_it_responses_to_json
-      do_request '/api/instance_states', {}, false, { :format => :json }
-      JSON::parse(last_response.body).class.should == Array
-      JSON::parse(last_response.body).first['transitions'].class.should == 
Array
-      JSON::parse(last_response.body).first['name'].should == 'start'
-    end
-
-    def test_it_responses_to_html
-      do_request '/api/instance_states', {}, false, { :format => :html }
-      last_response.status.should == 200
-      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
-    end
-
-    def test_it_responses_to_png
-      do_request '/api/instance_states', { :format => 'png' }, false
-      last_response.status.should == 200
-      last_response.headers['Content-Type'].should == 'image/png'
-    end
-
-  end
-end
diff --git a/server/tests/instances_test.rb b/server/tests/instances_test.rb
deleted file mode 100644
index 0af94fd..0000000
--- a/server/tests/instances_test.rb
+++ /dev/null
@@ -1,222 +0,0 @@
-require 'tests/common'
-
-module DeltacloudUnitTest
-  class InstancesTest < Test::Unit::TestCase
-    include Rack::Test::Methods
-
-    def app
-      Sinatra::Application
-    end
-
-    def test_it_require_authentication
-      require_authentication?('/api/instances').should == true
-    end
-
-    def test_it_returns_instances
-      do_xml_request '/api/instances', {}, true
-      (last_xml_response/'instances/instance').to_a.size.should > 0
-    end
-
-    def test_it_has_correct_attributes_set
-      do_xml_request '/api/images', {}, true
-      (last_xml_response/'images/image').each do |image|
-        image.attributes.keys.sort.should == [ 'href', 'id' ]
-      end
-    end
-
-    def test_it_has_unique_ids
-      do_xml_request '/api/instances', {}, true
-      ids = []
-      (last_xml_response/'instances/instance').each do |image|
-        ids << image['id'].to_s
-      end
-      ids.sort.should == ids.sort.uniq
-    end
-
-    def test_inst1_has_correct_attributes
-      do_xml_request '/api/instances', {}, true
-      instance = (last_xml_response/'instances/instan...@id="inst1"]')
-      test_instance_attributes(instance)
-    end
-
-    def test_it_returns_valid_realm
-      do_xml_request '/api/instances/inst1', {}, true
-      instance = (last_xml_response/'instance')
-      test_instance_attributes(instance)
-    end
-
-    def test_it_responses_to_json
-      do_request '/api/instances', {}, true, { :format => :json }
-      JSON::parse(last_response.body).class.should == Hash
-      JSON::parse(last_response.body)['instances'].class.should == Array
-
-      do_request '/api/instances/inst1', {}, true, { :format => :json }
-      last_response.status.should == 200
-      JSON::parse(last_response.body).class.should == Hash
-      JSON::parse(last_response.body)['instance'].class.should == Hash
-    end
-
-    def test_it_responses_to_html
-      do_request '/api/instances', {}, true, { :format => :html }
-      last_response.status.should == 200
-      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
-
-      do_request '/api/instances/inst1', {}, true, { :format => :html }
-      last_response.status.should == 200
-      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
-    end
-
-    def test_it_create_a_new_instance_using_image_id
-      params = {
-        :image_id => 'img1'
-      }
-      header 'Accept', accept_header(:xml)
-      post '/api/instances', params, authenticate
-      last_response.status.should == 201
-      last_response.headers['Location'].should_not == nil
-      do_xml_request last_response.headers['Location'], {}, true
-      (last_xml_response/'instance/name').should_not == nil
-      add_created_instance (last_xml_response/'instance').first['id']
-      test_instance_attributes(last_xml_response/'instance')
-    end
-
-    def test_it_create_a_new_instance_using_image_id_and_name
-      params = {
-        :image_id => 'img1',
-        :name => "unit_test_instance1"
-      }
-      header 'Accept', accept_header(:xml)
-      post '/api/instances', params, authenticate(:format => :xml)
-      last_response.status.should == 201
-      last_response.headers['Location'].should_not == nil
-      do_xml_request last_response.headers['Location'], {}, true
-      (last_xml_response/'instance/name').text.should == 'unit_test_instance1'
-      add_created_instance (last_xml_response/'instance').first['id']
-      test_instance_attributes(last_xml_response/'instance')
-    end
-
-    def test_it_create_a_new_instance_using_image_id_and_name_and_hwp
-      params = {
-        :image_id => 'img1',
-        :name => "unit_test_instance1",
-        :hwp_id => "m1-xlarge"
-      }
-      header 'Accept', accept_header(:xml)
-      post '/api/instances', params, authenticate(:format => :xml)
-      last_response.status.should == 201
-      last_response.headers['Location'].should_not == nil
-      do_xml_request last_response.headers['Location'], {}, true
-      (last_xml_response/'instance/name').text.should == 'unit_test_instance1'
-      (last_xml_response/'instance/hardware_profile').first['id'].should == 
'm1-xlarge'
-      add_created_instance (last_xml_response/'instance').first['id']
-      test_instance_attributes(last_xml_response/'instance')
-    end
-
-    def test_it_z0_stop_and_start_instance
-      $created_instances.each do |instance_id|
-        do_xml_request "/api/instances/#{instance_id}", {}, true
-        stop_url = 
(last_xml_response/'actions/li...@rel="stop"]').first['href']
-        stop_url.should_not == nil
-        post create_url(stop_url), { :format => 'xml' }, authenticate
-        last_response.status.should == 200
-        instance = Nokogiri::XML(last_response.body)
-        test_instance_attributes(instance)
-        (instance/'state').text.should == 'STOPPED'
-        do_xml_request "/api/instances/#{instance_id}", {}, true
-        start_url = 
(last_xml_response/'actions/li...@rel="start"]').first['href']
-        start_url.should_not == nil
-        post create_url(start_url), { :format => 'xml'}, authenticate
-        last_response.status.should == 200
-        instance = Nokogiri::XML(last_response.body)
-        test_instance_attributes(instance)
-        (instance/'state').text.should == 'RUNNING'
-      end
-    end
-
-    def test_z0_reboot_instance
-      $created_instances.each do |instance_id|
-        do_xml_request "/api/instances/#{instance_id}", {}, true
-        reboot_url = 
(last_xml_response/'actions/li...@rel="reboot"]').first['href']
-        reboot_url.should_not == nil
-        post create_url(reboot_url), { :format => "xml"}, authenticate
-        last_response.status.should == 200
-        instance = Nokogiri::XML(last_response.body)
-        test_instance_attributes(instance)
-        (instance/'state').text.should == 'RUNNING'
-      end
-    end
-
-    def test_z1_stop_created_instances
-      $created_instances.each do |instance_id|
-        do_xml_request "/api/instances/#{instance_id}", {}, true
-        stop_url = 
(last_xml_response/'actions/li...@rel="stop"]').first['href']
-        stop_url.should_not == nil
-        post create_url(stop_url), {}, authenticate
-        last_response.status.should == 200
-        instance = Nokogiri::XML(last_response.body)
-        test_instance_attributes(instance)
-        (instance/'state').text.should == 'STOPPED'
-      end
-    end
-
-    def test_z2_destroy_created_instances
-      $created_instances.each do |instance_id|
-        do_xml_request "/api/instances/#{instance_id}", {}, true
-        destroy_url = 
(last_xml_response/'actions/li...@rel="destroy"]').first['href']
-        destroy_url.should_not == nil
-        delete create_url(destroy_url), {}, authenticate
-        last_response.status.should == 302
-        do_xml_request last_response.headers['Location'], {}, true
-        (last_xml_response/'instances').should_not == nil
-        do_xml_request "/api/instances/#{instance_id}", {}, true
-        last_response.status.should == 404
-      end
-    end
-
-    private
-
-    def test_instance_attributes(instance)
-      (instance/'name').should_not == nil
-      (instance/'owner_id').should_not == nil
-      ['RUNNING', 'STOPPED'].include?((instance/'state').text).should == true
-
-      (instance/'public_addreses').should_not == nil
-      (instance/'public_addresses/address').to_a.size.should > 0
-      (instance/'public_addresses/address').first.text.should_not == ""
-
-      (instance/'private_addresses').should_not == nil
-      (instance/'private_addresses/address').to_a.size.should > 0
-      (instance/'private_addresses/address').first.text.should_not == ""
-
-      (instance/'actions/link').to_a.size.should > 0
-      (instance/'actions/link').each do |link|
-        link['href'].should_not == ""
-        link['rel'].should_not == ""
-        link['method'].should_not == ""
-        ['get', 'post', 'delete', 'put'].include?(link['method']).should == 
true
-      end
-
-      (instance/'image').size.should > 0
-      (instance/'image').first['href'].should_not == ""
-      (instance/'image').first['id'].should_not == ""
-      do_xml_request (instance/'image').first['href'], {}, true
-      (last_xml_response/'image').should_not == nil
-      (last_xml_response/'image').first['href'] == 
(instance/'image').first['href']
-
-      (instance/'realm').size.should > 0
-      (instance/'realm').first['href'].should_not == ""
-      (instance/'realm').first['id'].should_not == ""
-      do_xml_request (instance/'realm').first['href']
-      (last_xml_response/'realm').should_not == nil
-      (last_xml_response/'realm').first['href'] == 
(instance/'realm').first['href']
-
-      (instance/'hardware_profile').size.should > 0
-      (instance/'hardware_profile').first['href'].should_not == ""
-      (instance/'hardware_profile').first['id'].should_not == ""
-      do_xml_request (instance/'hardware_profile').first['href']
-      (last_xml_response/'hardware_profile').should_not == nil
-      (last_xml_response/'hardware_profile').first['href'] == 
(instance/'hardware_profile').first['href']
-    end
-
-  end
-end
diff --git a/server/tests/realms_test.rb b/server/tests/realms_test.rb
deleted file mode 100644
index d6161c8..0000000
--- a/server/tests/realms_test.rb
+++ /dev/null
@@ -1,78 +0,0 @@
-require 'tests/common'
-
-module DeltacloudUnitTest
-  class RealmsTest < Test::Unit::TestCase
-    include Rack::Test::Methods
-
-    def app
-      Sinatra::Application
-    end
-
-    def test_it_not_require_authentication
-      require_authentication?('/api/realms').should_not == true
-    end
-
-    def test_it_returns_realms
-      do_xml_request '/api/realms', {}, true
-      (last_xml_response/'realms/realm').to_a.size.should > 0
-    end
-
-    def test_it_has_correct_attributes_set
-      do_xml_request '/api/realms', {}, true
-      (last_xml_response/'realms/realm').each do |realm|
-        realm.attributes.keys.sort.should == [ 'href', 'id' ]
-      end
-    end
-
-    def test_us_has_correct_attributes
-      do_xml_request '/api/realms', {}, true
-      realm = (last_xml_response/'realms/rea...@id="us"]')
-      test_realm_attributes(realm)
-    end
-
-    def test_it_returns_valid_realm
-      do_xml_request '/api/realms/us', {}, true
-      realm = (last_xml_response/'realm')
-      test_realm_attributes(realm)
-    end
-
-    def test_it_has_unique_ids
-      do_xml_request '/api/realms', {}, true
-      ids = []
-      (last_xml_response/'realms/realm').each do |realm|
-        ids << realm['id'].to_s
-      end
-      ids.sort.should == ids.sort.uniq
-    end
-
-    def test_it_responses_to_json
-      do_request '/api/realms', {}, false, { :format => :json }
-      JSON::parse(last_response.body).class.should == Hash
-      JSON::parse(last_response.body)['realms'].class.should == Array
-
-      do_request '/api/realms/us', {}, false, { :format => :json }
-      last_response.status.should == 200
-      JSON::parse(last_response.body).class.should == Hash
-      JSON::parse(last_response.body)['realm'].class.should == Hash
-    end
-
-    def test_it_responses_to_html
-      do_request '/api/realms', {}, false, { :format => :html }
-      last_response.status.should == 200
-      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
-
-      do_request '/api/realms/us', {}, false, { :format => :html }
-      last_response.status.should == 200
-      Nokogiri::HTML(last_response.body).search('html').first.name.should == 
'html'
-    end
-
-    private
-
-    def test_realm_attributes(realm)
-      (realm/'name').should_not == nil
-      (realm/'limit').should_not == nil
-      ['AVAILABLE'].include?((realm/'state').text).should == true
-    end
-
-  end
-end
diff --git a/server/tests/url_for_test.rb b/server/tests/url_for_test.rb
deleted file mode 100644
index 400821d..0000000
--- a/server/tests/url_for_test.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-require 'tests/common'
-
-module DeltacloudUnitTest
-  class UrlForTest < Test::Unit::TestCase
-    include Rack::Test::Methods
-
-    def app
-      Sinatra::Application
-    end
-
-    def test_it_works_for_root
-      verify_url_for("/", "/")
-    end
-
-    def test_it_works_for_root_absolute
-      verify_url_for("/", "http://localhost/";, :full)
-    end
-
-    def test_it_works_with_spaces
-      verify_url_for("/url with spaces", "/url%20with%20spaces")
-    end
-
-    def test_it_works_when_given_absolute
-      verify_url_for("http://test.com";, "http://test.com";)
-    end
-
-    def test_it_works_when_not_at_root_context
-      verify_url_for("/", "context/", :path_only, {}, {"SCRIPT_NAME" => 
"context"})
-    end
-
-    def verify_url_for(url, expected_url, mode=:path_only, params={}, 
rack_env={})
-      # generate a unique url for each test
-      test_url = "/url_for_test/#{expected_url.hash}/#{Time.now.to_i}"
-      # Create our sinatra test endpoint
-      self.class.create_test_url_content(test_url, url, mode)
-
-      # verify the generated url matches what we expect
-      get test_url, params, rack_env
-      last_response.body.should == expected_url
-    end
-
-    def self.create_test_url_content(test_url, url_content, mode)
-      get test_url do
-        content_type "text/plain"
-          url_for(url_content, mode)
-      end
-    end
-
-  end
-end
-- 
1.7.2.3

Reply via email to