deltacloud-core 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/COPYING +176 -502
  2. data/Rakefile +21 -14
  3. data/deltacloud.rb +3 -0
  4. data/lib/deltacloud/base_driver.rb +12 -11
  5. data/lib/deltacloud/base_driver/base_driver.rb +22 -11
  6. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +15 -12
  7. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +16 -11
  8. data/lib/deltacloud/drivers/mock/data/images/img1.yml +3 -0
  9. data/lib/deltacloud/drivers/mock/data/images/img2.yml +3 -0
  10. data/lib/deltacloud/drivers/mock/data/images/img3.yml +3 -0
  11. data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +16 -0
  12. data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +9 -0
  13. data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +9 -0
  14. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap1.yml +4 -0
  15. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap2.yml +4 -0
  16. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap3.yml +4 -0
  17. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol1.yml +6 -0
  18. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol2.yml +6 -0
  19. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol3.yml +6 -0
  20. data/lib/deltacloud/drivers/mock/mock_driver.rb +13 -11
  21. data/lib/deltacloud/drivers/rackspace/rackspace_client.rb +12 -11
  22. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +12 -11
  23. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +12 -11
  24. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +12 -11
  25. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +14 -12
  26. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +12 -11
  27. data/lib/deltacloud/helpers/application_helper.rb +64 -11
  28. data/lib/deltacloud/helpers/conversion_helper.rb +12 -11
  29. data/lib/deltacloud/method_serializer.rb +12 -11
  30. data/lib/deltacloud/models/base_model.rb +12 -11
  31. data/lib/deltacloud/models/image.rb +12 -11
  32. data/lib/deltacloud/models/instance.rb +13 -12
  33. data/lib/deltacloud/models/instance_profile.rb +12 -11
  34. data/lib/deltacloud/models/realm.rb +12 -11
  35. data/lib/deltacloud/models/storage_snapshot.rb +12 -11
  36. data/lib/deltacloud/models/storage_volume.rb +12 -11
  37. data/lib/drivers.rb +12 -0
  38. data/lib/sinatra/rabbit.rb +1 -0
  39. data/lib/sinatra/respond_to.rb +3 -0
  40. data/server.rb +40 -80
  41. data/tests/api_test.rb +37 -0
  42. data/tests/hardware_profiles_test.rb +120 -0
  43. data/tests/images_test.rb +95 -78
  44. data/tests/instance_states_test.rb +52 -0
  45. data/tests/instances_test.rb +193 -110
  46. data/tests/realms_test.rb +66 -44
  47. data/views/errors/not_found.html.haml +6 -0
  48. data/views/errors/not_found.xml.haml +2 -0
  49. data/views/hardware_profiles/index.xml.haml +1 -1
  50. data/views/hardware_profiles/show.xml.haml +3 -2
  51. data/views/images/index.xml.haml +4 -3
  52. data/views/images/show.xml.haml +2 -2
  53. data/views/instances/index.xml.haml +6 -8
  54. data/views/instances/show.xml.haml +9 -10
  55. data/views/realms/index.xml.haml +1 -3
  56. data/views/realms/show.xml.haml +4 -5
  57. data/views/storage_snapshots/index.xml.haml +3 -5
  58. data/views/storage_snapshots/show.xml.haml +2 -4
  59. data/views/storage_volumes/index.xml.haml +7 -7
  60. data/views/storage_volumes/show.xml.haml +2 -4
  61. metadata +156 -81
  62. data/tests/deltacloud_test.rb +0 -60
  63. data/tests/storage_snapshots_test.rb +0 -48
  64. data/tests/storage_volumes_test.rb +0 -48
