deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1205812 - in /deltacloud/trunk/server/spec: ./ cimi/model/
Date Thu, 24 Nov 2011 13:18:50 GMT
Author: mfojtik
Date: Thu Nov 24 13:18:49 2011
New Revision: 1205812

URL: http://svn.apache.org/viewvc?rev=1205812&view=rev
Log:
CIMI: Added 'should_properly_serialize_model' helper to RSpec tests

Modified:
    deltacloud/trunk/server/spec/cimi/model/machine_admin_spec.rb
    deltacloud/trunk/server/spec/cimi/model/machine_configuration_spec.rb
    deltacloud/trunk/server/spec/cimi/model/machine_image_spec.rb
    deltacloud/trunk/server/spec/cimi/model/machine_spec.rb
    deltacloud/trunk/server/spec/cimi/model/machine_template_spec.rb
    deltacloud/trunk/server/spec/cimi/model/volume_spec.rb
    deltacloud/trunk/server/spec/spec_helper.rb

Modified: deltacloud/trunk/server/spec/cimi/model/machine_admin_spec.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/spec/cimi/model/machine_admin_spec.rb?rev=1205812&r1=1205811&r2=1205812&view=diff
==============================================================================
--- deltacloud/trunk/server/spec/cimi/model/machine_admin_spec.rb (original)
+++ deltacloud/trunk/server/spec/cimi/model/machine_admin_spec.rb Thu Nov 24 13:18:49 2011
@@ -21,18 +21,8 @@ describe "MachineAdmin model" do
     @json = IO::read(File::join(DATA_DIR, "machine_admin.json"))
   end
 
-  it "can be constructed from XML" do
-    conf = CIMI::Model::MachineAdmin.from_xml(@xml)
-    conf.should_not be_nil
-    should_serialize_from_xml! conf, @xml, @json
+  it "can be constructed from XML and JSON" do
+    should_properly_serialize_model CIMI::Model::MachineAdmin, @xml, @json
   end
 
-  it "can be constructed from JSON" do
-    conf = CIMI::Model::MachineAdmin.from_json(@json)
-    conf.should_not be_nil
-    should_serialize_from_json! conf, @xml, @json
-  end
-
-
-
 end

Modified: deltacloud/trunk/server/spec/cimi/model/machine_configuration_spec.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/spec/cimi/model/machine_configuration_spec.rb?rev=1205812&r1=1205811&r2=1205812&view=diff
==============================================================================
--- deltacloud/trunk/server/spec/cimi/model/machine_configuration_spec.rb (original)
+++ deltacloud/trunk/server/spec/cimi/model/machine_configuration_spec.rb Thu Nov 24 13:18:49
2011
@@ -20,16 +20,8 @@ describe "MachineConfiguration model" do
     @json = IO::read(File::join(DATA_DIR, "machine_configuration.json"))
   end
 
-  it "can be constructed from XML" do
-    conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
-    conf.should_not be_nil
-    should_serialize_from_xml! conf, @xml, @json
-  end
-
-  it "can be constructed from JSON" do
-    conf = CIMI::Model::MachineConfiguration.from_json(@json)
-    conf.should_not be_nil
-    should_serialize_from_json! conf, @xml, @json
+  it "can be constructed from XML and JSON" do
+    should_properly_serialize_model CIMI::Model::MachineConfiguration, @xml, @json
   end
 
 end

Modified: deltacloud/trunk/server/spec/cimi/model/machine_image_spec.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/spec/cimi/model/machine_image_spec.rb?rev=1205812&r1=1205811&r2=1205812&view=diff
==============================================================================
--- deltacloud/trunk/server/spec/cimi/model/machine_image_spec.rb (original)
+++ deltacloud/trunk/server/spec/cimi/model/machine_image_spec.rb Thu Nov 24 13:18:49 2011
@@ -21,16 +21,9 @@ describe "MachineImage model" do
     @json = IO::read(File::join(DATA_DIR, "machine_image.json"))
   end
 
-  it "can be constructed from XML" do
-    img = CIMI::Model::MachineImage.from_xml(@xml)
-    img.should_not be_nil
-    should_serialize_from_xml! img, @xml, @json
+  it "can be constructed from XML and JSON" do
+    should_properly_serialize_model CIMI::Model::MachineImage, @xml, @json
   end
 
-  it "can be constructed from JSON" do
-    img = CIMI::Model::MachineImage.from_json(@json)
-    img.should_not be_nil
-    should_serialize_from_json! img, @xml, @json
-  end
 
 end

