ruby_vim_sdk 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/README +1 -0
  2. data/Rakefile +51 -0
  3. data/lib/ruby_vim_sdk.rb +48 -0
  4. data/lib/ruby_vim_sdk/base_type.rb +15 -0
  5. data/lib/ruby_vim_sdk/const.rb +32 -0
  6. data/lib/ruby_vim_sdk/core_types.rb +68 -0
  7. data/lib/ruby_vim_sdk/data_type.rb +14 -0
  8. data/lib/ruby_vim_sdk/enum_type.rb +12 -0
  9. data/lib/ruby_vim_sdk/ext.rb +9 -0
  10. data/lib/ruby_vim_sdk/managed_type.rb +12 -0
  11. data/lib/ruby_vim_sdk/method.rb +37 -0
  12. data/lib/ruby_vim_sdk/missing_types.rb +11 -0
  13. data/lib/ruby_vim_sdk/property.rb +49 -0
  14. data/lib/ruby_vim_sdk/server_objects.rb +2718 -0
  15. data/lib/ruby_vim_sdk/soap/deserializer.rb +301 -0
  16. data/lib/ruby_vim_sdk/soap/serializer.rb +225 -0
  17. data/lib/ruby_vim_sdk/soap/stub_adapter.rb +123 -0
  18. data/lib/ruby_vim_sdk/soap_exception.rb +12 -0
  19. data/lib/ruby_vim_sdk/typed_array.rb +9 -0
  20. data/lib/ruby_vim_sdk/types.rb +22 -0
  21. data/lib/ruby_vim_sdk/version.rb +5 -0
  22. data/lib/ruby_vim_sdk/vmodl/data_object.rb +102 -0
  23. data/lib/ruby_vim_sdk/vmodl/managed_object.rb +78 -0
  24. data/lib/ruby_vim_sdk/vmodl/method_name.rb +7 -0
  25. data/lib/ruby_vim_sdk/vmodl/property_path.rb +7 -0
  26. data/lib/ruby_vim_sdk/vmodl/type_name.rb +7 -0
  27. data/lib/ruby_vim_sdk/vmodl_helper.rb +33 -0
  28. data/lib/ruby_vim_sdk/vmomi_support.rb +280 -0
  29. data/spec/spec_helper.rb +10 -0
  30. data/spec/unit/soap/deserializer_spec.rb +206 -0
  31. data/spec/unit/soap/serializer_spec.rb +261 -0
  32. data/spec/unit/soap/stub_adapter_spec.rb +9 -0
  33. data/spec/unit/vmodl/data_object_spec.rb +9 -0
  34. data/spec/unit/vmodl/managed_object_spec.rb +9 -0
  35. data/spec/unit/vmodl_helper_spec.rb +36 -0
  36. data/spec/unit/vmomi_support_spec.rb +33 -0
  37. metadata +121 -0