@@ -0,0 +1,52 @@
1
+ require 'tests/common'
2
+
3
+ module DeltacloudUnitTest
4
+ class RealmsTest < Test::Unit::TestCase
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ Sinatra::Application
9
+ end
10
+
11
+ def test_it_not_require_authentication
12
+ require_authentication?('/api/realms').should_not == true
13
+ end
14
+
15
+ def test_it_returns_instance_states
16
+ do_xml_request '/api/instance_states', {}, true
17
+ (last_xml_response/'states/state').map.size.should > 0
18
+ end
19
+
20
+ def test_each_state_has_transition
21
+ do_xml_request '/api/instance_states', {}, true
22
+ (last_xml_response/'states/state').each do |state|
23
+ next if state['name'].eql?('finish') # Finnish state doesn't have transitions
24
+ (state/'transition').map.size.should > 0
25
+ (state/'transition').each do |transition|
26
+ transition['to'].should_not == nil
27
+ end
28
+ end
29
+ end
30
+
31
+ def test_it_responses_to_json
32
+ do_request '/api/instance_states', {}, false, { :format => :json }
33
+ JSON::parse(last_response.body).class.should == Array
34
+ JSON::parse(last_response.body).first['transitions'].class.should == Array
35
+ JSON::parse(last_response.body).first['name'].should == 'start'
36
+ end
37
+
38
+ def test_it_responses_to_html
39
+ do_request '/api/instance_states', {}, false, { :format => :html }
40
+ last_response.status.should == 200
41
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
42
+ end
43
+
44
+ def test_it_responses_to_png
45
+ do_request '/api/instance_states', {}, false, { :format => :png }
46
+ last_response.status.should == 200
47
+ last_response.headers['Content-Type'].should == 'image/png'
48
+ #last_response.headers['Content-Length'].should == '4371'
49
+ end
50
+
51
+ end
52
+ end
@@ -1,136 +1,219 @@
1
- require 'tests/deltacloud_test'
1
+ require 'tests/common'
2
2
 
3
- class InstancesTest < Test::Unit::TestCase
3
+ module DeltacloudUnitTest
4
+ class InstancesTest < Test::Unit::TestCase
5
+ include Rack::Test::Methods
4
6
 
5
- def initialize(*args)
6
- @collection = 'instances'
7
- @operations = [:index, :show]
8
- @options = [:id, :architecture, :memory, :storage]
9
- @params = {}
10
- self.temp_inst_id = 'inst2'
11
- super(*args)
12
- end
13
-
14
- attr_accessor :temp_inst_id
15
-
16
- def test_if_instances_are_not_empty
17
- get '/api/instances.xml', @params, rack_headers
18
- doc = Nokogiri::XML.parse(last_response.body)
19
- assert_not_equal 0, doc.xpath('/instances/instance').size
20
- end
7
+ def app
8
+ Sinatra::Application
9
+ end
21
10
 
22
- [:id, :name, :owner_id, :image, :realm, :state, :actions, :'public-addresses', :'private-addresses'].each do |option|
23
- method_name = :"test_if_instances_index_contain_#{option}"
24
- send :define_method, method_name do
25
- get '/api/instances.xml', @params, rack_headers
26
- doc = Nokogiri::XML.parse(last_response.body)
27
- instance = doc.xpath('/instances/instance[1]').first
28
- assert_not_nil instance.xpath(option.to_s).first
11
+ def test_it_require_authentication
12
+ require_authentication?('/api/instances').should == true
29
13
  end
30
- end
31
14
 
32
- [:id, :name, :owner_id, :image, :realm, :state, :actions, :'public-addresses', :'private-addresses'].each do |option|
33
- method_name = :"test_if_instance_show_contain_#{option}"
34
- send :define_method, method_name do
35
- get '/api/instances/inst1.xml', @params, rack_headers
36
- doc = Nokogiri::XML.parse(last_response.body)
37
- instance = doc.xpath('/instance').first
38
- assert_not_nil instance.xpath(option.to_s).first
15
+ def test_it_returns_instances
16
+ do_xml_request '/api/instances', {}, true
17
+ (last_xml_response/'instances/instance').map.size.should > 0
39
18
  end
40
- end
41
19
 
42
- def test_instances_filtering_by_id
43
- get '/api/instances.xml', { :id => 'inst1'}, rack_headers
44
- doc = Nokogiri::XML.parse(last_response.body)
45
- assert_equal 1, doc.xpath('/instances/instance').size
46
- assert_equal 'inst1', doc.xpath('/instances/instance/id').first.text
47
- end
20
+ def test_it_has_correct_attributes_set
21
+ do_xml_request '/api/images', {}, true
22
+ (last_xml_response/'images/image').each do |image|
23
+ image.attributes.keys.sort.should == [ 'href', 'id' ]
24
+ end
25
+ end
48
26
 