Modified: deltacloud/trunk/server/spec/cimi/model/machine_spec.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/spec/cimi/model/machine_spec.rb?rev=1205812&r1=1205811&r2=1205812&view=diff
==============================================================================
--- deltacloud/trunk/server/spec/cimi/model/machine_spec.rb (original)
+++ deltacloud/trunk/server/spec/cimi/model/machine_spec.rb Thu Nov 24 13:18:49 2011
@@ -20,21 +20,8 @@ describe "Machine model" do
     @json = IO::read(File::join(DATA_DIR, "machine.json"))
   end
 
-  it "should hold just machine schema" do
-    CIMI::Model::Machine.schema.attribute_names.should_not include(:image_location)
-    CIMI::Model::Machine.schema.attribute_names.should include(:meters)
-  end
-
-  it "can be constructed from XML" do
-    machine = CIMI::Model::Machine.from_xml(@xml)
-    machine.should_not be_nil
-    should_serialize_from_xml! machine, @xml, @json
-  end
-
-  it "can be constructed from JSON" do
-    machine = CIMI::Model::Machine.from_json(@json)
-    machine.should_not be_nil
-    should_serialize_from_json! machine, @xml, @json
+  it "can be constructed from XML and JSON" do
+    should_properly_serialize_model CIMI::Model::Machine, @xml, @json
   end
 
 end

Modified: deltacloud/trunk/server/spec/cimi/model/machine_template_spec.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/spec/cimi/model/machine_template_spec.rb?rev=1205812&r1=1205811&r2=1205812&view=diff
==============================================================================
--- deltacloud/trunk/server/spec/cimi/model/machine_template_spec.rb (original)
+++ deltacloud/trunk/server/spec/cimi/model/machine_template_spec.rb Thu Nov 24 13:18:49 2011
@@ -20,16 +20,8 @@ describe "MachineTemplate model" do
     @json = IO::read(File::join(DATA_DIR, "machine_template.json"))
   end
 
-  it "can be constructed from XML" do
-    conf = CIMI::Model::MachineTemplate.from_xml(@xml)
-    conf.should_not be_nil
-    should_serialize_from_xml! conf, @xml, @json
-  end
-
-  it "can be constructed from JSON" do
-    conf = CIMI::Model::MachineTemplate.from_json(@json)
-    conf.should_not be_nil
-    should_serialize_from_json! conf, @xml, @json
+  it "can be constructed from XML and JSON" do
+    should_properly_serialize_model CIMI::Model::MachineTemplate, @xml, @json
   end
 
 end

Modified: deltacloud/trunk/server/spec/cimi/model/volume_spec.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/spec/cimi/model/volume_spec.rb?rev=1205812&r1=1205811&r2=1205812&view=diff
==============================================================================
--- deltacloud/trunk/server/spec/cimi/model/volume_spec.rb (original)
+++ deltacloud/trunk/server/spec/cimi/model/volume_spec.rb Thu Nov 24 13:18:49 2011
@@ -21,16 +21,8 @@ describe "Volume model" do
     @json = IO::read(File::join(DATA_DIR, "volume.json"))
   end
 
-  it "can be constructed from XML" do
-    conf = CIMI::Model::Volume.from_xml(@xml)
-    conf.should_not be_nil
-    should_serialize_from_xml! conf, @xml, @json
-  end
-
-  it "can be constructed from JSON" do
-    conf = CIMI::Model::Volume.from_json(@json)
-    conf.should_not be_nil
-    should_serialize_from_json! conf, @xml, @json
+  it "can be constructed from XML and JSON" do
+    should_properly_serialize_model CIMI::Model::Volume, @xml, @json
   end
 
 end

Modified: deltacloud/trunk/server/spec/spec_helper.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/spec/spec_helper.rb?rev=1205812&r1=1205811&r2=1205812&view=diff
==============================================================================
--- deltacloud/trunk/server/spec/spec_helper.rb (original)
+++ deltacloud/trunk/server/spec/spec_helper.rb Thu Nov 24 13:18:49 2011
@@ -90,14 +90,13 @@ class HashCmp
   end
 end
 
-def should_serialize_from_xml!(model, xml, json)
-  model.to_xml.should serialize_to xml, :fmt => :xml
-  model.to_json.should serialize_to json, :fmt => :json
-end
-
-def should_serialize_from_json!(model, xml, json)
-  model.to_xml.should serialize_to xml, :fmt => :xml
-  model.to_json.should serialize_to json, :fmt => :json
+def should_properly_serialize_model(model_class, xml, json)
+  # Roundtrip in same format
+  model_class.from_xml(xml).should serialize_to xml, :fmt => :xml
+  model_class.from_json(json).should serialize_to json, :fmt => :json
+  # Roundtrip crossing format
+  model_class.from_xml(xml).should serialize_to json, :fmt => :json
+  model_class.from_json(json).should serialize_to xml, :fmt => :xml
 end
 
 RSpec::Matchers.define :serialize_to do |exp, opts|



Mime
View raw message