incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1202679 - in /incubator/deltacloud/trunk/server/spec/cimi/model: machine_configuration_spec.rb machine_image_spec.rb machine_template_spec.rb
Date Wed, 16 Nov 2011 12:50:31 GMT
Author: mfojtik
Date: Wed Nov 16 12:50:31 2011
New Revision: 1202679

URL: http://svn.apache.org/viewvc?rev=1202679&view=rev
Log:
CIMI: Divided the rspec test to smaller chunks in order to do more atomic tests instead of
having one failure blocking rest of test case

Modified:
    incubator/deltacloud/trunk/server/spec/cimi/model/machine_configuration_spec.rb
    incubator/deltacloud/trunk/server/spec/cimi/model/machine_image_spec.rb
    incubator/deltacloud/trunk/server/spec/cimi/model/machine_template_spec.rb

Modified: incubator/deltacloud/trunk/server/spec/cimi/model/machine_configuration_spec.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/spec/cimi/model/machine_configuration_spec.rb?rev=1202679&r1=1202678&r2=1202679&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/spec/cimi/model/machine_configuration_spec.rb (original)
+++ incubator/deltacloud/trunk/server/spec/cimi/model/machine_configuration_spec.rb Wed Nov
16 12:50:31 2011
@@ -20,59 +20,97 @@ 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
-    conf.name.should == 'MachineConfiguration1'
-    conf.uri == 'http://cimi.example.org/machine_configurations/1'
-    conf.description == 'Example MachineConfiguration One'
-    conf.created.should == "2011-11-14"
-    conf.cpu.should == "2"
-    conf.memory.size.should == 1
-    conf.memory[0]['quantity'].should == '1'
-    conf.memory[0]['units'].should == 'gigabyte'
-    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'
-    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})$/
}
-    conf.should serialize_to @xml, :fmt => :xml
-  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 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) }
+    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
   end
 
-  it "can be constructed from JSON" do
-    conf = CIMI::Model::MachineConfiguration.from_json(@json)
-    conf.should_not be_nil
-    conf.name.should == 'MachineConfiguration1'
-    conf.uri == 'http://cimi.example.org/machine_configurations/1'
-    conf.description == 'Example MachineConfiguration One'
-    conf.created.should == "2011-11-14"
-    conf.cpu.should == "2"
-    conf.memory.size.should == 1
-    conf.memory[0]['quantity'].should == '1'
-    conf.memory[0]['units'].should == 'gigabyte'
-    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'
-    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})$/
}
-    conf.should serialize_to @json, :fmt => :json
+  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
+
   end
 end

Modified: incubator/deltacloud/trunk/server/spec/cimi/model/machine_image_spec.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/spec/cimi/model/machine_image_spec.rb?rev=1202679&r1=1202678&r2=1202679&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/spec/cimi/model/machine_image_spec.rb (original)
+++ incubator/deltacloud/trunk/server/spec/cimi/model/machine_image_spec.rb Wed Nov 16 12:50:31
2011
@@ -18,49 +18,85 @@ describe "MachineImage model" do
 
   before(:all) do
     @xml = IO::read(File::join(DATA_DIR, "machine_image.xml"))
-    @json = IO::read(File::join(DATA_DIR, "machine_template.json"))
+    @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
-    img.created.should == "2011-11-14"
-    img.name.should == "img1"
-    img.description.should == "Machine Image One"
-    img.uri.should == "http://cimi.example.org/machine_image/1"
-    img.image_location.size == 1
-    img.image_location[0]['href'].should == 'nfs://cimi.example.com/images/1.img'
-    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})$/
}
-    img.should serialize_to @xml, :fmt => :xml
+  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.size == 1
+      img.image_location[0]['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
+  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.size == 1
+      img.image_location[0]['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
   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(Symbol) }
-  end
-
-  it "can be constructed from JSON" do
-    templ = CIMI::Model::MachineTemplate.from_json(@json)
-    templ.should_not be_nil
-    templ.created.should == "2011-11-01"
-    templ.should serialize_to @json, :fmt => :json
-  end
-
-  it "should parse properties correctly in JSON" do
-    img = CIMI::Model::MachineImage.from_json(@json)
-    # TODO: Fix this
-    # 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
 end

Modified: incubator/deltacloud/trunk/server/spec/cimi/model/machine_template_spec.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/spec/cimi/model/machine_template_spec.rb?rev=1202679&r1=1202678&r2=1202679&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/spec/cimi/model/machine_template_spec.rb (original)
+++ incubator/deltacloud/trunk/server/spec/cimi/model/machine_template_spec.rb Wed Nov 16
12:50:31 2011
@@ -20,25 +20,152 @@ describe "MachineTemplate model" do
     @json = IO::read(File::join(DATA_DIR, "machine_template.json"))
   end
 
-  it "can be constructed from XML" do
-    templ = CIMI::Model::MachineTemplate.from_xml(@xml)
-    templ.should_not be_nil
-    templ.created.should == "2011-11-01"
-    templ.volumes.size.should == 1
-    templ.should serialize_to @xml, :fmt => :xml
-  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 "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(Symbol) }
   end
 
-  it "can be constructed from JSON" do
-    templ = CIMI::Model::MachineTemplate.from_json(@json)
-    templ.should_not be_nil
+  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
 
-    templ.created.should == "2011-11-01"
-    templ.should serialize_to @json, :fmt => :json
   end
+
 end



Mime
View raw message