You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2012/05/22 22:19:37 UTC
[38/50] [abbrv] Core: Replaced Test/Unit based tests for Mock with
new minitest
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6c4efc42/server/tests/drivers/mock/realms_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/mock/realms_test.rb b/server/tests/drivers/mock/realms_test.rb
index b0db9e4..6bc9101 100644
--- a/server/tests/drivers/mock/realms_test.rb
+++ b/server/tests/drivers/mock/realms_test.rb
@@ -1,89 +1,129 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership. The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-#
-
-$:.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
+describe 'Deltacloud API Realms' do
+ include Deltacloud::Test
- def test_it_returns_realms
- get_auth_url '/api/realms', {}
- (last_xml_response/'realms/realm').length.should > 0
- end
+ it 'must advertise have the realms collection in API entrypoint' do
+ get API_ROOT_URL
+ (xml_response/'api/link[@rel=realms]').wont_be_empty
+ end
+
+ it 'must require authentication to access the "realm" collection' do
+ get collection_url(:realms)
+ last_response.status.must_equal 401
+ end
+
+ it 'should respond with HTTP_OK when accessing the :realms collection with authentication' do
+ auth_as_mock
+ get collection_url(:realms)
+ last_response.status.must_equal 200
+ end
+
+ it 'should support the JSON media type' do
+ auth_as_mock
+ header 'Accept', 'application/json'
+ get collection_url(:realms)
+ last_response.status.must_equal 200
+ last_response.headers['Content-Type'].must_equal 'application/json'
+ end
+
+ it 'must include the ETag in HTTP headers' do
+ auth_as_mock
+ get collection_url(:realms)
+ last_response.headers['ETag'].wont_be_nil
+ end
+
+ it 'must have the "realms" element on top level' do
+ auth_as_mock
+ get collection_url(:realms)
+ xml_response.root.name.must_equal 'realms'
+ end
+
+ it 'must have some "realm" elements inside "realms"' do
+ auth_as_mock
+ get collection_url(:realms)
+ (xml_response/'realms/realm').wont_be_empty
+ end
- def test_it_has_correct_attributes_set
- get_auth_url '/api/realms', {}
- (last_xml_response/'realms/realm').each do |realm|
- realm.attributes.keys.sort.should == [ 'href', 'id' ]
- end
+ it 'must provide the :id attribute for each realm in collection' do
+ auth_as_mock
+ get collection_url(:realms)
+ (xml_response/'realms/realm').each do |r|
+ r[:id].wont_be_nil
end
+ end
- def test_us_has_correct_attributes
- get_auth_url '/api/realms', {}
- realm = (last_xml_response/'realms/realm[@id="us"]')
- test_realm_attributes(realm)
+ it 'must include the :href attribute for each "realm" element in collection' do
+ auth_as_mock
+ get collection_url(:realms)
+ (xml_response/'realms/realm').each do |r|
+ r[:href].wont_be_nil
end
+ end
- def test_it_returns_valid_realm
- get_auth_url '/api/realms/us', {}
- realm = (last_xml_response/'realm')
- test_realm_attributes(realm)
+ it 'must use the absolute URL in each :href attribute' do
+ auth_as_mock
+ get collection_url(:realms)
+ (xml_response/'realms/realm').each do |r|
+ r[:href].must_match /^http/
end
+ end
- def test_it_has_unique_ids
- get_auth_url '/api/realms', {}
- ids = []
- (last_xml_response/'realms/realm').each do |realm|
- ids << realm['id'].to_s
- end
- ids.sort.should == ids.sort.uniq
+ it 'must have the URL ending with the :id of the realm' do
+ auth_as_mock
+ get collection_url(:realms)
+ (xml_response/'realms/realm').each do |r|
+ r[:href].must_match /#{r[:id]}$/
end
+ end
+
+ it 'must return the list of valid parameters for the :index action' do
+ auth_as_mock
+ options collection_url(:realms) + '/index'
+ last_response.headers['Allow'].wont_be_nil
+ end
- def test_it_responses_to_json
- get_auth_url '/api/realms', {}, { :format => :json }
- JSON::parse(last_response.body).class.should == Hash
- JSON::parse(last_response.body)['realms'].class.should == Array
- get_auth_url '/api/realms/us', {}, { :format => :json }
- last_response.status.should == 200
- JSON::parse(last_response.body).class.should == Hash
- JSON::parse(last_response.body)['realm'].class.should == Hash
+ it 'must have the "name" element defined for each realm in collection' do
+ auth_as_mock
+ get collection_url(:realms)
+ (xml_response/'realms/realm').each do |r|
+ (r/'name').wont_be_empty
end
+ end
- def test_it_responses_to_html
- get_auth_url '/api/realms', {}, { :format => :html }
- last_response.status.should == 200
- Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
- get_auth_url '/api/realms/us', {}, { :format => :html }
- last_response.status.should == 200
- Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
+ it 'must have the "state" element defined for each realm in collection' do
+ auth_as_mock
+ get collection_url(:realms)
+ (xml_response/'realms/realm').each do |r|
+ (r/'state').wont_be_empty
end
+ end
- private
+ it 'must return the full "realm" when following the URL in realm element' do
+ auth_as_mock
+ get collection_url(:realms)
+ (xml_response/'realms/realm').each do |r|
+ get collection_url(:realms) + '/' + r[:id]
+ last_response.status.must_equal 200
+ end
+ end
- def test_realm_attributes(realm)
- (realm/'name').should_not == nil
- (realm/'limit').should_not == nil
- ['AVAILABLE'].include?((realm/'state').text).should == true
+ it 'must have the "name" element for the realm and it should match with the one in collection' do
+ auth_as_mock
+ get collection_url(:realms)
+ (xml_response/'realms/realm').each do |r|
+ get collection_url(:realms) + '/' + r[:id]
+ (xml_response/'name').wont_be_empty
+ (xml_response/'name').first.text.must_equal((r/'name').first.text)
end
+ end
+ it 'must have the "state" element for the realm and it should match with the one in collection' do
+ auth_as_mock
+ get collection_url(:realms)
+ (xml_response/'realms/realm').each do |r|
+ get collection_url(:realms) + '/' + r[:id]
+ (xml_response/'state').wont_be_empty
+ (xml_response/'state').first.text.must_equal((r/'state').first.text)
+ end
end
+
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6c4efc42/server/tests/drivers/mock/setup.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/mock/setup.rb b/server/tests/drivers/mock/setup.rb
deleted file mode 100644
index 60a7094..0000000
--- a/server/tests/drivers/mock/setup.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-ENV['API_DRIVER'] = "mock"
-ENV['API_USER'] = 'mockuser'
-ENV['API_PASSWORD'] = 'mockpassword'
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6c4efc42/server/tests/drivers/mock/storage_snapshots_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/mock/storage_snapshots_test.rb b/server/tests/drivers/mock/storage_snapshots_test.rb
new file mode 100644
index 0000000..52ea847
--- /dev/null
+++ b/server/tests/drivers/mock/storage_snapshots_test.rb
@@ -0,0 +1,111 @@
+describe 'Deltacloud API storage_snapshots' do
+ include Deltacloud::Test
+
+ it 'must advertise have the storage_snapshots collection in API entrypoint' do
+ get API_ROOT_URL
+ (xml_response/'api/link[@rel=storage_snapshots]').wont_be_empty
+ end
+
+ it 'must require authentication to access the "storage_snapshot" collection' do
+ get collection_url(:storage_snapshots)
+ last_response.status.must_equal 401
+ end
+
+ it 'should respond with HTTP_OK when accessing the :storage_snapshots collection with authentication' do
+ auth_as_mock
+ get collection_url(:storage_snapshots)
+ last_response.status.must_equal 200
+ end
+
+ it 'should support the JSON media type' do
+ auth_as_mock
+ header 'Accept', 'application/json'
+ get collection_url(:storage_snapshots)
+ last_response.status.must_equal 200
+ last_response.headers['Content-Type'].must_equal 'application/json'
+ end
+
+ it 'must include the ETag in HTTP headers' do
+ auth_as_mock
+ get collection_url(:storage_snapshots)
+ last_response.headers['ETag'].wont_be_nil
+ end
+
+ it 'must have the "storage_snapshots" element on top level' do
+ auth_as_mock
+ get collection_url(:storage_snapshots)
+ xml_response.root.name.must_equal 'storage_snapshots'
+ end
+
+ it 'must have some "storage_snapshot" elements inside "storage_snapshots"' do
+ auth_as_mock
+ get collection_url(:storage_snapshots)
+ (xml_response/'storage_snapshots/storage_snapshot').wont_be_empty
+ end
+
+ it 'must provide the :id attribute for each storage_snapshot in collection' do
+ auth_as_mock
+ get collection_url(:storage_snapshots)
+ (xml_response/'storage_snapshots/storage_snapshot').each do |r|
+ r[:id].wont_be_nil
+ end
+ end
+
+ it 'must include the :href attribute for each "storage_snapshot" element in collection' do
+ auth_as_mock
+ get collection_url(:storage_snapshots)
+ (xml_response/'storage_snapshots/storage_snapshot').each do |r|
+ r[:href].wont_be_nil
+ end
+ end
+
+ it 'must use the absolute URL in each :href attribute' do
+ auth_as_mock
+ get collection_url(:storage_snapshots)
+ (xml_response/'storage_snapshots/storage_snapshot').each do |r|
+ r[:href].must_match /^http/
+ end
+ end
+
+ it 'must have the URL ending with the :id of the storage_snapshot' do
+ auth_as_mock
+ get collection_url(:storage_snapshots)
+ (xml_response/'storage_snapshots/storage_snapshot').each do |r|
+ r[:href].must_match /#{r[:id]}$/
+ end
+ end
+
+ it 'must return the list of valid parameters for the :index action' do
+ auth_as_mock
+ options collection_url(:storage_snapshots) + '/index'
+ last_response.headers['Allow'].wont_be_nil
+ end
+
+ it 'must have the "name" element defined for each storage_snapshot in collection' do
+ auth_as_mock
+ get collection_url(:storage_snapshots)
+ (xml_response/'storage_snapshots/storage_snapshot').each do |r|
+ (r/'name').wont_be_empty
+ end
+ end
+
+ it 'must return the full "storage_snapshot" when following the URL in storage_snapshot element' do
+ auth_as_mock
+ get collection_url(:storage_snapshots)
+ (xml_response/'storage_snapshots/storage_snapshot').each do |r|
+ get collection_url(:storage_snapshots) + '/' + r[:id]
+ last_response.status.must_equal 200
+ end
+ end
+
+ it 'must have the "name" element for the storage_snapshot and it should match with the one in collection' do
+ auth_as_mock
+ get collection_url(:storage_snapshots)
+ (xml_response/'storage_snapshots/storage_snapshot').each do |r|
+ get collection_url(:storage_snapshots) + '/' + r[:id]
+ (xml_response/'name').wont_be_empty
+ (xml_response/'name').first.text.must_equal((r/'name').first.text)
+ end
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6c4efc42/server/tests/drivers/mock/storage_volumes_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/mock/storage_volumes_test.rb b/server/tests/drivers/mock/storage_volumes_test.rb
new file mode 100644
index 0000000..cbafd5d
--- /dev/null
+++ b/server/tests/drivers/mock/storage_volumes_test.rb
@@ -0,0 +1,119 @@
+describe 'Deltacloud API storage_volumes' do
+ include Deltacloud::Test
+
+ it 'must advertise have the storage_volumes collection in API entrypoint' do
+ get API_ROOT_URL
+ (xml_response/'api/link[@rel=storage_volumes]').wont_be_empty
+ end
+
+ it 'must require authentication to access the "storage_volume" collection' do
+ get collection_url(:storage_volumes)
+ last_response.status.must_equal 401
+ end
+
+ it 'should respond with HTTP_OK when accessing the :storage_volumes collection with authentication' do
+ auth_as_mock
+ get collection_url(:storage_volumes)
+ last_response.status.must_equal 200
+ end
+
+ it 'should support the JSON media type' do
+ auth_as_mock
+ header 'Accept', 'application/json'
+ get collection_url(:storage_volumes)
+ last_response.status.must_equal 200
+ last_response.headers['Content-Type'].must_equal 'application/json'
+ end
+
+ it 'must include the ETag in HTTP headers' do
+ auth_as_mock
+ get collection_url(:storage_volumes)
+ last_response.headers['ETag'].wont_be_nil
+ end
+
+ it 'must have the "storage_volumes" element on top level' do
+ auth_as_mock
+ get collection_url(:storage_volumes)
+ xml_response.root.name.must_equal 'storage_volumes'
+ end
+
+ it 'must have some "storage_volume" elements inside "storage_volumes"' do
+ auth_as_mock
+ get collection_url(:storage_volumes)
+ (xml_response/'storage_volumes/storage_volume').wont_be_empty
+ end
+
+ it 'must provide the :id attribute for each storage_volume in collection' do
+ auth_as_mock
+ get collection_url(:storage_volumes)
+ (xml_response/'storage_volumes/storage_volume').each do |r|
+ r[:id].wont_be_nil
+ end
+ end
+
+ it 'must include the :href attribute for each "storage_volume" element in collection' do
+ auth_as_mock
+ get collection_url(:storage_volumes)
+ (xml_response/'storage_volumes/storage_volume').each do |r|
+ r[:href].wont_be_nil
+ end
+ end
+
+ it 'must use the absolute URL in each :href attribute' do
+ auth_as_mock
+ get collection_url(:storage_volumes)
+ (xml_response/'storage_volumes/storage_volume').each do |r|
+ r[:href].must_match /^http/
+ end
+ end
+
+ it 'must have the URL ending with the :id of the storage_volume' do
+ auth_as_mock
+ get collection_url(:storage_volumes)
+ (xml_response/'storage_volumes/storage_volume').each do |r|
+ r[:href].must_match /#{r[:id]}$/
+ end
+ end
+
+ it 'must return the list of valid parameters for the :index action' do
+ auth_as_mock
+ options collection_url(:storage_volumes) + '/index'
+ last_response.headers['Allow'].wont_be_nil
+ end
+
+ it 'must have the "name" element defined for each storage_volume in collection' do
+ auth_as_mock
+ get collection_url(:storage_volumes)
+ (xml_response/'storage_volumes/storage_volume').each do |r|
+ (r/'name').wont_be_empty
+ end
+ end
+
+ it 'must have the "state" element defined for each storage_volume in collection' do
+ auth_as_mock
+ get collection_url(:storage_volumes)
+ (xml_response/'storage_volumes/storage_volume').each do |r|
+ (r/'state').wont_be_empty
+ end
+ end
+
+ it 'must return the full "storage_volume" when following the URL in storage_volume element' do
+ auth_as_mock
+ get collection_url(:storage_volumes)
+ (xml_response/'storage_volumes/storage_volume').each do |r|
+ get collection_url(:storage_volumes) + '/' + r[:id]
+ last_response.status.must_equal 200
+ end
+ end
+
+ it 'must have the "name" element for the storage_volume and it should match with the one in collection' do
+ auth_as_mock
+ get collection_url(:storage_volumes)
+ (xml_response/'storage_volumes/storage_volume').each do |r|
+ get collection_url(:storage_volumes) + '/' + r[:id]
+ (xml_response/'name').wont_be_empty
+ (xml_response/'name').first.text.must_equal((r/'name').first.text)
+ end
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6c4efc42/server/tests/drivers/mock/url_for_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/mock/url_for_test.rb b/server/tests/drivers/mock/url_for_test.rb
deleted file mode 100644
index ccd4ebf..0000000
--- a/server/tests/drivers/mock/url_for_test.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership. The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-#
-
-$:.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://example.org/", :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