Thanks Michael. Did you change public_folder to public before you push this patch or do you like me to create a patch for that? I really do not like to see deprecating warnings. It bothers me a lot. Since it is not supported in earlier Sinatra, we will have to live with that.
Tong Li Emerging Technologies & Standards Building 501/B205 liton...@us.ibm.com From: Michal Fojtik <mfoj...@redhat.com> To: deltacloud-dev@incubator.apache.org Date: 11/01/2011 06:23 AM Subject: Re: [PATCH] cimi unit test cases for collection and individual resources On Oct 31, 2011, at 9:06 PM, email4t...@gmail.com wrote: Awesome! ACK! Thanks for doing this Tong. I'll try to improve the tests later today/tomorrow and add more XML/JSON checking. Just one minor nit below :-) -- Michal > From: Tong Li <liton...@us.ibm.com> > > --- > server/Rakefile | 9 ++ > server/lib/cimi/server.rb | 2 +- > server/tests/cimi/cimi.rb | 3 + > server/tests/cimi/common/cloud_entry_point_test.rb | 92 +++++++++++++++ +++++ > .../cimi/common/machine_configuration_test.rb | 60 +++++++++++++ > server/tests/cimi/common/machine_image_test.rb | 60 +++++++++++++ > server/tests/cimi/common/machine_test.rb | 60 +++++++++++++ > server/tests/cimi/common/volume_test.rb | 60 +++++++++++++ > server/tests/common.rb | 6 +- > 9 files changed, 350 insertions(+), 2 deletions(-) > create mode 100644 server/tests/cimi/cimi.rb > create mode 100644 server/tests/cimi/common/cloud_entry_point_test.rb > create mode 100644 server/tests/cimi/common/machine_configuration_test.rb > create mode 100644 server/tests/cimi/common/machine_image_test.rb > create mode 100644 server/tests/cimi/common/machine_test.rb > create mode 100644 server/tests/cimi/common/volume_test.rb > > diff --git a/server/Rakefile b/server/Rakefile > index 27605d5..f07a6ce 100644 > --- a/server/Rakefile > +++ b/server/Rakefile > @@ -62,6 +62,15 @@ namespace :test do > t.warning = false > } > end > + > + desc "Run CIMI frontend tests" > + Rake::TestTask.new "cimi" do |t| > + t.test_files = ["tests/cimi/cimi.rb", "tests/cimi/common/*_test.rb"] > + t.options = "-v -v" > + t.verbose = true > + t.warning = false > + end > + > end > > desc "Call our Test::Unit suite" > diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb > index 17285bd..cfb77ea 100644 > --- a/server/lib/cimi/server.rb > +++ b/server/lib/cimi/server.rb > @@ -40,7 +40,7 @@ configure do > set :views, File::join($top_srcdir, 'views', 'cimi') > # NOTE: Change :public to :public_folder once we update sinatra to 1.3 > # set :public_folder, File::join($top_srcdir, 'public') > - set :public, File::join($top_srcdir, 'public') > + set :public_folder, File::join($top_srcdir, 'public') Tong, could you please preserve the 'public' directive here instead of 'public_folder'? Thing is that not everyone use the latest Sinatra and this change is not backward compatible. However in Sinatra 1.3.x it just throws a deprecation warning, which we can safely ignore until we update everything for Sinatra 1.3. (See the NOTE above ;-) > # Try to load the driver on startup to fail early if there are issues > driver > set :store, STOREROOT > diff --git a/server/tests/cimi/cimi.rb b/server/tests/cimi/cimi.rb > new file mode 100644 > index 0000000..8d351ad > --- /dev/null > +++ b/server/tests/cimi/cimi.rb > @@ -0,0 +1,3 @@ > +ENV['API_FRONTEND'] = "cimi" > +ENV['API_USER'] = 'mockuser' > +ENV['API_PASSWORD'] = 'mockpassword' > diff --git a/server/tests/cimi/common/cloud_entry_point_test.rb b/server/tests/cimi/common/cloud_entry_point_test.rb > new file mode 100644 > index 0000000..dc7cb36 > --- /dev/null > +++ b/server/tests/cimi/common/cloud_entry_point_test.rb > @@ -0,0 +1,92 @@ > +# 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' > +require 'nokogiri' > + > +module CimiUnitTest > + class CloudEntryPointTest < Test::Unit::TestCase > + include Rack::Test::Methods > + > + def app > + Sinatra::Application > + end > + > + def test_it_redirect_client_to_entrypoint > + get_url '/cimi' > + last_response.status.should == 301 > + last_response.header['Location'].should == 'http://example.org/cimi/cloudEntryPoint' > + end > + > + def test_it_return_valid_content_type > + get_url '/cimi/cloudEntryPoint' > + last_response.content_type.should == 'application/CIMI-CloudEntryPoint+xml;charset=utf-8' > + end > + > + def test_it_return_valid_xmlns > + get_url '/cimi/cloudEntryPoint' > + (last_xml_response/'CloudEntryPoint').first.namespace.href.should == CMWG_NAMESPACE > + end > + > + def test_it_return_valid_root_element > + get_url '/cimi/cloudEntryPoint' > + last_xml_response.root.name == "CloudEntryPoint" > + end > + > + def test_it_include_all_properties > + get_url '/cimi/cloudEntryPoint' > + properties = ['uri', 'name', 'description', 'created', 'volumes', 'machines', 'machineImages', 'machineConfigurations'].sort > + (last_xml_response/'CloudEntryPoint/*').collect { |p| p.name }.sort.should == properties > + end > + > + def test_collection_have_href_attributes > + get_url '/cimi/cloudEntryPoint' > + collections = [ 'volumes', 'machines', 'machineImages', 'machineConfigurations' ] > + (last_xml_response/'CloudEntryPoint/*').each do |collection| > + collection[:href].should_not nil > + end > + end > + > + def test_collection_href_attributes_are_valid > + valid_uris = { > + 'volumes' => 'cimi/volumes', > + 'machines' => 'cimi/machines', > + 'machineImages' => 'cimi/machine_images', > + 'machineConfiguration' => 'cimi/machine_configurations' > + } > + get_url '/cimi/cloudEntryPoint' > + (last_xml_response/'CloudEntryPoint/*').each do |collection| > + next unless valid_uris.keys.include? collection.name > + collection[:href].should =~ /#{valid_uris[collection.name]}$/ > + end > + end > + > + def test_it_respond_to_json > + get_url '/cimi/cloudEntryPoint', {}, :format => :json > + JSON::parse(last_response.body).class.should == Hash > + end > + > + def test_json_include_all_properties > + get_url '/cimi/cloudEntryPoint', {}, :format => :json > + properties = ['uri', 'name', 'description', 'created', 'volumes', 'machines', 'machineImages', 'machineConfigurations'].sort > + properties.each do |property| > + JSON::parse(last_response.body).keys.include?(property).should == true > + end > + end > + > + end > +end > diff --git a/server/tests/cimi/common/machine_configuration_test.rb b/server/tests/cimi/common/machine_configuration_test.rb > new file mode 100644 > index 0000000..c28312f > --- /dev/null > +++ b/server/tests/cimi/common/machine_configuration_test.rb > @@ -0,0 +1,60 @@ > +# 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' > +require 'nokogiri' > + > +module CimiUnitTest > + class MachineConfigurationTest < Test::Unit::TestCase > + include Rack::Test::Methods > + > + def app > + Sinatra::Application > + end > + > + #setup the url to access a machine. this will be used by all the test cases in this class > + def setup > + if @checked.nil? > + get_url '/cimi/cloudEntryPoint' > + configurations = last_xml_response/'CloudEntryPoint/machineConfigurations' > + if configurations > + get_auth_url configurations.attr('href') > + elements = last_xml_response/'MachineConfigurationCollection/machineConfiguration' > + if elements.size > 0 > + @access_url = elements[0].attr('href') > + end > + end > + @checked = true > + end > + end > + > + def test_machine_configuration_read_to_xml > + if @access_url > + get_auth_url @access_url, {}, :format => :xml > + last_response.status.should == 200 > + end > + end > + > + def test_machine_configuration_read_to_json > + if @access_url > + get_auth_url @access_url, {}, :format => :json > + last_response.status.should == 200 > + end > + end > + > + end > +end > diff --git a/server/tests/cimi/common/machine_image_test.rb b/server/tests/cimi/common/machine_image_test.rb > new file mode 100644 > index 0000000..e271449 > --- /dev/null > +++ b/server/tests/cimi/common/machine_image_test.rb > @@ -0,0 +1,60 @@ > +# 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' > +require 'nokogiri' > + > +module CimiUnitTest > + class MachineImageTest < Test::Unit::TestCase > + include Rack::Test::Methods > + > + def app > + Sinatra::Application > + end > + > + #setup the url to access a machine. this will be used by all the test cases in this class > + def setup > + if @checked.nil? > + get_url '/cimi/cloudEntryPoint' > + images = last_xml_response/'CloudEntryPoint/machineImages' > + if images > + get_auth_url images.attr('href') > + elements = last_xml_response/'MachineImageCollection/machineImage' > + if elements.size > 0 > + @access_url = elements[0].attr('href') > + end > + end > + @checked = true > + end > + end > + > + def test_machine_image_read_to_xml > + if @access_url > + get_auth_url @access_url, {}, :format => :xml > + last_response.status.should == 200 > + end > + end > + > + def test_machine_image_read_to_json > + if @access_url > + get_auth_url @access_url, {}, :format => :json > + last_response.status.should == 200 > + end > + end > + > + end > +end > diff --git a/server/tests/cimi/common/machine_test.rb b/server/tests/cimi/common/machine_test.rb > new file mode 100644 > index 0000000..2fda201 > --- /dev/null > +++ b/server/tests/cimi/common/machine_test.rb > @@ -0,0 +1,60 @@ > +# 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' > +require 'nokogiri' > + > +module CimiUnitTest > + class MachineTest < Test::Unit::TestCase > + include Rack::Test::Methods > + > + def app > + Sinatra::Application > + end > + > + #setup the url to access a machine. this will be used by all the test cases in this class > + def setup > + if @checked.nil? > + get_url '/cimi/cloudEntryPoint' > + machines = (last_xml_response/'CloudEntryPoint/machines') > + if machines > + get_auth_url machines.attr('href') > + elements = last_xml_response/'MachineCollection/machine' > + if elements.size > 0 > + @access_url = elements[0].attr('href') > + end > + end > + @checked = true > + end > + end > + > + def test_machine_read_to_xml > + if @access_url > + get_auth_url @access_url, {}, :format => :xml > + last_response.status.should == 200 > + end > + end > + > + def test_machine_read_to_json > + if @access_url > + get_auth_url @access_url, {}, :format => :json > + last_response.status.should == 200 > + end > + end > + > + end > +end > diff --git a/server/tests/cimi/common/volume_test.rb b/server/tests/cimi/common/volume_test.rb > new file mode 100644 > index 0000000..9788309 > --- /dev/null > +++ b/server/tests/cimi/common/volume_test.rb > @@ -0,0 +1,60 @@ > +# 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' > +require 'nokogiri' > + > +module CimiUnitTest > + class VolumeTest < Test::Unit::TestCase > + include Rack::Test::Methods > + > + def app > + Sinatra::Application > + end > + > + #setup the url to access a machine. this will be used by all the test cases in this class > + def setup > + if @checked.nil? > + get_url '/cimi/cloudEntryPoint' > + volumes = (last_xml_response/'CloudEntryPoint/volumes') > + if volumes > + get_auth_url volumes.attr('href') > + elements = last_xml_response/'VolumeCollection/volume' > + if elements.size > 0 > + @access_url = elements[0].attr('href') > + end > + end > + @checked = true > + end > + end > + > + def test_volume_read_to_xml > + if @access_url > + get_auth_url @access_url, {}, :format => :xml > + last_response.status.should == 200 > + end > + end > + > + def test_volume_read_to_json > + if @access_url > + get_auth_url @access_url, {}, :format => :json > + last_response.status.should == 200 > + end > + end > + > + end > +end > diff --git a/server/tests/common.rb b/server/tests/common.rb > index e86f818..a0272ae 100644 > --- a/server/tests/common.rb > +++ b/server/tests/common.rb > @@ -13,6 +13,7 @@ > # License for the specific language governing permissions and limitations > # under the License. > # > +ENV.delete 'API_VERBOSE' > > $:.unshift File.join(File.dirname(__FILE__), '..', 'lib') > $top_srcdir = File::dirname(File::dirname(__FILE__)) > @@ -26,7 +27,10 @@ require 'json' > require 'digest/sha1' > require 'base64' > require 'rack/test' > -require 'deltacloud/server' > + > +server_dir = ENV['API_FRONTEND'] == 'cimi' ? 'cimi' : 'deltacloud' > +load File.join($top_srcdir, 'lib', server_dir, 'server.rb') > + > > driver > > -- > 1.7.4.1 > ------------------------------------------------------ Michal Fojtik, mfoj...@redhat.com Deltacloud API: http://deltacloud.org