deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1195915 - in /incubator/deltacloud/trunk/server: ./ lib/cimi/ tests/ tests/cimi/ tests/cimi/common/
Date Tue, 01 Nov 2011 10:25:53 GMT
Author: mfojtik
Date: Tue Nov  1 10:25:52 2011
New Revision: 1195915

URL: http://svn.apache.org/viewvc?rev=1195915&view=rev
Log:
CIMI: Unit test cases for collection and individual resources

Added:
    incubator/deltacloud/trunk/server/tests/cimi/
    incubator/deltacloud/trunk/server/tests/cimi/cimi.rb   (with props)
    incubator/deltacloud/trunk/server/tests/cimi/common/
    incubator/deltacloud/trunk/server/tests/cimi/common/cloud_entry_point_test.rb   (with
props)
    incubator/deltacloud/trunk/server/tests/cimi/common/machine_configuration_test.rb   (with
props)
    incubator/deltacloud/trunk/server/tests/cimi/common/machine_image_test.rb   (with props)
    incubator/deltacloud/trunk/server/tests/cimi/common/machine_test.rb   (with props)
    incubator/deltacloud/trunk/server/tests/cimi/common/volume_test.rb   (with props)
Modified:
    incubator/deltacloud/trunk/server/Rakefile
    incubator/deltacloud/trunk/server/lib/cimi/server.rb
    incubator/deltacloud/trunk/server/tests/common.rb

Modified: incubator/deltacloud/trunk/server/Rakefile
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/Rakefile?rev=1195915&r1=1195914&r2=1195915&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/Rakefile (original)
+++ incubator/deltacloud/trunk/server/Rakefile Tue Nov  1 10:25:52 2011
@@ -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"

Modified: incubator/deltacloud/trunk/server/lib/cimi/server.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/cimi/server.rb?rev=1195915&r1=1195914&r2=1195915&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/cimi/server.rb (original)
+++ incubator/deltacloud/trunk/server/lib/cimi/server.rb Tue Nov  1 10:25:52 2011
@@ -37,7 +37,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')
   # Try to load the driver on startup to fail early if there are issues
   driver
   set :store, STOREROOT

Added: incubator/deltacloud/trunk/server/tests/cimi/cimi.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/tests/cimi/cimi.rb?rev=1195915&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/tests/cimi/cimi.rb (added)
+++ incubator/deltacloud/trunk/server/tests/cimi/cimi.rb Tue Nov  1 10:25:52 2011
@@ -0,0 +1,3 @@
+ENV['API_FRONTEND'] = "cimi"
+ENV['API_USER'] = 'mockuser'
+ENV['API_PASSWORD'] = 'mockpassword'

Propchange: incubator/deltacloud/trunk/server/tests/cimi/cimi.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/deltacloud/trunk/server/tests/cimi/common/cloud_entry_point_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/tests/cimi/common/cloud_entry_point_test.rb?rev=1195915&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/tests/cimi/common/cloud_entry_point_test.rb (added)
+++ incubator/deltacloud/trunk/server/tests/cimi/common/cloud_entry_point_test.rb Tue Nov
 1 10:25:52 2011
@@ -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

Propchange: incubator/deltacloud/trunk/server/tests/cimi/common/cloud_entry_point_test.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/deltacloud/trunk/server/tests/cimi/common/machine_configuration_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/tests/cimi/common/machine_configuration_test.rb?rev=1195915&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/tests/cimi/common/machine_configuration_test.rb (added)
+++ incubator/deltacloud/trunk/server/tests/cimi/common/machine_configuration_test.rb Tue
Nov  1 10:25:52 2011
@@ -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

Propchange: incubator/deltacloud/trunk/server/tests/cimi/common/machine_configuration_test.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/deltacloud/trunk/server/tests/cimi/common/machine_image_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/tests/cimi/common/machine_image_test.rb?rev=1195915&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/tests/cimi/common/machine_image_test.rb (added)
+++ incubator/deltacloud/trunk/server/tests/cimi/common/machine_image_test.rb Tue Nov  1 10:25:52
2011
@@ -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

Propchange: incubator/deltacloud/trunk/server/tests/cimi/common/machine_image_test.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/deltacloud/trunk/server/tests/cimi/common/machine_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/tests/cimi/common/machine_test.rb?rev=1195915&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/tests/cimi/common/machine_test.rb (added)
+++ incubator/deltacloud/trunk/server/tests/cimi/common/machine_test.rb Tue Nov  1 10:25:52
2011
@@ -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

Propchange: incubator/deltacloud/trunk/server/tests/cimi/common/machine_test.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/deltacloud/trunk/server/tests/cimi/common/volume_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/tests/cimi/common/volume_test.rb?rev=1195915&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/tests/cimi/common/volume_test.rb (added)
+++ incubator/deltacloud/trunk/server/tests/cimi/common/volume_test.rb Tue Nov  1 10:25:52
2011
@@ -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

Propchange: incubator/deltacloud/trunk/server/tests/cimi/common/volume_test.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/deltacloud/trunk/server/tests/common.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/tests/common.rb?rev=1195915&r1=1195914&r2=1195915&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/tests/common.rb (original)
+++ incubator/deltacloud/trunk/server/tests/common.rb Tue Nov  1 10:25:52 2011
@@ -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
 



Mime
View raw message