49
- def test_instances_filtering_by_state
50
- get '/api/instances.xml', { :state => 'RUNNING'}, rack_headers
51
- doc = Nokogiri::XML.parse(last_response.body)
52
- doc.xpath('/instances/instance').each do |instance|
53
- assert_equal 'RUNNING', instance.xpath('state').first.text
27
+ def test_it_has_unique_ids
28
+ do_xml_request '/api/instances', {}, true
29
+ ids = []
30
+ (last_xml_response/'instances/instance').each do |image|
31
+ ids << image['id'].to_s
32
+ end
33
+ ids.sort.should == ids.sort.uniq
54
34
  end
55
- end
56
35
 
57
- def test_instances_filtering_by_unknown_state
58
- get '/api/instances.xml', { :state => '_TEST_UNKNOWN_STATE'}, rack_headers
59
- doc = Nokogiri::XML.parse(last_response.body)
60
- assert_equal 0, doc.xpath('/instances/instance').size
61
- end
36
+ def test_inst1_has_correct_attributes
37
+ do_xml_request '/api/instances', {}, true
38
+ instance = (last_xml_response/'instances/instance[@id="inst1"]')
39
+ test_instance_attributes(instance)
40
+ end
62
41
 
63
- def test_001_create_instance
64
- @params = {
65
- :name => '_test-instance',
66
- :image_id => 'img1'
67
- }
42
+ def test_it_returns_valid_realm
43
+ do_xml_request '/api/instances/inst1', {}, true
44
+ instance = (last_xml_response/'instance')
45
+ test_instance_attributes(instance)
46
+ end
68
47
 
69
- post '/api/instances.xml', @params, rack_headers
70
- doc = Nokogiri::XML.parse(last_response.body)
48
+ def test_it_responses_to_json
49
+ do_request '/api/instances', {}, true, { :format => :json }
50
+ JSON::parse(last_response.body).class.should == Hash
51
+ JSON::parse(last_response.body)['instances'].class.should == Array
71
52
 
72
- self.temp_inst_id = doc.xpath('/instance/id').text
53
+ do_request '/api/instances/inst1', {}, true, { :format => :json }
54
+ last_response.status.should == 200
55
+ JSON::parse(last_response.body).class.should == Hash
56
+ JSON::parse(last_response.body)['instance'].class.should == Hash
57
+ end
73
58
 
74
- assert_equal @params[:name], doc.xpath('/instance/name').first.text
75
- image_href = doc.xpath('/instance/image').first[:href].to_s
76
- image_id = image_href.gsub(/.*\/(\w+)$/, '\1')
77
- assert_equal @params[:image_id], image_id
78
- end
59
+ def test_it_responses_to_html
60
+ do_request '/api/instances', {}, true, { :format => :html }
61
+ last_response.status.should == 200
62
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
79
63
 
80
- def test_create_instance_with_hwp_id
64
+ do_request '/api/instances/inst1', {}, true, { :format => :html }
65
+ last_response.status.should == 200
66
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
67
+ end
81
68
 
82
- @params = {
83
- :name => '_test-instance',
84
- :image_id => 'img1',
85
- :hwp_id => 'm1-xlarge'
86
- }
69
+ def test_it_create_a_new_instance_using_image_id
70
+ params = {
71
+ :image_id => 'img1'
72
+ }
73
+ post '/api/instances', params, authenticate(:format => :xml)
74
+ last_response.status.should == 302
75
+ last_response.headers['Location'].should_not == nil
76
+ do_xml_request last_response.headers['Location'], {}, true
77
+ (last_xml_response/'instance/name').should_not == nil
78
+ add_created_instance (last_xml_response/'instance').first['id']
79
+ test_instance_attributes(last_xml_response/'instance')
80
+ end
87
81
 
88
- post '/api/instances.xml', @params, rack_headers
89
- doc = Nokogiri::XML.parse(last_response.body)
90
- hwp_href = doc.xpath('/instance/hardware_profile').first[:href].to_s
91
- hwp_id = hwp_href.gsub(/.*\/([\w\-]+)$/, '\1')
92
- assert_equal @params[:hwp_id], hwp_id
93
- end
82
+ def test_it_create_a_new_instance_using_image_id_and_name
83
+ params = {
84
+ :image_id => 'img1',
85
+ :name => "unit_test_instance1"
86
+ }
87
+ post '/api/instances', params, authenticate(:format => :xml)
88
+ last_response.status.should == 302
89
+ last_response.headers['Location'].should_not == nil
90
+ do_xml_request last_response.headers['Location'], {}, true
91
+ (last_xml_response/'instance/name').text.should == 'unit_test_instance1'
92
+ add_created_instance (last_xml_response/'instance').first['id']
93
+ test_instance_attributes(last_xml_response/'instance')
94
+ end
94
95
 
