You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by lu...@apache.org on 2012/08/14 23:47:25 UTC
[3/6] git commit: tests: very simple CIMI tests
tests: very simple CIMI tests
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/2ca0a20f
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/2ca0a20f
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/2ca0a20f
Branch: refs/heads/master
Commit: 2ca0a20ff6077850a0b91de4ba346c9cdbb73ed7
Parents: b01a8f5
Author: David Lutterkort <lu...@redhat.com>
Authored: Tue Aug 7 17:53:28 2012 -0700
Committer: David Lutterkort <lu...@redhat.com>
Committed: Tue Aug 14 14:44:18 2012 -0700
----------------------------------------------------------------------
tests/Rakefile | 4 ++
tests/cimi/cep_test.rb | 57 +++++++++++++++++++++
tests/cimi/test_helper.rb | 108 ++++++++++++++++++++++++++++++++++++++++
tests/config.yaml | 6 ++
4 files changed, 175 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2ca0a20f/tests/Rakefile
----------------------------------------------------------------------
diff --git a/tests/Rakefile b/tests/Rakefile
index 88c1966..f276dbb 100644
--- a/tests/Rakefile
+++ b/tests/Rakefile
@@ -30,4 +30,8 @@ namespace :test do
end
end
+ Rake::TestTask.new(:cimi) do |t|
+ t.test_files = FileList["cimi/*_test.rb"]
+ end
+
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2ca0a20f/tests/cimi/cep_test.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/cep_test.rb b/tests/cimi/cep_test.rb
new file mode 100644
index 0000000..647db0c
--- /dev/null
+++ b/tests/cimi/cep_test.rb
@@ -0,0 +1,57 @@
+#
+# 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 "test_helper.rb"
+
+describe "CIMI Entry Point" do
+ include CIMI::Test::Methods
+
+ describe "XML form" do
+ # Cache the response for all assertions
+ res = cep(:accept => :xml)
+
+ it "should set the proper content type" do
+ res.headers[:content_type].must_equal "application/xml"
+ end
+
+ it "should use CloudEntryPoint as the XML root" do
+ res.xml.root.name.must_equal "CloudEntryPoint"
+ names = res.xml.xpath("/c:CloudEntryPoint", api.ns).map { |e| e.name }
+ names.must_equal ["CloudEntryPoint"]
+ end
+
+ it "should have an id equal to the CEP URL" do
+ (res.xml/"CloudEntryPoint/id").text.must_equal api.cep_url
+ end
+
+ end
+
+ describe "JSON form" do
+ # Cache the response for all assertions
+ res = cep(:accept => :json)
+
+ it "should set the proper content type" do
+ res.headers[:content_type].must_equal "application/json"
+ end
+
+ it "should return JSON if asked to" do
+ res.headers[:content_type].must_equal "application/json"
+ res.json["id"].must_equal api.cep_url
+ end
+ end
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2ca0a20f/tests/cimi/test_helper.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
new file mode 100644
index 0000000..f26fa96
--- /dev/null
+++ b/tests/cimi/test_helper.rb
@@ -0,0 +1,108 @@
+#
+# 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.
+
+require 'rubygems'
+require 'require_relative'
+require_relative '../helpers/common.rb'
+
+require 'singleton'
+
+# Add CIMI specific config stuff
+module CIMI
+ module Test
+ class Config
+
+ include Singleton
+
+ def initialize
+ @hash = Deltacloud::Test::yaml_config
+ @cimi = @hash["cimi"]
+ end
+
+ def cep_url
+ @cimi["cep"]
+ end
+
+ def collections
+ xml.xpath("/c:CloudEntryPoint/c:*[@href]", ns).map { |c| c.name }
+ end
+
+ def features
+ {}
+ end
+
+ def ns
+ { "c" => "http://www.dmtf.org/cimi" }
+ end
+
+ private
+ def xml
+ unless @xml
+ @xml = RestClient.get(cep_url, "Accept" => "application/xml").xml
+ end
+ @xml
+ end
+ end
+
+ def self.config
+ Config::instance
+ end
+ end
+end
+
+module CIMI::Test::Methods
+
+ module Global
+ def api
+ CIMI::Test::config
+ end
+
+ def cep(params = {})
+ get(api.cep_url, params)
+ end
+
+ def get(path, params = {})
+ RestClient.get path, headers(params)
+ end
+
+ private
+ def headers(params)
+ headers = {}
+ if params[:accept]
+ headers["Accept"] = "application/#{params.delete(:accept)}" if params[:accept]
+ else #default to xml
+ headers["Accept"] = "application/xml"
+ end
+ headers
+ end
+ end
+
+ module ClassMethods
+ def need_collection(name)
+ before :each do
+ unless api.collections.include?(name.to_sym)
+ skip "Server at #{api.cep_url} doesn't support #{name}"
+ end
+ end
+ end
+ end
+
+ def self.included(base)
+ base.extend ClassMethods
+ base.extend Global
+ base.send(:include, Global)
+ end
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2ca0a20f/tests/config.yaml
----------------------------------------------------------------------
diff --git a/tests/config.yaml b/tests/config.yaml
index d13b814..67892f0 100644
--- a/tests/config.yaml
+++ b/tests/config.yaml
@@ -29,3 +29,9 @@ ec2:
image: "ami-2b5fba42"
hardware_profile: "m1.small"
realm: "us-east-1b"
+
+# CIMI testing
+cimi:
+ cep: "http://localhost:3001/cimi/cloudEntryPoint"
+ user: "mockuser"
+ password: "mockpassword"