From: David Lutterkort <lut...@redhat.com> It is legal to omit subcollections, e.g. in Machine; make sure we process these correctly. --- 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(-) create mode 100644 server/tests/cimi/data/machine-minimal.json create mode 100644 server/tests/cimi/data/machine-minimal.xml
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) 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 +} 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> 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 -- 1.7.7.6