You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/11/16 21:34:33 UTC

[PATCH core 4/4] CIMI: Revampled spec files once again to use the helpers for checking sanity of serialization

From: Michal Fojtik <mf...@redhat.com>

---
 .../spec/cimi/model/machine_configuration_spec.rb  |   99 ++------------
 server/spec/cimi/model/machine_image_spec.rb       |   82 +----------
 server/spec/cimi/model/machine_template_spec.rb    |  152 +------------------
 3 files changed, 25 insertions(+), 308 deletions(-)

diff --git a/server/spec/cimi/model/machine_configuration_spec.rb b/server/spec/cimi/model/machine_configuration_spec.rb
index d60286e..454e8c4 100644
--- a/server/spec/cimi/model/machine_configuration_spec.rb
+++ b/server/spec/cimi/model/machine_configuration_spec.rb
@@ -20,97 +20,16 @@ describe "MachineConfiguration model" do
     @json = IO::read(File::join(DATA_DIR, "machine_configuration.json"))
   end
 
-  describe 'XML' do
-    it "can be constructed" do
-      conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
-      conf.should_not be_nil
-      conf.should serialize_to @xml, :fmt => :xml
-    end
-
-    it "should convert strings in keys to symbols when contructed from XML" do
-      conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
-      conf.should_not be_nil
-      conf.attribute_values.keys.each { |key| key.should be_a(Symbol) }
-    end
-
-    it "should have default properties" do
-      conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
-      conf.name.should == 'MachineConfiguration1'
-      conf.uri == 'http://cimi.example.org/machine_configurations/1'
-      conf.description == 'Example MachineConfiguration One'
-      conf.created.should == "2011-11-14"
-    end
-
-    it "should have cpu and memory properties" do
-      conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
-      conf.cpu.should == "2"
-      conf.memory.should be_an_instance_of Hash
-      conf.memory['quantity'].should == '1'
-      conf.memory['units'].should == 'gigabyte'
-    end
-
-    it "should have disk array property with capacity" do
-      conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
-      conf.disk.size.should == 1
-      conf.disk[0].respond_to?(:capacity).should be_true
-      conf.disk[0].capacity.size.should == 1
-      conf.disk[0].capacity[0]['format'] == 'ext4'
-      conf.disk[0].capacity[0]['quantity'] == '1'
-      conf.disk[0].capacity[0]['attachmentPoint'] == '/'
-      conf.disk[0].capacity[0]['units'] == 'terabyte'
-    end
-
-    it "should have edit and delete operations" do
-      conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
-      conf.operations.size.should == 2
-      conf.operations.any? { |operation| operation.rel == 'edit' }.should be_true
-      conf.operations.any? { |operation| operation.rel == 'delete' }.should be_true
-      conf.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
-    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
 
-  describe "JSON" do
-    it "can be constructed" do
-      conf = CIMI::Model::MachineConfiguration.from_json(@json)
-      conf.should_not be_nil
-      conf.should serialize_to @json, :fmt => :json
-    end
-
-    it "should have default properties" do
-      conf = CIMI::Model::MachineConfiguration.from_json(@json)
-      conf.name.should == 'MachineConfiguration1'
-      conf.uri == 'http://cimi.example.org/machine_configurations/1'
-      conf.description == 'Example MachineConfiguration One'
-      conf.created.should == "2011-11-14"
-    end
-
-    it "should have cpu and memory properties" do
-      conf = CIMI::Model::MachineConfiguration.from_json(@json)
-      conf.cpu.should == "2"
-      conf.memory.should be_an_instance_of Hash
-      conf.memory['quantity'].should == '1'
-      conf.memory['units'].should == 'gigabyte'
-    end
-
-    it "should have disk array property with capacity" do
-      conf = CIMI::Model::MachineConfiguration.from_json(@json)
-      conf.disk.should be_an_instance_of Array
-      conf.disk.size.should > 0
-      conf.disk[0].should respond_to :capacity
-      conf.disk[0].capacity.size.should == 1
-      conf.disk[0].capacity[0]['format'] == 'ext4'
-      conf.disk[0].capacity[0]['quantity'] == '1'
-      conf.disk[0].capacity[0]['attachmentPoint'] == '/'
-      conf.disk[0].capacity[0]['units'] == 'terabyte'
-    end
-
-    it "should have edit and delete operations" do
-      conf = CIMI::Model::MachineConfiguration.from_json(@json)
-      conf.operations.size.should == 2
-      conf.operations.any? { |operation| operation.rel == 'edit' }.should be_true
-      conf.operations.any? { |operation| operation.rel == 'delete' }.should be_true
-      conf.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
-    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
   end
+
 end
diff --git a/server/spec/cimi/model/machine_image_spec.rb b/server/spec/cimi/model/machine_image_spec.rb
index 517769a..824d032 100644
--- a/server/spec/cimi/model/machine_image_spec.rb
+++ b/server/spec/cimi/model/machine_image_spec.rb
@@ -21,82 +21,16 @@ describe "MachineImage model" do
     @json = IO::read(File::join(DATA_DIR, "machine_image.json"))
   end
 
