test/test_deserialization.rb in rbvmomi-1.4.0 vs test/test_deserialization.rb in rbvmomi-1.5.0

- old
+ new

@@ -1,16 +1,15 @@ -require 'test/unit' -require 'rbvmomi' -VIM = RbVmomi::VIM unless Object.const_defined? :VIM +require 'test_helper' class DeserializationTest < Test::Unit::TestCase def setup - @soap = VIM.new(:ns => 'urn:vim25', :rev => '4.0') + conn = VIM.new(:ns => 'urn:vim25', :rev => '4.0') + @deserializer = RbVmomi::Deserializer.new conn end def check str, expected, type - got = @soap.xml2obj Nokogiri(str).root, type + got = @deserializer.deserialize Nokogiri(str).root, type assert_equal expected, got end def test_moref check <<-EOS, VIM.Folder(nil, 'ha-folder-root'), 'Folder' @@ -35,18 +34,18 @@ :dynamicProperty => [] ) check <<-EOS, obj, 'DatastoreSummary' <root> - <capacity>1000</capacity> - <accessible>1</accessible> <datastore type="Datastore">foo</datastore> + <name>baz</name> + <url>http://foo/</url> + <capacity>1000</capacity> <freeSpace>31</freeSpace> + <accessible>1</accessible> <multipleHostAccess>false</multipleHostAccess> - <name>baz</name> <type>VMFS</type> - <url>http://foo/</url> </root> EOS end def test_enum @@ -288,8 +287,94 @@ check <<-EOS, obj, 'KeyValue' <root> <key>a</key> <value>b</value> </root> + EOS + end + + def test_boolean + check "<root>1</root>", true, 'xsd:boolean' + check "<root>true</root>", true, 'xsd:boolean' + check "<root>0</root>", false, 'xsd:boolean' + check "<root>false</root>", false, 'xsd:boolean' + end + + def test_int + check "<root>5</root>", 5, 'xsd:byte' + check "<root>5</root>", 5, 'xsd:short' + check "<root>5</root>", 5, 'xsd:int' + check "<root>5</root>", 5, 'xsd:long' + end + + def test_float + obj = 1.2 + check <<-EOS, obj, 'xsd:float' +<root>1.2</root> + EOS + end + + def test_date + time_str = '2010-08-20T05:44:35.0Z' + obj = Time.parse(time_str) + check <<-EOS, obj, 'xsd:dateTime' +<root>#{time_str}</root> + EOS + end + + def test_array_mangling + obj = ["foo"] + check <<-EOS, obj, 'ArrayOfString' +<root><e>foo</e></root> + EOS + + time_str = '2010-08-20T05:44:35.0Z' + obj = [Time.parse(time_str)] + check <<-EOS, obj, 'ArrayOfDateTime' +<root><e>#{time_str}</e></root> + EOS + + obj = [1] + check <<-EOS, obj, 'ArrayOfAnyType' +<root xmlns:xsi="#{VIM::NS_XSI}"> + <e xsi:type="xsd:int">1</e> +</root> + EOS + end + + def test_propertypath + check "<root>foo</root>", "foo", 'PropertyPath' + end + + def test_methodname + check "<root>foo</root>", "foo", 'MethodName' + end + + def test_typename + check "<root>foo</root>", "foo", 'TypeName' + end + + def test_new_fields + obj = VIM::HostBlockHba( + :dynamicProperty => [], + :key => 'key-vim.host.BlockHba-vmhba0', + :device => 'vmhba0', + :bus => 0, + :status => 'unknown', + :model => 'Virtual Machine Chipset', + :driver => 'ata_piix', + :pci => '00:07.1') + + check <<-EOS, obj, "HostBlockHba" +<hostBusAdapter xsi:type="HostBlockHba"> + <key>key-vim.host.BlockHba-vmhba0</key> + <device>vmhba0</device> + <bus>0</bus> + <status>unknown</status> + <foo>bar</foo> + <model>Virtual Machine Chipset</model> + <driver>ata_piix</driver> + <pci>00:07.1</pci> +</hostBusAdapter> EOS end end