deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@redhat.com
Subject [PATCH 3/3] Common API (black box) collections tests for CIMI collections
Date Mon, 05 Nov 2012 15:12:37 GMT
From: marios <marios@redhat.com>


Signed-off-by: marios <marios@redhat.com>
---
 tests/cimi/common_tests_cimi_collections.rb | 94 +++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)
 create mode 100644 tests/cimi/common_tests_cimi_collections.rb

diff --git a/tests/cimi/common_tests_cimi_collections.rb b/tests/cimi/common_tests_cimi_collections.rb
new file mode 100644
index 0000000..db8b927
--- /dev/null
+++ b/tests/cimi/common_tests_cimi_collections.rb
@@ -0,0 +1,94 @@
+#
+# Licensee 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.
+
+module CommonCIMICollectionsTest
+
+  #tests for only the collection, i.e. for 'Networks' but
+  #not for each 'Network' element
+  def self.run_collection_tests_for(test_collection)
+    describe "CIMI common tests for #{test_collection.camelize.singularize} Collection" do
+
+      it "should respond with HTTP_OK when accessing the #{test_collection} collection with
authentication" do
+        res = get(test_collection)
+        res.code.must_equal 200
+      end
+
+      it 'should support the JSON media type' do
+        res = get(test_collection, :accept=>:json)
+        res.code.must_equal 200
+        res.headers[:content_type].must_equal 'application/json'
+        assert_silent {JSON.parse(res)}
+      end
+
+      it "must require authentication to access the #{test_collection} collection" do
+        proc {  get(test_collection, :noauth => true) }.must_raise RestClient::Request::Unauthorized
+      end
+
+      it "must have the #{test_collection.camelize.singularize} Collection element on top
level" do
+        res = get(test_collection)
+        res.xml.root.name.must_equal "Collection"
+      end
+
+      it "must have the \"id\" and \"count\" attributes for the #{test_collection.camelize.singularize}
Collection" do
+        res = get(test_collection)
+        res.xml.at_xpath("/xmlns:Collection/xmlns:count").text.wont_be_empty
+        res.xml.at_xpath("/xmlns:Collection/xmlns:id").text.wont_be_empty
+      end
+
+    end
+  end
+
+  #run tests for both collection and it's members
+  def self.run_collection_and_member_tests_for(test_collection)
+    #first run only  collection tests (e.g. for 'Networks' collection)
+    run_collection_tests_for(test_collection)
+
+    #now for each member of collection (.e.g. each 'Network' in 'Networks' Collection)
+    describe "common tests for MEMBERS of #{test_collection.camelize.singularize} Collection"
do
+
+      it "must have some #{test_collection.singularize} elements inside #{test_collection}
" do
+        res = get(test_collection)
+        res.xml.xpath("//xmlns:Collection/xmlns:#{test_collection.camelize.singularize}").wont_be_empty
+      end
+
+      it "must provide the :id attribute for each #{test_collection.singularize} in collection"
do
+        res = get(test_collection)
+        each_collection_member(test_collection) do |member|
+          (member/'id').wont_be_empty
+        end
+      end
+
+      it "must provide the :name attribute for each #{test_collection.singularize} in collection"
do
+        res = get(test_collection)
+        each_collection_member(test_collection) do |member|
+          (member/'name').wont_be_empty
+        end
+      end
+
+      it "must return 200 OK when following the :id for each #{test_collection.singularize}
element" do
+        res = get(test_collection)
+        each_collection_member(test_collection) do |member|
+          element_res = get((member/'id').text)
+          element_res.code.must_equal 200
+        end
+      end
+
+    end
+  end
+end
+
+
+
-- 
1.7.11.7


Mime
View raw message