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/12/11 04:48:25 UTC

[11/14] git commit: CIMI: tolerate missing subcollections when parsing

CIMI: tolerate missing subcollections when parsing

It is legal to omit subcollections, e.g. in Machine; make sure we process
these correctly.


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

Branch: refs/heads/master
Commit: 614b302b6faf35431ba1bcfe0efe50655930a288
Parents: e6c46db
Author: David Lutterkort <lu...@redhat.com>
Authored: Tue Dec 4 00:34:24 2012 -0800
Committer: David Lutterkort <lu...@redhat.com>
Committed: Mon Dec 10 17:08:48 2012 -0800

----------------------------------------------------------------------
 server/lib/cimi/models/schema.rb            |    8 ++++++--
 server/tests/cimi/data/machine-minimal.json |    7 +++++++
 server/tests/cimi/data/machine-minimal.xml  |    5 +++++
 server/tests/cimi/model/machine_spec.rb     |   17 +++++++++++++++++
 4 files changed, 35 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/614b302b/server/lib/cimi/models/schema.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/schema.rb b/server/lib/cimi/models/schema.rb
index 3d6a097..4e1affb 100644
--- a/server/lib/cimi/models/schema.rb
+++ b/server/lib/cimi/models/schema.rb
@@ -229,11 +229,15 @@ class CIMI::Model::Schema
     end
 
     def from_xml(xml, model)
-      model[name] = @collection_class.schema.from_xml(xml[xml_name].first, {})
+      if xml[xml_name]
+        model[name] = @collection_class.schema.from_xml(xml[xml_name].first, {})
+      end
     end
 
     def from_json(json, model)
-      model[name] = @collection_class.schema.from_json(json[json_name], {})
+      if json[json_name]
+        model[name] = @collection_class.schema.from_json(json[json_name], {})
+      end
     end
 
     def to_xml(model, xml)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/614b302b/server/tests/cimi/data/machine-minimal.json
----------------------------------------------------------------------
diff --git a/server/tests/cimi/data/machine-minimal.json b/server/tests/cimi/data/machine-minimal.json
new file mode 100644
index 0000000..59a7d51
--- /dev/null
+++ b/server/tests/cimi/data/machine-minimal.json
@@ -0,0 +1,7 @@
+{
+ "resourceURI": "http://schemas.dmtf.org/cimi/1/Machine",
+ "id": "http://cimi.example.org/machines/1",
+  "state": "STARTED",
+  "cpu": "4",
+  "memory":12582912
+}

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/614b302b/server/tests/cimi/data/machine-minimal.xml
----------------------------------------------------------------------
diff --git a/server/tests/cimi/data/machine-minimal.xml b/server/tests/cimi/data/machine-minimal.xml
new file mode 100644
index 0000000..ae2f729
--- /dev/null
+++ b/server/tests/cimi/data/machine-minimal.xml
@@ -0,0 +1,5 @@
+<Machine xmlns="http://schemas.dmtf.org/cimi/1">
+  <id>http://cimi.example.org/machines/1</id>
+  <memory>12582912</memory>
+  <state>STARTED</state>
+</Machine>

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/614b302b/server/tests/cimi/model/machine_spec.rb
----------------------------------------------------------------------
diff --git a/server/tests/cimi/model/machine_spec.rb b/server/tests/cimi/model/machine_spec.rb
index aa90cf3..45a02fa 100644
--- a/server/tests/cimi/model/machine_spec.rb
+++ b/server/tests/cimi/model/machine_spec.rb
@@ -23,10 +23,27 @@ describe "Machine model" do
   before do
     @xml = IO::read(File::join(DATA_DIR, "machine.xml"))
     @json = IO::read(File::join(DATA_DIR, "machine.json"))
+    @xml_minimal = IO::read(File::join(DATA_DIR, "machine-minimal.xml"))
+    @json_minimal = IO::read(File::join(DATA_DIR, "machine-minimal.json"))
   end
 
   it "can be constructed from XML and JSON" do
     should_properly_serialize_model CIMI::Model::Machine, @xml, @json
   end
 
+  it "should parse minimal XML machine" do
+    machine = CIMI::Model::Machine.from_xml(@xml_minimal)
+    machine.id.wont_be_nil
+    machine.state.must_equal "STARTED"
+    machine.disks.entries.wont_be_nil
+    machine.disks.entries.size.must_equal 0
+  end
+
+  it "should parse minimal JSON machine" do
+    machine = CIMI::Model::Machine.from_json(@json_minimal)
+    machine.id.wont_be_nil
+    machine.state.must_equal "STARTED"
+    machine.disks.entries.wont_be_nil
+    machine.disks.entries.size.must_equal 0
+  end
 end