-  describe "XML" do
-    it "can be constructed" do
-      img = CIMI::Model::MachineImage.from_xml(@xml)
-      img.should_not be_nil
-      img.should serialize_to @xml, :fmt => :xml
-    end
-
-    it "should have default properties" do
-      img = CIMI::Model::MachineImage.from_xml(@xml)
-      img.uri.should == "http://cimi.example.org/machine_image/1"
-      img.name.should == "img1"
-      img.description.should == "Machine Image One"
-      img.created.should == "2011-11-14"
-    end
-
-    it "should have image location property" do
-      img = CIMI::Model::MachineImage.from_xml(@xml)
-      img.image_location.should be_an_instance_of Hash
-      img.image_location['href'].should == 'nfs://cimi.example.com/images/1.img'
-    end
-
-    it "should have edit and delete operations" do
-      img = CIMI::Model::MachineImage.from_xml(@xml)
-      img.operations.any? { |operation| operation.rel == 'edit' }.should be_true
-      img.operations.any? { |operation| operation.rel == 'delete' }.should be_true
-      img.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
-    end
-
-    it "should parse properties correctly in XML" do
-      img = CIMI::Model::MachineImage.from_xml(@xml)
-      img.property.any? { |p| p.name == 'status' }.should be_true
-      img.property.any? { |p| p.name == 'locked' }.should be_true
-      img.property.size.should == 2
-    end
-
-    it "should convert strings in keys to symbols when contructed from XML" do
-      imgl = CIMI::Model::MachineImage.from_xml(@xml)
-      imgl.should_not be_nil
-      imgl.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) }
-    end
+  it "can be constructed from XML" do
+    conf = CIMI::Model::MachineImage.from_xml(@xml)
+    conf.should_not be_nil
+    should_serialize_from_xml! conf, @xml, @json
   end
 
-  describe 'JSON' do
-    it "can be constructed" do
-      img = CIMI::Model::MachineImage.from_json(@json)
-      img.should_not be_nil
-      img.should serialize_to @json, :fmt => :json
-    end
-
-    it "should have default properties" do
-      img = CIMI::Model::MachineImage.from_json(@json)
-      img.uri.should == "http://cimi.example.org/machine_images/1"
-      img.name.should == "img1"
-      img.description.should == "Machine Image One"
-      img.created.should == "2011-11-14"
-    end
-
-    it "should have image location property" do
-      img = CIMI::Model::MachineImage.from_json(@json)
-      img.image_location.should be_an_instance_of Hash
-      img.image_location['href'].should == 'nfs://cimi.example.com/images/1.img'
-    end
-
-    it "should have edit and delete operations" do
-      img = CIMI::Model::MachineImage.from_json(@json)
-      img.operations.any? { |operation| operation.rel == 'edit' }.should be_true
-      img.operations.any? { |operation| operation.rel == 'delete' }.should be_true
-      img.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
-    end
-
-    it "should parse properties correctly in XML" do
-      img = CIMI::Model::MachineImage.from_json(@json)
-      img.property.any? { |p| p.name == 'status' }.should be_true
-      img.property.any? { |p| p.name == 'locked' }.should be_true
-      img.property.size.should == 2
-    end
+  it "can be constructed from JSON" do
+    conf = CIMI::Model::MachineImage.from_json(@json)
+    conf.should_not be_nil
+    should_serialize_from_json! conf, @xml, @json
   end
 
 end
diff --git a/server/spec/cimi/model/machine_template_spec.rb b/server/spec/cimi/model/machine_template_spec.rb
index 8ccd9ae..0c6f50a 100644
--- a/server/spec/cimi/model/machine_template_spec.rb
+++ b/server/spec/cimi/model/machine_template_spec.rb
@@ -20,152 +20,16 @@ describe "MachineTemplate model" do
     @json = IO::read(File::join(DATA_DIR, "machine_template.json"))
   end
 
-  describe 'XML' do
-    it "can be constructed" do
-      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
-      templ.should_not be_nil
-      templ.should serialize_to @xml, :fmt => :xml
-    end
-
-    it "should have default properties" do
-      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
-      templ.created.should == "2011-11-01"
-      templ.name.should == "My First Template"
-      templ.description.should == "A template for testing"
-      templ.uri.should == "http://cimi.example.org/machine_templates/1"
-    end
-
-    it "should convert strings in keys to symbols when contructed from XML" do
-      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
-      templ.should_not be_nil
-      templ.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) }
-    end
-
-    it "should reference machine_config" do
-      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
-      templ.machine_config.should be_an_instance_of Struct::CIMI_MachineConfig
-      templ.machine_config.href.should == "http://cimi.example.org/machine_configs/1"
-    end
-
-    it "should reference machine_image" do
-      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
-      templ.machine_image.should be_an_instance_of Struct::CIMI_MachineImage
-      templ.machine_image.href.should == "http://cimi.example.org/machine_images/1"
-    end
-
-    it "should have list of attached volumes" do
-      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
-      templ.volumes.should be_a_kind_of Array
-      templ.volumes.each do |volume|
-        volume.href.should =~ /^http:\/\/.*\/volumes\/(\w+)$/
-        volume.protocol.should == 'nfs'
-        volume.attachment_point == '/dev/sda'
-        volume.should be_an_instance_of Struct::CIMI_Volume
-      end
-    end
-
-    it "should have list of network interfaces" do
-      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
-      templ.network_interfaces.should be_an_instance_of Array
-      templ.network_interfaces.each do |interface|
-        interface.hostname == 'host.cimi.example.org'
-        interface.mac_address == '00:11:22:33:44:55'
-        interface.state == 'UP'
-        interface.protocol == 'TCP'
-        interface.allocation == 'static'
-        interface.address == '192.168.0.17'
-        interface.default_gateway == '192.168.0.1'
-        interface.dns == '192.168.0.1'
-        interface.max_transmission_unit == '1500'
-        interface.vsp.should_not be_nil
-        interface.vsp.should be_an_instance_of Struct::CIMI_Vsp
-        interface.vsp.href.should =~ /^http:\/\/.*\/vsps\/(\w+)$/
-        interface.should be_an_instance_of Struct::CIMI_NetworkInterface
-      end
-    end
-
-    it "should have edit and delete operations" do
-      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
-      templ.operations.size.should == 2
-      templ.operations.any? { |operation| operation.rel == 'edit' }.should be_true
-      templ.operations.any? { |operation| operation.rel == 'delete' }.should be_true
-      templ.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
-    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
 