95
- def test_create_instance_with_realm_id
96
+ def test_it_create_a_new_instance_using_image_id_and_name_and_hwp
97
+ params = {
98
+ :image_id => 'img1',
99
+ :name => "unit_test_instance1",
100
+ :hwp_id => "m1-xlarge"
101
+ }
102
+ post '/api/instances', params, authenticate(:format => :xml)
103
+ last_response.status.should == 302
104
+ last_response.headers['Location'].should_not == nil
105
+ do_xml_request last_response.headers['Location'], {}, true
106
+ (last_xml_response/'instance/name').text.should == 'unit_test_instance1'
107
+ (last_xml_response/'instance/hardware_profile').first['id'].should == 'm1-xlarge'
108
+ add_created_instance (last_xml_response/'instance').first['id']
109
+ test_instance_attributes(last_xml_response/'instance')
110
+ end
96
111
 
97
- @params = {
98
- :name => '_test-instance',
99
- :image_id => 'img1',
100
- :realm_id => 'us'
101
- }
112
+ def test_it_z0_stop_and_start_instance
113
+ $created_instances.each do |instance_id|
114
+ do_xml_request "/api/instances/#{instance_id}", {}, true
115
+ stop_url = (last_xml_response/'actions/link[@rel="stop"]').first['href']
116
+ stop_url.should_not == nil
117
+ post create_url(stop_url), {}, authenticate(:format => :xml)
118
+ last_response.status.should == 200
119
+ instance = Nokogiri::XML(last_response.body)
120
+ test_instance_attributes(instance)
121
+ (instance/'state').text.should == 'STOPPED'
122
+ do_xml_request "/api/instances/#{instance_id}", {}, true
123
+ start_url = (last_xml_response/'actions/link[@rel="start"]').first['href']
124
+ start_url.should_not == nil
125
+ post create_url(start_url), {}, authenticate(:format => :xml)
126
+ last_response.status.should == 200
127
+ instance = Nokogiri::XML(last_response.body)
128
+ test_instance_attributes(instance)
129
+ (instance/'state').text.should == 'RUNNING'
130
+ end
131
+ end
102
132
 
103
- post '/api/instances.xml', @params, rack_headers
104
- doc = Nokogiri::XML.parse(last_response.body)
105
- realm_href = doc.xpath('/instance/realm').first[:href].to_s
106
- realm_id = realm_href.gsub(/.*\/([\w\-]+)$/, '\1')
107
- assert_equal @params[:realm_id], realm_id
108
- end
133
+ def test_z0_reboot_instance
134
+ $created_instances.each do |instance_id|
135
+ do_xml_request "/api/instances/#{instance_id}", {}, true
136
+ reboot_url = (last_xml_response/'actions/link[@rel="reboot"]').first['href']
137
+ reboot_url.should_not == nil
138
+ post create_url(reboot_url), {}, authenticate(:format => :xml)
139
+ last_response.status.should == 200
140
+ instance = Nokogiri::XML(last_response.body)
141
+ test_instance_attributes(instance)
142
+ (instance/'state').text.should == 'RUNNING'
143
+ end
144
+ end
109
145
 
110
- def test_002_stop_instance
111
- post '/api/instances/'+self.temp_inst_id+'/stop.xml', rack_headers
112
- doc = Nokogiri::XML.parse(last_response.body)
113
- assert_equal 'STOPPED', doc.xpath('/instance/state').first.text
114
- end
146
+ def test_z1_stop_created_instances
147
+ $created_instances.each do |instance_id|
148
+ do_xml_request "/api/instances/#{instance_id}", {}, true
149
+ stop_url = (last_xml_response/'actions/link[@rel="stop"]').first['href']
150
+ stop_url.should_not == nil
151
+ post create_url(stop_url), {}, authenticate(:format => :xml)
152
+ last_response.status.should == 200
153
+ instance = Nokogiri::XML(last_response.body)
154
+ test_instance_attributes(instance)
155
+ (instance/'state').text.should == 'STOPPED'
156
+ end
157
+ end
115
158
 
