deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [9/12] git commit: CIMI: Tests for CIMI validation in MachineTemplate model
Date Fri, 22 Feb 2013 10:32:24 GMT
CIMI: Tests for CIMI validation in MachineTemplate model


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/f0b66965
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/f0b66965
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/f0b66965

Branch: refs/heads/master
Commit: f0b66965047b2b0dbd86df4f7568aa700762af6a
Parents: 73fb6a7
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Thu Feb 7 13:40:37 2013 +0100
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Fri Feb 22 11:32:02 2013 +0100

----------------------------------------------------------------------
 .../cimi/collections/machine_templates_test.rb     |   76 +++++++++++++++
 1 files changed, 76 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/f0b66965/server/tests/cimi/collections/machine_templates_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/cimi/collections/machine_templates_test.rb b/server/tests/cimi/collections/machine_templates_test.rb
new file mode 100644
index 0000000..696052a
--- /dev/null
+++ b/server/tests/cimi/collections/machine_templates_test.rb
@@ -0,0 +1,76 @@
+require 'rubygems'
+require 'require_relative' if RUBY_VERSION < '1.9'
+require 'minitest/autorun'
+require_relative './common.rb'
+
+describe CIMI::Collections::MachineTemplates do
+
+  before do
+    def app; run_frontend(:cimi) end
+    authorize 'mockuser', 'mockpassword'
+    @collection = CIMI::Collections.collection(:machine_images)
+  end
+
+  it 'should return bad request creating template with scrambled JSON' do
+    json_body = '{
+      "resourceURI": "http://schemas.dmtf.org/cimi/1/MachineTemplateCreate",
+      "name": "myMachineDemoTemplate",
+      "description": "My very loved machine template",
+      "machineConfig": { "href": "http://localhost:3001/cimi/machine_configurations/m1-xlarge"
}
+      "machineImage": { "href": "http://localhost:3001/cimi/machine_images/img1" }
+    }'
+    header 'Content-Type', 'application/json'
+    header 'Accept', 'application/json'
+    post root_url('/machine_templates'), json_body
+    status.must_equal 400
+    json['code'].must_equal 400
+    json['message'].must_equal "Bad request (expected ',' or '}' in object at '\"machineImage\":
{ \"h'!)"
+  end
+
+  it 'should return validation error when missing required attribute in JSON' do
+    json_body = '{
+      "resourceURI": "http://schemas.dmtf.org/cimi/1/MachineTemplateCreate",
+      "name": "myMachineDemoTemplate",
+      "description": "My very loved machine template",
+      "machineConfig": { "href": "http://localhost:3001/cimi/machine_configurations/m1-xlarge"
}
+    }'
+    header 'Content-Type', 'application/json'
+    header 'Accept', 'application/json'
+    post root_url('/machine_templates'), json_body
+    status.must_equal 400
+    json['message'].must_equal "Required attributes not set: machineImage"
+    json['error'].must_equal 'CIMI::Model::ValidationError'
+  end
+
+  it 'should return bad request creating template with scrambled XML' do
+    xml_body = '
+      <MachineTemplateCreate>
+        <name>myXmlTestMachineTemplate1</name>
+        <description>Description of my MachineTemplate</description>
+        operty key="test">value</property>
+        <machineConfig href="http://localhost:3001/cimi/machine_configurations/m1-xlarge"/>
+        <machineImage href="http://localhost:3001/cimi/machine_images/img3"/>
+      </MachineTemplateCreate>'
+    header 'Content-Type', 'text/xml'
+    header 'Accept', 'text/xml'
+    post root_url('/machine_templates'), xml_body
+    status.must_equal 400
+    xml.at('/error/message').text.must_equal 'Bad Request'
+  end
+
+  it 'should return validation error when missing required attribute in XML' do
+    xml_body = '
+      <MachineTemplateCreate>
+        <name>myXmlTestMachineTemplate1</name>
+        <description>Description of my MachineTemplate</description>
+        <machineConfig href="http://localhost:3001/cimi/machine_configurations/m1-xlarge"/>
+      </MachineTemplateCreate>'
+    header 'Content-Type', 'text/xml'
+    header 'Accept', 'text/xml'
+    post root_url('/machine_templates'), xml_body
+    status.must_equal 400
+    xml.at('/error/message').text.must_equal "Required attributes not set: machineImage"
+    xml.at('/error/parameter').text.must_equal "machineImage"
+  end
+
+end


Mime
View raw message