-  describe 'JSON' do
-    it "can be constructed" do
-      templ = CIMI::Model::MachineTemplate.from_json(@json)
-      templ.should_not be_nil
-      templ.should serialize_to @xml, :fmt => :xml
-    end
-
-    it "should have default properties" do
-      templ = CIMI::Model::MachineTemplate.from_json(@json)
-      templ.created.should == "2011-11-01"
-      templ.name.should == "My First Template"
-      templ.description.should == "A template for testing"
-      templ.uri.should == "http://cimi.example.org/machine_templates/1"
-    end
-
-    it "should convert strings in keys to symbols when contructed from XML" do
-      templ = CIMI::Model::MachineTemplate.from_json(@json)
-      templ.should_not be_nil
-      templ.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) }
-    end
-
-    it "should reference machine_config" do
-      templ = CIMI::Model::MachineTemplate.from_json(@json)
-      templ.machine_config.should be_an_instance_of Struct::CIMI_MachineConfig
-      templ.machine_config.href.should == "http://cimi.example.org/machine_configs/1"
-    end
-
-    it "should reference machine_image" do
-      templ = CIMI::Model::MachineTemplate.from_json(@json)
-      templ.machine_image.should be_an_instance_of Struct::CIMI_MachineImage
-      templ.machine_image.href.should == "http://cimi.example.org/machine_images/1"
-    end
-
-    it "should have list of attached volumes" do
-      templ = CIMI::Model::MachineTemplate.from_json(@json)
-      templ.volumes.should be_a_kind_of Array
-      templ.volumes.each do |volume|
-        volume.href.should =~ /^http:\/\/.*\/volumes\/(\w+)$/
-        volume.protocol.should == 'nfs'
-        volume.attachment_point == '/dev/sda'
-        volume.should be_an_instance_of Struct::CIMI_Volume
-      end
-    end
-
-    it "should have list of network interfaces" do
-      templ = CIMI::Model::MachineTemplate.from_json(@json)
-      templ.network_interfaces.should be_an_instance_of Array
-      templ.network_interfaces.each do |interface|
-        interface.hostname == 'host.cimi.example.org'
-        interface.mac_address == '00:11:22:33:44:55'
-        interface.state == 'UP'
-        interface.protocol == 'TCP'
-        interface.allocation == 'static'
-        interface.address == '192.168.0.17'
-        interface.default_gateway == '192.168.0.1'
-        interface.dns == '192.168.0.1'
-        interface.max_transmission_unit == '1500'
-        interface.vsp.should_not be_nil
-        interface.vsp.should be_an_instance_of Struct::CIMI_Vsp
-        interface.vsp.href.should =~ /^http:\/\/.*\/vsps\/(\w+)$/
-        interface.should be_an_instance_of Struct::CIMI_NetworkInterface
-      end
-    end
-
-    it "should have edit and delete operations" do
-      templ = CIMI::Model::MachineTemplate.from_json(@json)
-      templ.operations.size.should == 2
-      templ.operations.any? { |operation| operation.rel == 'edit' }.should be_true
-      templ.operations.any? { |operation| operation.rel == 'delete' }.should be_true
-      templ.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
-    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
   end
 
 end
-- 
1.7.7.3


Re: [PATCH core 4/4] CIMI: Revampled spec files once again to use the helpers for checking sanity of serialization

Posted by Michal Fojtik <mf...@redhat.com>.
Thanks! Fixed MachineConfig data to match with latest WIP and pushed.

 -- Michal