116
- def test_003_start_instance
117
- post '/api/instances/'+self.temp_inst_id+'/start.xml', rack_headers
118
- doc = Nokogiri::XML.parse(last_response.body)
119
- assert_equal 'RUNNING', doc.xpath('/instance/state').first.text
120
- end
159
+ def test_z2_destroy_created_instances
160
+ $created_instances.each do |instance_id|
161
+ do_xml_request "/api/instances/#{instance_id}", {}, true
162
+ destroy_url = (last_xml_response/'actions/link[@rel="destroy"]').first['href']
163
+ destroy_url.should_not == nil
164
+ delete create_url(destroy_url), {}, authenticate(:format => :xml)
165
+ last_response.status.should == 302
166
+ do_xml_request last_response.headers['Location'], {}, true
167
+ (last_xml_response/'instances').should_not == nil
168
+ do_xml_request "/api/instances/#{instance_id}", {}, true
169
+ last_response.status.should == 404
170
+ end
171
+ end
121
172
 
122
- def test_004_reboot_instance
123
- post '/api/instances/'+self.temp_inst_id+'/reboot.xml', rack_headers
124
- doc = Nokogiri::XML.parse(last_response.body)
125
- assert_equal 'RUNNING', doc.xpath('/instance/state').first.text
126
- end
173
+ private
174
+
175
+ def test_instance_attributes(instance)
176
+ (instance/'name').should_not == nil
177
+ (instance/'owner_id').should_not == nil
178
+ ['RUNNING', 'STOPPED'].include?((instance/'state').text).should == true
179
+
180
+ (instance/'public_addreses').should_not == nil
181
+ (instance/'public_addresses/address').map.size.should > 0
182
+ (instance/'public_addresses/address').first.text.should_not == ""
183
+
184
+ (instance/'private_addresses').should_not == nil
185
+ (instance/'private_addresses/address').map.size.should > 0
186
+ (instance/'private_addresses/address').first.text.should_not == ""
187
+
188
+ (instance/'actions/link').map.size.should > 0
189
+ (instance/'actions/link').each do |link|
190
+ link['href'].should_not == ""
191
+ link['rel'].should_not == ""
192
+ link['method'].should_not == ""
193
+ ['get', 'post', 'delete', 'put'].include?(link['method']).should == true
194
+ end
195
+
196
+ (instance/'image').size.should > 0
197
+ (instance/'image').first['href'].should_not == ""
198
+ (instance/'image').first['id'].should_not == ""
199
+ do_xml_request (instance/'image').first['href'], {}, true
200
+ (last_xml_response/'image').should_not == nil
201
+ (last_xml_response/'image').first['href'] == (instance/'image').first['href']
202
+
203
+ (instance/'realm').size.should > 0
204
+ (instance/'realm').first['href'].should_not == ""
205
+ (instance/'realm').first['id'].should_not == ""
206
+ do_xml_request (instance/'realm').first['href']
207
+ (last_xml_response/'realm').should_not == nil
208
+ (last_xml_response/'realm').first['href'] == (instance/'realm').first['href']
209
+
210
+ (instance/'hardware_profile').size.should > 0
211
+ (instance/'hardware_profile').first['href'].should_not == ""
212
+ (instance/'hardware_profile').first['id'].should_not == ""
213
+ do_xml_request (instance/'hardware_profile').first['href']
214
+ (last_xml_response/'hardware_profile').should_not == nil
215
+ (last_xml_response/'hardware_profile').first['href'] == (instance/'hardware_profile').first['href']
216
+ end
127
217
 
128
- def test_005_destroy_instance
129
- delete '/api/instances/'+self.temp_inst_id+'.xml', {}, rack_headers
130
- doc = Nokogiri::XML.parse(last_response.body)
131
- assert last_response.ok?
132
218
  end
133
-
134
- include DeltacloudTest
135
-
136
219
  end
data/tests/realms_test.rb CHANGED
@@ -1,56 +1,78 @@
1
- require 'tests/deltacloud_test'
1
+ require 'tests/common'
2
2
 
3
- class RealmsTest < Test::Unit::TestCase
3
+ module DeltacloudUnitTest
4
+ class RealmsTest < Test::Unit::TestCase
5
+ include Rack::Test::Methods
4
6
 
5
- def initialize(*args)
6
- @collection = 'realms'
7
- @operations = [:index, :show]
8
- @options = [:id, :name, :state]
9
- @params = {}
10
- super(*args)
11
- end
7
+ def app
8
+ Sinatra::Application
9
+ end
12
10
 