@@ -0,0 +1,10 @@
1
+ # Copyright (c) 2009-2012 VMware, Inc.
2
+
3
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
4
+
5
+ require "rubygems"
6
+ require "bundler"
7
+ Bundler.setup(:default, :test)
8
+
9
+ require "rspec"
10
+ require "ruby_vim_sdk"
@@ -0,0 +1,206 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe VimSdk::Soap::SoapDeserializer do
4
+ it "should deserialize a basic object" do
5
+ test_class = Class.new(VimSdk::Vmodl::DataObject) do
6
+ @type_info = VimSdk::DataType.new("test.Test", "Test", "DataObject", "test_version", [
7
+ ["byte_test", VimSdk::SoapByte, "test_version"],
8
+ ["short_test", VimSdk::SoapShort, "test_version"],
9
+ ["long_test", VimSdk::SoapLong, "test_version"],
10
+ ["int_test", VimSdk::SoapInteger, "test_version"],
11
+ ["float_test", VimSdk::SoapFloat, "test_version"],
12
+ ["double_test", VimSdk::SoapDouble, "test_version"],
13
+ ["bool_test", VimSdk::SoapBoolean, "test_version"],
14
+ ["string_test", String, "test_version"]
15
+ ])
16
+ end
17
+ test_class.finalize
18
+
19
+ stub = mock("stub")
20
+ deserializer = VimSdk::Soap::SoapDeserializer.new(stub, "test_version")
21
+ deserializer.deserialize(VimSdk::Soap::DelegatedDocument.new, test_class, false)
22
+ parser = Nokogiri::XML::SAX::Parser.new(deserializer)
23
+ parser.parse("<test xmlns=\"urn:test\"><byte_test>1</byte_test><short_test>2</short_test>" +
24
+ "<long_test>3</long_test><int_test>4</int_test><float_test>1.0</float_test><double_test>2.0</double_test>" +
25
+ "<bool_test>true</bool_test><string_test>test value</string_test></test>")
26
+
27
+ result = deserializer.result
28
+
29
+ {
30
+ :byte_test => 1,
31
+ :short_test => 2,
32
+ :long_test => 3,
33
+ :int_test => 4,
34
+ :float_test => 1.0,
35
+ :double_test => 2.0,
36
+ :bool_test => true,
37
+ :string_test => "test value"
38
+ }.each do |key, value|
39
+ result.send(key).should == value
40
+ end
41
+ end
42
+
43
+ it "should deserialize time" do
44
+ test_class = Class.new(VimSdk::Vmodl::DataObject) do
45
+ @type_info = VimSdk::DataType.new("test.Test", "Test", "DataObject", "test_version", [
46
+ ["time_test", Time, "test_version"]
47
+ ])
48
+ end
49
+ test_class.finalize
50
+
51
+ stub = mock("stub")
52
+ deserializer = VimSdk::Soap::SoapDeserializer.new(stub, "test_version")
53
+ deserializer.deserialize(VimSdk::Soap::DelegatedDocument.new, test_class, false)
54
+ parser = Nokogiri::XML::SAX::Parser.new(deserializer)
55
+ parser.parse("<test xmlns=\"urn:test\"><time_test>2011-03-26T21:28:52Z</time_test></test>")
56
+
57
+ result = deserializer.result
58
+
59
+ {
60
+ :time_test => Time.at(1301174932)
61
+ }.each do |key, value|
62
+ result.send(key).should == value
63
+ end
64
+ end
65
+
66
+ it "should deserialize binary" do
67
+ test_class = Class.new(VimSdk::Vmodl::DataObject) do
68
+ @type_info = VimSdk::DataType.new("test.Test", "Test", "DataObject", "test_version", [
69
+ ["binary_test", VimSdk::SoapBinary, "test_version"]
70
+ ])
71
+ end
72
+ test_class.finalize
73
+
74
+ stub = mock("stub")
75
+ deserializer = VimSdk::Soap::SoapDeserializer.new(stub, "test_version")
76
+ deserializer.deserialize(VimSdk::Soap::DelegatedDocument.new, test_class, false)
77
+ parser = Nokogiri::XML::SAX::Parser.new(deserializer)
78
+ parser.parse("<test xmlns=\"urn:test\"><binary_test>c29tZSBiaW5hcnkgc3RyaW5n\n</binary_test></test>")
79
+
80
+ result = deserializer.result
81
+
82
+ {
83
+ :binary_test => "some binary string"
84
+ }.each do |key, value|
85
+ result.send(key).should == value
86
+ end
87
+ end
88
+
89
+ it "should deserialize an array" do
90
+ test_class = Class.new(VimSdk::Vmodl::DataObject) do
91
+ @type_info = VimSdk::DataType.new("test.Test", "Test", "DataObject", "test_version", [
92
+ ["array_test", String::TypedArray, "test_version"]
93
+ ])
94
+ end
95
+ test_class.finalize
96
+
97
+ stub = mock("stub")
98
+ deserializer = VimSdk::Soap::SoapDeserializer.new(stub, "test_version")
99
+ deserializer.deserialize(VimSdk::Soap::DelegatedDocument.new, test_class, false)
100
+ parser = Nokogiri::XML::SAX::Parser.new(deserializer)
101
+ parser.parse("<test xmlns=\"urn:test\"><array_test>foo</array_test><array_test>bar</array_test></test>")
102
+
103
+ result = deserializer.result
104
+
105
+ {
106
+ :array_test => ["foo", "bar"]
107
+ }.each do |key, value|
108
+ result.send(key).should == value
109
+ end
110
+ end
111
+
112
+ it "should deserialize a class" do
113
+ test_class = Class.new(VimSdk::Vmodl::DataObject) do
114
+ @type_info = VimSdk::DataType.new("test.Test", "Test", "DataObject", "test_version", [
115
+ ["class_test", VimSdk::Vmodl::TypeName, "test_version"],
116
+ ["type_name_test", VimSdk::Vmodl::TypeName, "test_version"]
117
+ ])
118
+ end
119
+ test_class.finalize
120
+
121
+ stub = mock("stub")
122
+ deserializer = VimSdk::Soap::SoapDeserializer.new(stub, "test_version")
123
+ deserializer.deserialize(VimSdk::Soap::DelegatedDocument.new, test_class, false)
124
+ parser = Nokogiri::XML::SAX::Parser.new(deserializer)
125
+ parser.parse("<test xmlns=\"urn:test\"><class_test>string</class_test>" +
126
+ "<type_name_test>DataObject</type_name_test></test>")
127
+
128
+ result = deserializer.result
129
+
130
+ {
131
+ :class_test => String,
132
+ :type_name_test => VimSdk::Vmodl::DataObject
133
+ }.each do |key, value|
134
+ result.send(key).should == value
135
+ end
136
+ end
137
+
138
+ it "should deserialize an inherited type" do
139
+ test_class = Class.new(VimSdk::Vmodl::DataObject) do
140
+ @type_info = VimSdk::DataType.new("test.Test", "Test", "DataObject", "test_version", [
141
+ ["test", String, "test_version"]
142
+ ])
143
+ end
144
+ test_class.finalize
145
+
146
+ test_class2 = Class.new(test_class) do
147
+ @type_info = VimSdk::DataType.new("test.Test2", "Test2", "test.Test", "test_version", [
148
+ ["test2", String, "test_version"]
149
+ ])
150
+ end
151
+ test_class2.finalize
152
+ VimSdk::VmomiSupport.stub!(:loaded_wsdl_type).with("urn:test", "Test2").and_return(test_class2)
153
+
154
+ stub = mock("stub")
155
+ deserializer = VimSdk::Soap::SoapDeserializer.new(stub, "test_version")
156
+ deserializer.deserialize(VimSdk::Soap::DelegatedDocument.new, test_class, false)
157
+ parser = Nokogiri::XML::SAX::Parser.new(deserializer)
158
+ parser.parse("<test xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:test\" xsi:type=\"Test2\"><test>foo</test><test2>bar</test2></test>")
159
+
160
+ result = deserializer.result
161
+
162
+ {
163
+ :test => "foo",
164
+ :test2 => "bar"
165
+ }.each do |key, value|
166
+ result.send(key).should == value
167
+ end
168
+ end
169
+
170
+ it "should deserialize a managed object"
171
+
172
+ it "should deserialize an enum"
173
+
174
+ it "should fail to deserialize a bad boolean value"
175
+
176
+ it "should unwrap nested localized method faults" do
177
+
178
+ response = <<RESPONSE
179
+ <propSet xmlns="urn:vim25" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
180
+ <name>info.error</name>
181
+ <val xsi:type="LocalizedMethodFault">
182
+ <fault xsi:type="SystemError"><reason>Error deleting disk Device or resource busy</reason></fault>
183
+ <localizedMessage>A general system error occurred: Error deleting disk Device or resource busy</localizedMessage>
184
+ </val>
185
+ </propSet>
186
+ RESPONSE
187
+
188
+ stub = mock("stub")
189
+ deserializer = VimSdk::Soap::SoapDeserializer.new(stub, "vim.version.version6")
190
+ deserializer.deserialize(VimSdk::Soap::DelegatedDocument.new,
191
+ VimSdk::Vmodl::DynamicProperty, false)
192
+ parser = Nokogiri::XML::SAX::Parser.new(deserializer)
193
+ parser.parse(response)
194
+
195
+ result = deserializer.result
196
+ value = result.val
197
+ value.class.should == VimSdk::Vmodl::Fault::SystemError
198
+ value.msg.should == "A general system error occurred: Error deleting disk Device or resource busy"
199
+ value.reason.should == "Error deleting disk Device or resource busy"
200
+ end
201
+ end
202
+
203
+ describe VimSdk::Soap::SoapResponseDeserializer do
204
+ it "should deserialize a fault"
205
+ it "should deserialize a response"
206
+ end
@@ -0,0 +1,261 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe VimSdk::Soap::SoapSerializer do
4
+ it "should serialize a simple object" do
5
+ test_class = Class.new(VimSdk::Vmodl::DataObject) do
6
+ @type_info = VimSdk::DataType.new("test.Test", "Test", "DataObject", "test_version", [
7
+ ["byte_test", VimSdk::SoapByte, "test_version"],
8
+ ["short_test", VimSdk::SoapShort, "test_version"],
9
+ ["long_test", VimSdk::SoapLong, "test_version"],
10
+ ["int_test", VimSdk::SoapInteger, "test_version"],
11
+ ["float_test", VimSdk::SoapFloat, "test_version"],
12
+ ["double_test", VimSdk::SoapDouble, "test_version"],
13
+ ["bool_test", VimSdk::SoapBoolean, "test_version"],
14
+ ["string_test", String, "test_version"]
15
+ ])
16
+ end
17
+ test_class.finalize
18
+
19
+ VimSdk::VmomiSupport.stub!(:compatible_type).with(test_class, "test_version").and_return(test_class)
20
+ VimSdk::VmomiSupport.stub!(:wsdl_namespace).with("test_version").and_return("urn:test")
21
+
22
+ writer = StringIO.new
23
+ serializer = VimSdk::Soap::SoapSerializer.new(writer, "test_version", VimSdk::SOAP_NAMESPACE_MAP.dup)
24
+
25
+ property = VimSdk::Property.new("test", test_class, "test_version")
26
+ value = test_class.new(:byte_test => 1, :short_test => 2, :long_test => 3, :int_test => 4, :float_test => 1.0,
27
+ :double_test => 2.0, :bool_test => true, :string_test => "test value")
28
+
29
+ serializer.serialize(value, property)
30
+ writer.string.should == "<test xmlns=\"urn:test\"><byte_test>1</byte_test><short_test>2</short_test>" +
31
+ "<long_test>3</long_test><int_test>4</int_test><float_test>1.0</float_test><double_test>2.0</double_test>" +
32
+ "<bool_test>true</bool_test><string_test>test value</string_test></test>"
33
+ end
34
+
35
+ it "should serialize time" do
36
+ test_class = Class.new(VimSdk::Vmodl::DataObject) do
37
+ @type_info = VimSdk::DataType.new("test.Test", "Test", "DataObject", "test_version", [
38
+ ["time_test", Time, "test_version"]
39
+ ])
40
+ end
41
+ test_class.finalize
42
+
43
+ VimSdk::VmomiSupport.stub!(:compatible_type).with(test_class, "test_version").and_return(test_class)
44
+ VimSdk::VmomiSupport.stub!(:wsdl_namespace).with("test_version").and_return("urn:test")
45
+
46
+ writer = StringIO.new
47
+ serializer = VimSdk::Soap::SoapSerializer.new(writer, "test_version", VimSdk::SOAP_NAMESPACE_MAP.dup)
48
+
49
+ property = VimSdk::Property.new("test", test_class, "test_version")
50
+ value = test_class.new(:time_test => Time.at(1301174932))
51
+
52
+ serializer.serialize(value, property)
53
+ writer.string.should == "<test xmlns=\"urn:test\"><time_test>2011-03-26T21:28:52Z</time_test></test>"
54
+ end
55
+
56
+ it "should serialize binary" do
57
+ test_class = Class.new(VimSdk::Vmodl::DataObject) do
58
+ @type_info = VimSdk::DataType.new("test.Test", "Test", "DataObject", "test_version", [
59
+ ["binary_test", VimSdk::SoapBinary, "test_version"]
60
+ ])
61
+ end
62
+ test_class.finalize
63
+
64
+ VimSdk::VmomiSupport.stub!(:compatible_type).with(test_class, "test_version").and_return(test_class)
65
+ VimSdk::VmomiSupport.stub!(:wsdl_namespace).with("test_version").and_return("urn:test")
66
+
67
+ writer = StringIO.new
68
+ serializer = VimSdk::Soap::SoapSerializer.new(writer, "test_version", VimSdk::SOAP_NAMESPACE_MAP.dup)
69
+
70
+ property = VimSdk::Property.new("test", test_class, "test_version")
71
+ value = test_class.new(:binary_test => "some binary string")
72
+
73
+ serializer.serialize(value, property)
74
+ writer.string.should == "<test xmlns=\"urn:test\"><binary_test>c29tZSBiaW5hcnkgc3RyaW5n\n</binary_test></test>"
75
+ end
76
+
77
+ it "should serialize classes" do
78
+ test_class = Class.new(VimSdk::Vmodl::DataObject) do
79
+ @type_info = VimSdk::DataType.new("test.Test", "Test", "DataObject", "test_version", [
80
+ ["class_test", VimSdk::Vmodl::TypeName, "test_version"],
81
+ ["type_name_test", VimSdk::Vmodl::TypeName, "test_version"]
82
+ ])
83
+ end
84
+ test_class.finalize
85
+
86
+ VimSdk::VmomiSupport.stub!(:compatible_type).with(test_class, "test_version").and_return(test_class)
87
+ VimSdk::VmomiSupport.stub!(:wsdl_namespace).with("test_version").and_return("urn:test")
88
+
89
+ writer = StringIO.new
90
+ serializer = VimSdk::Soap::SoapSerializer.new(writer, "test_version", VimSdk::SOAP_NAMESPACE_MAP.dup)
91
+
92
+ property = VimSdk::Property.new("test", test_class, "test_version")
93
+ value = test_class.new(:class_test => String, :type_name_test => VimSdk::Vmodl::TypeName.new("DataObject"))
94
+
95
+ serializer.serialize(value, property)
96
+ writer.string.should == "<test xmlns=\"urn:test\"><class_test>string</class_test>" +
97
+ "<type_name_test>DataObject</type_name_test></test>"
98
+ end
99
+
100
+ it "should serialize arrays" do
101
+ test_class = Class.new(VimSdk::Vmodl::DataObject) do
102
+ @type_info = VimSdk::DataType.new("test.Test", "Test", "DataObject", "test_version", [
103
+ ["array_test", String::TypedArray, "test_version"]
104
+ ])
105
+ end
106
+ test_class.finalize
107
+
108
+ VimSdk::VmomiSupport.stub!(:compatible_type).with(test_class, "test_version").and_return(test_class)
109
+ VimSdk::VmomiSupport.stub!(:wsdl_namespace).with("test_version").and_return("urn:test")
110
+
111
+ writer = StringIO.new
112
+ serializer = VimSdk::Soap::SoapSerializer.new(writer, "test_version", VimSdk::SOAP_NAMESPACE_MAP.dup)
113
+
114
+ property = VimSdk::Property.new("test", test_class, "test_version")
115
+ value = test_class.new(:array_test => ["foo", "bar"])
116
+
117
+ serializer.serialize(value, property)
118
+ writer.string.should == "<test xmlns=\"urn:test\"><array_test>foo</array_test><array_test>bar</array_test></test>"
119
+ end
120
+
121
+ it "should serialize managed objects" do
122
+ test_managed_class = Class.new(VimSdk::Vmodl::ManagedObject) do
123
+ @type_info = VimSdk::ManagedType.new("test.ManagedTest", "ManagedTest", "ManagedObject", "test_version", [], [])
124
+ end
125
+ test_managed_class.finalize
126
+
127
+ test_class = Class.new(VimSdk::Vmodl::DataObject) do
128
+ @type_info = VimSdk::DataType.new("test.Test", "Test", "DataObject", "test_version", [
129
+ ["mob_test", test_managed_class, "test_version"]
130
+ ])
131
+ end
132
+ test_class.finalize
133
+
134
+ VimSdk::VmomiSupport.stub!(:compatible_type).with(test_class, "test_version").and_return(test_class)
135
+ VimSdk::VmomiSupport.stub!(:wsdl_namespace).with("test_version").and_return("urn:test")
136
+
137
+ writer = StringIO.new
138
+ serializer = VimSdk::Soap::SoapSerializer.new(writer, "test_version", VimSdk::SOAP_NAMESPACE_MAP.dup)
139
+
140
+ property = VimSdk::Property.new("test", test_class, "test_version")
141
+ value = test_class.new(:mob_test => test_managed_class.new("some mob id"))
142
+
143
+ serializer.serialize(value, property)
144
+ writer.string.should == "<test xmlns=\"urn:test\"><mob_test type=\"ManagedTest\">some mob id</mob_test></test>"
145
+ end
146
+
147
+ it "should serialize any type" do
148
+ test_managed_class = Class.new(VimSdk::Vmodl::ManagedObject) do
149
+ @type_info = VimSdk::ManagedType.new("test.ManagedTest", "ManagedTest", "ManagedObject", "test_version", [], [])
150
+ end
151
+ test_managed_class.finalize
152
+
153
+ test_class = Class.new(VimSdk::Vmodl::DataObject) do
154
+ @type_info = VimSdk::DataType.new("test.Test", "Test", "DataObject", "test_version", [
155
+ ["byte_test", Object, "test_version"],
156
+ ["short_test", Object, "test_version"],
157
+ ["long_test", Object, "test_version"],
158
+ ["int_test", Object, "test_version"],
159
+ ["float_test", Object, "test_version"],
160
+ ["double_test", Object, "test_version"],
161
+ ["bool_test", Object, "test_version"],
162
+ ["string_test", Object, "test_version"],
163
+ ["time_test", Object, "test_version"],
164
+ ["binary_test", Object, "test_version"],
165
+ ["mob_test", Object, "test_version"]
166
+ ])
167
+ end
168
+ test_class.finalize
169
+
170
+ VimSdk::VmomiSupport.stub!(:compatible_type).with(test_class, "test_version").and_return(test_class)
171
+ VimSdk::VmomiSupport.stub!(:wsdl_namespace).with("test_version").and_return("urn:test")
172
+
173
+ writer = StringIO.new
174
+ serializer = VimSdk::Soap::SoapSerializer.new(writer, "test_version", VimSdk::SOAP_NAMESPACE_MAP.dup)
175
+
176
+ property = VimSdk::Property.new("test", test_class, "test_version")
177
+ value = test_class.new(:byte_test => VimSdk::SoapByte.new(1), :short_test => VimSdk::SoapShort.new(2),
178
+ :long_test => VimSdk::SoapLong.new(3), :int_test => 4, :float_test => 1.0,
179
+ :double_test => VimSdk::SoapDouble.new(2.0), :bool_test => true,
180
+ :string_test => "test value", :time_test => Time.at(1301174932),
181
+ :binary_test => VimSdk::SoapBinary.new("some binary string"),
182
+ :mob_test => test_managed_class.new("some mob id"))
183
+
184
+ serializer.serialize(value, property)
185
+ writer.string.should == "<test xmlns=\"urn:test\"><byte_test xsi:type=\"xsd:byte\">1</byte_test>" +
186
+ "<short_test xsi:type=\"xsd:short\">2</short_test><long_test xsi:type=\"xsd:long\">3</long_test>" +
187
+ "<int_test xsi:type=\"xsd:int\">4</int_test><float_test xsi:type=\"xsd:float\">1.0</float_test>" +
188
+ "<double_test xsi:type=\"xsd:double\">2.0</double_test><bool_test xsi:type=\"xsd:boolean\">true</bool_test>" +
189
+ "<string_test xsi:type=\"xsd:string\">test value</string_test>" +
190
+ "<time_test xsi:type=\"xsd:dateTime\">2011-03-26T21:28:52Z</time_test>" +
191
+ "<binary_test xsi:type=\"xsd:base64Binary\">c29tZSBiaW5hcnkgc3RyaW5n\n</binary_test>" +
192
+ "<mob_test xmlns:vim25=\"urn:vim25\" xsi:type=\"vim25:ManagedObject\" type=\"ManagedTest\">" +
193
+ "some mob id</mob_test></test>"
194
+ end
195
+
196
+ it "should serialize any type array" do
197
+ test_managed_class = Class.new(VimSdk::Vmodl::ManagedObject) do
198
+ @type_info = VimSdk::ManagedType.new("test.ManagedTest", "ManagedTest", "ManagedObject", "test_version", [], [])
199
+ end
200
+ test_managed_class.finalize
201
+
202
+ test_class = Class.new(VimSdk::Vmodl::DataObject) do
203
+ @type_info = VimSdk::DataType.new("test.Test", "Test", "DataObject", "test_version", [
204
+ ["basic_test", Object, "test_version"],
205
+ ["class_test", Object, "test_version"],
206
+ ["mob_test", Object, "test_version"]
207
+ ])
208
+ end
209
+ test_class.finalize
210
+
211
+ VimSdk::VmomiSupport.stub!(:compatible_type).with(test_class, "test_version").and_return(test_class)
212
+ VimSdk::VmomiSupport.stub!(:wsdl_namespace).with("test_version").and_return("urn:test")
213
+
214
+ writer = StringIO.new
215
+ serializer = VimSdk::Soap::SoapSerializer.new(writer, "test_version", VimSdk::SOAP_NAMESPACE_MAP.dup)
216
+
217
+ property = VimSdk::Property.new("test", test_class, "test_version")
218
+ value = test_class.new(:basic_test => ["hello", "world"], :class_test => [String, Float, VimSdk::Vmodl::DataObject],
219
+ :mob_test => [test_managed_class.new("some mob id")])
220
+
221
+ serializer.serialize(value, property)
222
+ writer.string.should == "<test xmlns=\"urn:test\">" +
223
+ "<basic_test xmlns:vim25=\"urn:vim25\" xsi:type=\"vim25:ArrayOfString\"><string>hello</string>" +
224
+ "<string>world</string></basic_test><class_test xmlns:vim25=\"urn:vim25\" xsi:type=\"vim25:ArrayOfString\">" +
225
+ "<string>string</string><string>float</string><string>DataObject</string></class_test>" +
226
+ "<mob_test xmlns:vim25=\"urn:vim25\" xsi:type=\"vim25:ArrayOfManagedObject\">" +
227
+ "<ManagedObjectReference type=\"ManagedTest\">some mob id</ManagedObjectReference></mob_test></test>"
228
+ end
229
+
230
+ it "should serialize inherited types" do
231
+ test_class = Class.new(VimSdk::Vmodl::DataObject) do
232
+ @type_info = VimSdk::DataType.new("test.Test", "Test", "DataObject", "test_version", [
233
+ ["test", String, "test_version"]
234
+ ])
235
+ end
236
+ test_class.finalize
237
+
238
+ test_class2 = Class.new(test_class) do
239
+ @type_info = VimSdk::DataType.new("test.Test2", "Test2", "test.Test", "test_version", [
240
+ ["test2", String, "test_version"]
241
+ ])
242
+ end
243
+ test_class2.finalize
244
+
245
+ VimSdk::VmomiSupport.stub!(:compatible_type).with(test_class, "test_version").and_return(test_class)
246
+ VimSdk::VmomiSupport.stub!(:compatible_type).with(test_class2, "test_version").and_return(test_class2)
247
+ VimSdk::VmomiSupport.stub!(:wsdl_namespace).with("test_version").and_return("urn:test")
248
+
249
+ writer = StringIO.new
250
+ serializer = VimSdk::Soap::SoapSerializer.new(writer, "test_version", VimSdk::SOAP_NAMESPACE_MAP.dup)
251
+
252
+ property = VimSdk::Property.new("test", test_class, "test_version")
253
+ value = test_class2.new(:test => "foo", :test2 => "bar")
254
+ serializer.serialize(value, property)
255
+ writer.string.should == "<test xmlns=\"urn:test\" xsi:type=\"Test2\"><test>foo</test><test2>bar</test2></test>"
256
+ end
257
+
258
+ it "should fail serializing native ruby arrays as any type"
259
+
260
+ it "should serialize a fault"
261
+ end