marios@redhat.com wrote:
> ACK
>
> On 16/11/11 22:34, mfojtik@redhat.com wrote:
>> From: Michal Fojtik <mf...@redhat.com>
>>
>> ---
>>  .../spec/cimi/model/machine_configuration_spec.rb  |   99 ++------------
>>  server/spec/cimi/model/machine_image_spec.rb       |   82 +----------
>>  server/spec/cimi/model/machine_template_spec.rb    |  152 +------------------
>>  3 files changed, 25 insertions(+), 308 deletions(-)
>>
>> diff --git a/server/spec/cimi/model/machine_configuration_spec.rb b/server/spec/cimi/model/machine_configuration_spec.rb
>> index d60286e..454e8c4 100644
>> --- a/server/spec/cimi/model/machine_configuration_spec.rb
>> +++ b/server/spec/cimi/model/machine_configuration_spec.rb
>> @@ -20,97 +20,16 @@ describe "MachineConfiguration model" do
>>      @json = IO::read(File::join(DATA_DIR, "machine_configuration.json"))
>>    end
>>  
>> -  describe 'XML' do
>> -    it "can be constructed" do
>> -      conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
>> -      conf.should_not be_nil
>> -      conf.should serialize_to @xml, :fmt => :xml
>> -    end
>> -
>> -    it "should convert strings in keys to symbols when contructed from XML" do
>> -      conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
>> -      conf.should_not be_nil
>> -      conf.attribute_values.keys.each { |key| key.should be_a(Symbol) }
>> -    end
>> -
>> -    it "should have default properties" do
>> -      conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
>> -      conf.name.should == 'MachineConfiguration1'
>> -      conf.uri == 'http://cimi.example.org/machine_configurations/1'
>> -      conf.description == 'Example MachineConfiguration One'
>> -      conf.created.should == "2011-11-14"
>> -    end
>> -
>> -    it "should have cpu and memory properties" do
>> -      conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
>> -      conf.cpu.should == "2"
>> -      conf.memory.should be_an_instance_of Hash
>> -      conf.memory['quantity'].should == '1'
>> -      conf.memory['units'].should == 'gigabyte'
>> -    end
>> -
>> -    it "should have disk array property with capacity" do
>> -      conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
>> -      conf.disk.size.should == 1
>> -      conf.disk[0].respond_to?(:capacity).should be_true
>> -      conf.disk[0].capacity.size.should == 1
>> -      conf.disk[0].capacity[0]['format'] == 'ext4'
>> -      conf.disk[0].capacity[0]['quantity'] == '1'
>> -      conf.disk[0].capacity[0]['attachmentPoint'] == '/'
>> -      conf.disk[0].capacity[0]['units'] == 'terabyte'
>> -    end
>> -
>> -    it "should have edit and delete operations" do
>> -      conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
>> -      conf.operations.size.should == 2
>> -      conf.operations.any? { |operation| operation.rel == 'edit' }.should be_true
>> -      conf.operations.any? { |operation| operation.rel == 'delete' }.should be_true
>> -      conf.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
>> -    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
>>  
>> -  describe "JSON" do
>> -    it "can be constructed" do
>> -      conf = CIMI::Model::MachineConfiguration.from_json(@json)
>> -      conf.should_not be_nil
>> -      conf.should serialize_to @json, :fmt => :json
>> -    end
>> -
>> -    it "should have default properties" do
>> -      conf = CIMI::Model::MachineConfiguration.from_json(@json)
>> -      conf.name.should == 'MachineConfiguration1'
>> -      conf.uri == 'http://cimi.example.org/machine_configurations/1'
>> -      conf.description == 'Example MachineConfiguration One'
>> -      conf.created.should == "2011-11-14"
>> -    end
>> -
>> -    it "should have cpu and memory properties" do
>> -      conf = CIMI::Model::MachineConfiguration.from_json(@json)
>> -      conf.cpu.should == "2"
>> -      conf.memory.should be_an_instance_of Hash
>> -      conf.memory['quantity'].should == '1'
>> -      conf.memory['units'].should == 'gigabyte'
>> -    end
>> -
>> -    it "should have disk array property with capacity" do
>> -      conf = CIMI::Model::MachineConfiguration.from_json(@json)
>> -      conf.disk.should be_an_instance_of Array
>> -      conf.disk.size.should > 0
>> -      conf.disk[0].should respond_to :capacity
>> -      conf.disk[0].capacity.size.should == 1
>> -      conf.disk[0].capacity[0]['format'] == 'ext4'
>> -      conf.disk[0].capacity[0]['quantity'] == '1'
>> -      conf.disk[0].capacity[0]['attachmentPoint'] == '/'
>> -      conf.disk[0].capacity[0]['units'] == 'terabyte'
>> -    end
>> -
>> -    it "should have edit and delete operations" do
>> -      conf = CIMI::Model::MachineConfiguration.from_json(@json)
>> -      conf.operations.size.should == 2
>> -      conf.operations.any? { |operation| operation.rel == 'edit' }.should be_true
>> -      conf.operations.any? { |operation| operation.rel == 'delete' }.should be_true
>> -      conf.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
>> -    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
>>    end
>> +
>>  end
>> diff --git a/server/spec/cimi/model/machine_image_spec.rb b/server/spec/cimi/model/machine_image_spec.rb
>> index 517769a..824d032 100644
>> --- a/server/spec/cimi/model/machine_image_spec.rb
>> +++ b/server/spec/cimi/model/machine_image_spec.rb
>> @@ -21,82 +21,16 @@ describe "MachineImage model" do
>>      @json = IO::read(File::join(DATA_DIR, "machine_image.json"))
>>    end
>>  
>> -  describe "XML" do
>> -    it "can be constructed" do
>> -      img = CIMI::Model::MachineImage.from_xml(@xml)
>> -      img.should_not be_nil
>> -      img.should serialize_to @xml, :fmt => :xml
>> -    end
>> -
>> -    it "should have default properties" do
>> -      img = CIMI::Model::MachineImage.from_xml(@xml)
>> -      img.uri.should == "http://cimi.example.org/machine_image/1"
>> -      img.name.should == "img1"
>> -      img.description.should == "Machine Image One"
>> -      img.created.should == "2011-11-14"
>> -    end
>> -
>> -    it "should have image location property" do
>> -      img = CIMI::Model::MachineImage.from_xml(@xml)
>> -      img.image_location.should be_an_instance_of Hash
>> -      img.image_location['href'].should == 'nfs://cimi.example.com/images/1.img'
>> -    end
>> -
>> -    it "should have edit and delete operations" do
>> -      img = CIMI::Model::MachineImage.from_xml(@xml)
>> -      img.operations.any? { |operation| operation.rel == 'edit' }.should be_true
>> -      img.operations.any? { |operation| operation.rel == 'delete' }.should be_true
>> -      img.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
>> -    end
>> -
>> -    it "should parse properties correctly in XML" do
>> -      img = CIMI::Model::MachineImage.from_xml(@xml)
>> -      img.property.any? { |p| p.name == 'status' }.should be_true
>> -      img.property.any? { |p| p.name == 'locked' }.should be_true
>> -      img.property.size.should == 2
>> -    end
>> -
>> -    it "should convert strings in keys to symbols when contructed from XML" do
>> -      imgl = CIMI::Model::MachineImage.from_xml(@xml)
>> -      imgl.should_not be_nil
>> -      imgl.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) }
>> -    end
>> +  it "can be constructed from XML" do
>> +    conf = CIMI::Model::MachineImage.from_xml(@xml)
>> +    conf.should_not be_nil
>> +    should_serialize_from_xml! conf, @xml, @json
>>    end
>>  
>> -  describe 'JSON' do
>> -    it "can be constructed" do
>> -      img = CIMI::Model::MachineImage.from_json(@json)
>> -      img.should_not be_nil
>> -      img.should serialize_to @json, :fmt => :json
>> -    end
>> -
>> -    it "should have default properties" do
>> -      img = CIMI::Model::MachineImage.from_json(@json)
>> -      img.uri.should == "http://cimi.example.org/machine_images/1"
>> -      img.name.should == "img1"
>> -      img.description.should == "Machine Image One"
>> -      img.created.should == "2011-11-14"
>> -    end
>> -
>> -    it "should have image location property" do
>> -      img = CIMI::Model::MachineImage.from_json(@json)
>> -      img.image_location.should be_an_instance_of Hash
>> -      img.image_location['href'].should == 'nfs://cimi.example.com/images/1.img'
>> -    end
>> -
>> -    it "should have edit and delete operations" do
>> -      img = CIMI::Model::MachineImage.from_json(@json)
>> -      img.operations.any? { |operation| operation.rel == 'edit' }.should be_true
>> -      img.operations.any? { |operation| operation.rel == 'delete' }.should be_true
>> -      img.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
>> -    end
>> -
>> -    it "should parse properties correctly in XML" do
>> -      img = CIMI::Model::MachineImage.from_json(@json)
>> -      img.property.any? { |p| p.name == 'status' }.should be_true
>> -      img.property.any? { |p| p.name == 'locked' }.should be_true
>> -      img.property.size.should == 2
>> -    end
>> +  it "can be constructed from JSON" do
>> +    conf = CIMI::Model::MachineImage.from_json(@json)
>> +    conf.should_not be_nil
>> +    should_serialize_from_json! conf, @xml, @json
>>    end
>>  
>>  end
>> diff --git a/server/spec/cimi/model/machine_template_spec.rb b/server/spec/cimi/model/machine_template_spec.rb
>> index 8ccd9ae..0c6f50a 100644
>> --- a/server/spec/cimi/model/machine_template_spec.rb
>> +++ b/server/spec/cimi/model/machine_template_spec.rb
>> @@ -20,152 +20,16 @@ describe "MachineTemplate model" do
>>      @json = IO::read(File::join(DATA_DIR, "machine_template.json"))
>>    end
>>  
>> -  describe 'XML' do
>> -    it "can be constructed" do
>> -      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
>> -      templ.should_not be_nil
>> -      templ.should serialize_to @xml, :fmt => :xml
>> -    end
>> -
>> -    it "should have default properties" do
>> -      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
>> -      templ.created.should == "2011-11-01"
>> -      templ.name.should == "My First Template"
>> -      templ.description.should == "A template for testing"
>> -      templ.uri.should == "http://cimi.example.org/machine_templates/1"
>> -    end
>> -
>> -    it "should convert strings in keys to symbols when contructed from XML" do
>> -      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
>> -      templ.should_not be_nil
>> -      templ.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) }
>> -    end
>> -
>> -    it "should reference machine_config" do
>> -      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
>> -      templ.machine_config.should be_an_instance_of Struct::CIMI_MachineConfig
>> -      templ.machine_config.href.should == "http://cimi.example.org/machine_configs/1"
>> -    end
>> -
>> -    it "should reference machine_image" do
>> -      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
>> -      templ.machine_image.should be_an_instance_of Struct::CIMI_MachineImage
>> -      templ.machine_image.href.should == "http://cimi.example.org/machine_images/1"
>> -    end
>> -
>> -    it "should have list of attached volumes" do
>> -      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
>> -      templ.volumes.should be_a_kind_of Array
>> -      templ.volumes.each do |volume|
>> -        volume.href.should =~ /^http:\/\/.*\/volumes\/(\w+)$/
>> -        volume.protocol.should == 'nfs'
>> -        volume.attachment_point == '/dev/sda'
>> -        volume.should be_an_instance_of Struct::CIMI_Volume
>> -      end
>> -    end
>> -
>> -    it "should have list of network interfaces" do
>> -      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
>> -      templ.network_interfaces.should be_an_instance_of Array
>> -      templ.network_interfaces.each do |interface|
>> -        interface.hostname == 'host.cimi.example.org'
>> -        interface.mac_address == '00:11:22:33:44:55'
>> -        interface.state == 'UP'
>> -        interface.protocol == 'TCP'
>> -        interface.allocation == 'static'
>> -        interface.address == '192.168.0.17'
>> -        interface.default_gateway == '192.168.0.1'
>> -        interface.dns == '192.168.0.1'
>> -        interface.max_transmission_unit == '1500'
>> -        interface.vsp.should_not be_nil
>> -        interface.vsp.should be_an_instance_of Struct::CIMI_Vsp
>> -        interface.vsp.href.should =~ /^http:\/\/.*\/vsps\/(\w+)$/
>> -        interface.should be_an_instance_of Struct::CIMI_NetworkInterface
>> -      end
>> -    end
>> -
>> -    it "should have edit and delete operations" do
>> -      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
>> -      templ.operations.size.should == 2
>> -      templ.operations.any? { |operation| operation.rel == 'edit' }.should be_true
>> -      templ.operations.any? { |operation| operation.rel == 'delete' }.should be_true
>> -      templ.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
>> -    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
>>  
>> -  describe 'JSON' do
>> -    it "can be constructed" do
>> -      templ = CIMI::Model::MachineTemplate.from_json(@json)
>> -      templ.should_not be_nil
>> -      templ.should serialize_to @xml, :fmt => :xml
>> -    end
>> -
>> -    it "should have default properties" do
>> -      templ = CIMI::Model::MachineTemplate.from_json(@json)
>> -      templ.created.should == "2011-11-01"
>> -      templ.name.should == "My First Template"
>> -      templ.description.should == "A template for testing"
>> -      templ.uri.should == "http://cimi.example.org/machine_templates/1"
>> -    end
>> -
>> -    it "should convert strings in keys to symbols when contructed from XML" do
>> -      templ = CIMI::Model::MachineTemplate.from_json(@json)
>> -      templ.should_not be_nil
>> -      templ.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) }
>> -    end
>> -
>> -    it "should reference machine_config" do
>> -      templ = CIMI::Model::MachineTemplate.from_json(@json)
>> -      templ.machine_config.should be_an_instance_of Struct::CIMI_MachineConfig
>> -      templ.machine_config.href.should == "http://cimi.example.org/machine_configs/1"
>> -    end
>> -
>> -    it "should reference machine_image" do
>> -      templ = CIMI::Model::MachineTemplate.from_json(@json)
>> -      templ.machine_image.should be_an_instance_of Struct::CIMI_MachineImage
>> -      templ.machine_image.href.should == "http://cimi.example.org/machine_images/1"
>> -    end
>> -
>> -    it "should have list of attached volumes" do
>> -      templ = CIMI::Model::MachineTemplate.from_json(@json)
>> -      templ.volumes.should be_a_kind_of Array
>> -      templ.volumes.each do |volume|
>> -        volume.href.should =~ /^http:\/\/.*\/volumes\/(\w+)$/
>> -        volume.protocol.should == 'nfs'
>> -        volume.attachment_point == '/dev/sda'
>> -        volume.should be_an_instance_of Struct::CIMI_Volume
>> -      end
>> -    end
>> -
>> -    it "should have list of network interfaces" do
>> -      templ = CIMI::Model::MachineTemplate.from_json(@json)
>> -      templ.network_interfaces.should be_an_instance_of Array
>> -      templ.network_interfaces.each do |interface|
>> -        interface.hostname == 'host.cimi.example.org'
>> -        interface.mac_address == '00:11:22:33:44:55'
>> -        interface.state == 'UP'
>> -        interface.protocol == 'TCP'
>> -        interface.allocation == 'static'
>> -        interface.address == '192.168.0.17'
>> -        interface.default_gateway == '192.168.0.1'
>> -        interface.dns == '192.168.0.1'
>> -        interface.max_transmission_unit == '1500'
>> -        interface.vsp.should_not be_nil
>> -        interface.vsp.should be_an_instance_of Struct::CIMI_Vsp
>> -        interface.vsp.href.should =~ /^http:\/\/.*\/vsps\/(\w+)$/
>> -        interface.should be_an_instance_of Struct::CIMI_NetworkInterface
>> -      end
>> -    end
>> -
>> -    it "should have edit and delete operations" do
>> -      templ = CIMI::Model::MachineTemplate.from_json(@json)
>> -      templ.operations.size.should == 2
>> -      templ.operations.any? { |operation| operation.rel == 'edit' }.should be_true
>> -      templ.operations.any? { |operation| operation.rel == 'delete' }.should be_true
>> -      templ.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
>> -    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
>>    end
>>  
>>  end
>