13
- def test_if_realms_are_not_empty
14
- get '/api/realms.xml', @params, rack_headers
15
- doc = Nokogiri::XML.parse(last_response.body)
16
- assert_not_equal 0, doc.xpath('/realms/realm').size
17
- end
11
+ def test_it_not_require_authentication
12
+ require_authentication?('/api/realms').should_not == true
13
+ end
18
14
 
19
- [:id, :name, :state].each do |option|
20
- method_name = :"test_if_realms_index_contain_#{option}"
21
- send :define_method, method_name do
22
- get '/api/realms.xml', @params, rack_headers
23
- doc = Nokogiri::XML.parse(last_response.body)
24
- realm = doc.xpath('/realms/realm[1]').first
25
- assert_not_nil realm.xpath(option.to_s).first
15
+ def test_it_returns_realms
16
+ do_xml_request '/api/realms', {}, true
17
+ (last_xml_response/'realms/realm').map.size.should > 0
26
18
  end
27
- end
28
19
 
29
- [:id, :name, :state].each do |option|
30
- method_name = :"test_if_realm_show_contain_#{option}"
31
- send :define_method, method_name do
32
- get '/api/realms/us.xml', @params, rack_headers
33
- doc = Nokogiri::XML.parse(last_response.body)
34
- realm = doc.xpath('/realm').first
35
- assert_not_nil realm.xpath(option.to_s).first
20
+ def test_it_has_correct_attributes_set
21
+ do_xml_request '/api/realms', {}, true
22
+ (last_xml_response/'realms/realm').each do |realm|
23
+ realm.attributes.keys.sort.should == [ 'href', 'id' ]
24
+ end
36
25
  end
37
- end
38
26
 
39
- def test_realms_filtering_by_state
40
- @params[:state] = 'AVAILABLE'
41
- get '/api/realms.xml', @params, rack_headers
42
- doc = Nokogiri::XML.parse(last_response.body)
43
- assert_equal 2, doc.xpath('/realms/realm').size
44
- assert_equal @params[:state], doc.xpath('/realms/realm/state').first.text
45
- end
27
+ def test_us_has_correct_attributes
28
+ do_xml_request '/api/realms', {}, true
29
+ realm = (last_xml_response/'realms/realm[@id="us"]')
30
+ test_realm_attributes(realm)
31
+ end
46
32
 
47
- def test_realms_filtering_by_id
48
- get '/api/realms.xml', { :id => 'us'}, rack_headers
49
- doc = Nokogiri::XML.parse(last_response.body)
50
- assert_equal 1, doc.xpath('/realms/realm').size
51
- assert_equal 'us', doc.xpath('/realms/realm/id').first.text
52
- end
33
+ def test_it_returns_valid_realm
34
+ do_xml_request '/api/realms/us', {}, true
35
+ realm = (last_xml_response/'realm')
36
+ test_realm_attributes(realm)
37
+ end
53
38
 
54
- include DeltacloudTest
39
+ def test_it_has_unique_ids
40
+ do_xml_request '/api/realms', {}, true
41
+ ids = []
42
+ (last_xml_response/'realms/realm').each do |realm|
43
+ ids << realm['id'].to_s
44
+ end
45
+ ids.sort.should == ids.sort.uniq
46
+ end
55
47
 
48
+ def test_it_responses_to_json
49
+ do_request '/api/realms', {}, false, { :format => :json }
50
+ JSON::parse(last_response.body).class.should == Hash
51
+ JSON::parse(last_response.body)['realms'].class.should == Array
52
+
53
+ do_request '/api/realms/us', {}, false, { :format => :json }
54
+ last_response.status.should == 200
55
+ JSON::parse(last_response.body).class.should == Hash
56
+ JSON::parse(last_response.body)['realm'].class.should == Hash
57
+ end
58
+
59
+ def test_it_responses_to_html
60
+ do_request '/api/realms', {}, false, { :format => :html }
61
+ last_response.status.should == 200
62
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
63
+
64
+ do_request '/api/realms/us', {}, false, { :format => :html }
65
+ last_response.status.should == 200
66
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
67
+ end
68
+
69
+ private
70
+
71
+ def test_realm_attributes(realm)
72
+ (realm/'name').should_not == nil
73
+ (realm/'limit').should_not == nil
74
+ ['AVAILABLE'].include?((realm/'state').text).should == true
75
+ end
76
+
77
+ end
56
78
  end