Re: [PATCH core 4/4] CIMI: Revampled spec files once again to use the helpers for checking sanity of serialization

Posted by "marios@redhat.com" <ma...@redhat.com>.
ACK

On 16/11/11 22:34, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> 
> ---
>  .../spec/cimi/model/machine_configuration_spec.rb  |   99 ++------------
>  server/spec/cimi/model/machine_image_spec.rb       |   82 +----------
>  server/spec/cimi/model/machine_template_spec.rb    |  152 +------------------
>  3 files changed, 25 insertions(+), 308 deletions(-)
> 
> diff --git a/server/spec/cimi/model/machine_configuration_spec.rb b/server/spec/cimi/model/machine_configuration_spec.rb
> index d60286e..454e8c4 100644
> --- a/server/spec/cimi/model/machine_configuration_spec.rb
> +++ b/server/spec/cimi/model/machine_configuration_spec.rb
> @@ -20,97 +20,16 @@ describe "MachineConfiguration model" do
>      @json = IO::read(File::join(DATA_DIR, "machine_configuration.json"))
>    end
>  
> -  describe 'XML' do
> -    it "can be constructed" do
> -      conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
> -      conf.should_not be_nil
> -      conf.should serialize_to @xml, :fmt => :xml
> -    end
> -
> -    it "should convert strings in keys to symbols when contructed from XML" do
> -      conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
> -      conf.should_not be_nil
> -      conf.attribute_values.keys.each { |key| key.should be_a(Symbol) }
> -    end
> -
> -    it "should have default properties" do
> -      conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
> -      conf.name.should == 'MachineConfiguration1'
> -      conf.uri == 'http://cimi.example.org/machine_configurations/1'
> -      conf.description == 'Example MachineConfiguration One'
> -      conf.created.should == "2011-11-14"
> -    end
> -
> -    it "should have cpu and memory properties" do
> -      conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
> -      conf.cpu.should == "2"
> -      conf.memory.should be_an_instance_of Hash
> -      conf.memory['quantity'].should == '1'
> -      conf.memory['units'].should == 'gigabyte'
> -    end
> -
> -    it "should have disk array property with capacity" do
> -      conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
> -      conf.disk.size.should == 1
> -      conf.disk[0].respond_to?(:capacity).should be_true
> -      conf.disk[0].capacity.size.should == 1
> -      conf.disk[0].capacity[0]['format'] == 'ext4'
> -      conf.disk[0].capacity[0]['quantity'] == '1'
> -      conf.disk[0].capacity[0]['attachmentPoint'] == '/'
> -      conf.disk[0].capacity[0]['units'] == 'terabyte'
> -    end
> -
> -    it "should have edit and delete operations" do
> -      conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
> -      conf.operations.size.should == 2
> -      conf.operations.any? { |operation| operation.rel == 'edit' }.should be_true
> -      conf.operations.any? { |operation| operation.rel == 'delete' }.should be_true
> -      conf.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
> -    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
>  
> -  describe "JSON" do
> -    it "can be constructed" do
> -      conf = CIMI::Model::MachineConfiguration.from_json(@json)
> -      conf.should_not be_nil
> -      conf.should serialize_to @json, :fmt => :json
> -    end
> -
> -    it "should have default properties" do
> -      conf = CIMI::Model::MachineConfiguration.from_json(@json)
> -      conf.name.should == 'MachineConfiguration1'
> -      conf.uri == 'http://cimi.example.org/machine_configurations/1'
> -      conf.description == 'Example MachineConfiguration One'
> -      conf.created.should == "2011-11-14"
> -    end
> -
> -    it "should have cpu and memory properties" do
> -      conf = CIMI::Model::MachineConfiguration.from_json(@json)
> -      conf.cpu.should == "2"
> -      conf.memory.should be_an_instance_of Hash
> -      conf.memory['quantity'].should == '1'
> -      conf.memory['units'].should == 'gigabyte'
> -    end
> -
> -    it "should have disk array property with capacity" do
> -      conf = CIMI::Model::MachineConfiguration.from_json(@json)
> -      conf.disk.should be_an_instance_of Array
> -      conf.disk.size.should > 0
> -      conf.disk[0].should respond_to :capacity
> -      conf.disk[0].capacity.size.should == 1
> -      conf.disk[0].capacity[0]['format'] == 'ext4'
> -      conf.disk[0].capacity[0]['quantity'] == '1'
> -      conf.disk[0].capacity[0]['attachmentPoint'] == '/'
> -      conf.disk[0].capacity[0]['units'] == 'terabyte'
> -    end
> -
> -    it "should have edit and delete operations" do
> -      conf = CIMI::Model::MachineConfiguration.from_json(@json)
> -      conf.operations.size.should == 2
> -      conf.operations.any? { |operation| operation.rel == 'edit' }.should be_true
> -      conf.operations.any? { |operation| operation.rel == 'delete' }.should be_true
> -      conf.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
> -    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
>    end
> +
>  end
> diff --git a/server/spec/cimi/model/machine_image_spec.rb b/server/spec/cimi/model/machine_image_spec.rb
> index 517769a..824d032 100644
> --- a/server/spec/cimi/model/machine_image_spec.rb
> +++ b/server/spec/cimi/model/machine_image_spec.rb
> @@ -21,82 +21,16 @@ describe "MachineImage model" do
>      @json = IO::read(File::join(DATA_DIR, "machine_image.json"))
>    end
>  
> -  describe "XML" do
> -    it "can be constructed" do
> -      img = CIMI::Model::MachineImage.from_xml(@xml)
> -      img.should_not be_nil
> -      img.should serialize_to @xml, :fmt => :xml
> -    end
> -
> -    it "should have default properties" do
> -      img = CIMI::Model::MachineImage.from_xml(@xml)
> -      img.uri.should == "http://cimi.example.org/machine_image/1"
> -      img.name.should == "img1"
> -      img.description.should == "Machine Image One"
> -      img.created.should == "2011-11-14"
> -    end
> -
> -    it "should have image location property" do
> -      img = CIMI::Model::MachineImage.from_xml(@xml)
> -      img.image_location.should be_an_instance_of Hash
> -      img.image_location['href'].should == 'nfs://cimi.example.com/images/1.img'
> -    end
> -
> -    it "should have edit and delete operations" do
> -      img = CIMI::Model::MachineImage.from_xml(@xml)
> -      img.operations.any? { |operation| operation.rel == 'edit' }.should be_true
> -      img.operations.any? { |operation| operation.rel == 'delete' }.should be_true
> -      img.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
> -    end
> -
> -    it "should parse properties correctly in XML" do
> -      img = CIMI::Model::MachineImage.from_xml(@xml)
> -      img.property.any? { |p| p.name == 'status' }.should be_true
> -      img.property.any? { |p| p.name == 'locked' }.should be_true
> -      img.property.size.should == 2
> -    end
> -
> -    it "should convert strings in keys to symbols when contructed from XML" do
> -      imgl = CIMI::Model::MachineImage.from_xml(@xml)
> -      imgl.should_not be_nil
> -      imgl.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) }
> -    end
> +  it "can be constructed from XML" do
> +    conf = CIMI::Model::MachineImage.from_xml(@xml)
> +    conf.should_not be_nil
> +    should_serialize_from_xml! conf, @xml, @json
>    end
>  
> -  describe 'JSON' do
> -    it "can be constructed" do
> -      img = CIMI::Model::MachineImage.from_json(@json)
> -      img.should_not be_nil
> -      img.should serialize_to @json, :fmt => :json
> -    end
> -
> -    it "should have default properties" do
> -      img = CIMI::Model::MachineImage.from_json(@json)
> -      img.uri.should == "http://cimi.example.org/machine_images/1"
> -      img.name.should == "img1"
> -      img.description.should == "Machine Image One"
> -      img.created.should == "2011-11-14"
> -    end
> -
> -    it "should have image location property" do
> -      img = CIMI::Model::MachineImage.from_json(@json)
> -      img.image_location.should be_an_instance_of Hash
> -      img.image_location['href'].should == 'nfs://cimi.example.com/images/1.img'
> -    end
> -
> -    it "should have edit and delete operations" do
> -      img = CIMI::Model::MachineImage.from_json(@json)
> -      img.operations.any? { |operation| operation.rel == 'edit' }.should be_true
> -      img.operations.any? { |operation| operation.rel == 'delete' }.should be_true
> -      img.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
> -    end
> -
> -    it "should parse properties correctly in XML" do
> -      img = CIMI::Model::MachineImage.from_json(@json)
> -      img.property.any? { |p| p.name == 'status' }.should be_true
> -      img.property.any? { |p| p.name == 'locked' }.should be_true
> -      img.property.size.should == 2
> -    end
> +  it "can be constructed from JSON" do
> +    conf = CIMI::Model::MachineImage.from_json(@json)
> +    conf.should_not be_nil
> +    should_serialize_from_json! conf, @xml, @json
>    end
>  
>  end
> diff --git a/server/spec/cimi/model/machine_template_spec.rb b/server/spec/cimi/model/machine_template_spec.rb
> index 8ccd9ae..0c6f50a 100644
> --- a/server/spec/cimi/model/machine_template_spec.rb
> +++ b/server/spec/cimi/model/machine_template_spec.rb
> @@ -20,152 +20,16 @@ describe "MachineTemplate model" do
>      @json = IO::read(File::join(DATA_DIR, "machine_template.json"))
>    end
>  
> -  describe 'XML' do
> -    it "can be constructed" do
> -      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
> -      templ.should_not be_nil
> -      templ.should serialize_to @xml, :fmt => :xml
> -    end
> -
> -    it "should have default properties" do
> -      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
> -      templ.created.should == "2011-11-01"
> -      templ.name.should == "My First Template"
> -      templ.description.should == "A template for testing"
> -      templ.uri.should == "http://cimi.example.org/machine_templates/1"
> -    end
> -
> -    it "should convert strings in keys to symbols when contructed from XML" do
> -      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
> -      templ.should_not be_nil
> -      templ.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) }
> -    end
> -
> -    it "should reference machine_config" do
> -      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
> -      templ.machine_config.should be_an_instance_of Struct::CIMI_MachineConfig
> -      templ.machine_config.href.should == "http://cimi.example.org/machine_configs/1"
> -    end
> -
> -    it "should reference machine_image" do
> -      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
> -      templ.machine_image.should be_an_instance_of Struct::CIMI_MachineImage
> -      templ.machine_image.href.should == "http://cimi.example.org/machine_images/1"
> -    end
> -
> -    it "should have list of attached volumes" do
> -      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
> -      templ.volumes.should be_a_kind_of Array
> -      templ.volumes.each do |volume|
> -        volume.href.should =~ /^http:\/\/.*\/volumes\/(\w+)$/
> -        volume.protocol.should == 'nfs'
> -        volume.attachment_point == '/dev/sda'
> -        volume.should be_an_instance_of Struct::CIMI_Volume
> -      end
> -    end
> -
> -    it "should have list of network interfaces" do
> -      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
> -      templ.network_interfaces.should be_an_instance_of Array
> -      templ.network_interfaces.each do |interface|
> -        interface.hostname == 'host.cimi.example.org'
> -        interface.mac_address == '00:11:22:33:44:55'
> -        interface.state == 'UP'
> -        interface.protocol == 'TCP'
> -        interface.allocation == 'static'
> -        interface.address == '192.168.0.17'
> -        interface.default_gateway == '192.168.0.1'
> -        interface.dns == '192.168.0.1'
> -        interface.max_transmission_unit == '1500'
> -        interface.vsp.should_not be_nil
> -        interface.vsp.should be_an_instance_of Struct::CIMI_Vsp
> -        interface.vsp.href.should =~ /^http:\/\/.*\/vsps\/(\w+)$/
> -        interface.should be_an_instance_of Struct::CIMI_NetworkInterface
> -      end
> -    end
> -
> -    it "should have edit and delete operations" do
> -      templ = CIMI::Model::MachineTemplate.from_xml(@xml)
> -      templ.operations.size.should == 2
> -      templ.operations.any? { |operation| operation.rel == 'edit' }.should be_true
> -      templ.operations.any? { |operation| operation.rel == 'delete' }.should be_true
> -      templ.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
> -    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
>  
> -  describe 'JSON' do
> -    it "can be constructed" do
> -      templ = CIMI::Model::MachineTemplate.from_json(@json)
> -      templ.should_not be_nil
> -      templ.should serialize_to @xml, :fmt => :xml
> -    end
> -
> -    it "should have default properties" do
> -      templ = CIMI::Model::MachineTemplate.from_json(@json)
> -      templ.created.should == "2011-11-01"
> -      templ.name.should == "My First Template"
> -      templ.description.should == "A template for testing"
> -      templ.uri.should == "http://cimi.example.org/machine_templates/1"
> -    end
> -
> -    it "should convert strings in keys to symbols when contructed from XML" do
> -      templ = CIMI::Model::MachineTemplate.from_json(@json)
> -      templ.should_not be_nil
> -      templ.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) }
> -    end
> -
> -    it "should reference machine_config" do
> -      templ = CIMI::Model::MachineTemplate.from_json(@json)
> -      templ.machine_config.should be_an_instance_of Struct::CIMI_MachineConfig
> -      templ.machine_config.href.should == "http://cimi.example.org/machine_configs/1"
> -    end
> -
> -    it "should reference machine_image" do
> -      templ = CIMI::Model::MachineTemplate.from_json(@json)
> -      templ.machine_image.should be_an_instance_of Struct::CIMI_MachineImage
> -      templ.machine_image.href.should == "http://cimi.example.org/machine_images/1"
> -    end
> -
> -    it "should have list of attached volumes" do
> -      templ = CIMI::Model::MachineTemplate.from_json(@json)
> -      templ.volumes.should be_a_kind_of Array
> -      templ.volumes.each do |volume|
> -        volume.href.should =~ /^http:\/\/.*\/volumes\/(\w+)$/
> -        volume.protocol.should == 'nfs'
> -        volume.attachment_point == '/dev/sda'
> -        volume.should be_an_instance_of Struct::CIMI_Volume
> -      end
> -    end
> -
> -    it "should have list of network interfaces" do
> -      templ = CIMI::Model::MachineTemplate.from_json(@json)
> -      templ.network_interfaces.should be_an_instance_of Array
> -      templ.network_interfaces.each do |interface|
> -        interface.hostname == 'host.cimi.example.org'
> -        interface.mac_address == '00:11:22:33:44:55'
> -        interface.state == 'UP'
> -        interface.protocol == 'TCP'
> -        interface.allocation == 'static'
> -        interface.address == '192.168.0.17'
> -        interface.default_gateway == '192.168.0.1'
> -        interface.dns == '192.168.0.1'
> -        interface.max_transmission_unit == '1500'
> -        interface.vsp.should_not be_nil
> -        interface.vsp.should be_an_instance_of Struct::CIMI_Vsp
> -        interface.vsp.href.should =~ /^http:\/\/.*\/vsps\/(\w+)$/
> -        interface.should be_an_instance_of Struct::CIMI_NetworkInterface
> -      end
> -    end
> -
> -    it "should have edit and delete operations" do
> -      templ = CIMI::Model::MachineTemplate.from_json(@json)
> -      templ.operations.size.should == 2
> -      templ.operations.any? { |operation| operation.rel == 'edit' }.should be_true
> -      templ.operations.any? { |operation| operation.rel == 'delete' }.should be_true
> -      templ.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
> -    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
>    end
>  
>  end