1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
require 'test_helper'
class EmitRequestTest < Test::Unit::TestCase
MO = VIM::VirtualMachine(nil, "foo")
def check desc, str, this, params
soap = VIM.new(:ns => 'urn:vim25', :rev => '4.0')
xml = Builder::XmlMarkup.new :indent => 2
soap.emit_request xml, 'root', desc, this, params
begin
assert_equal str, xml.target!
rescue MiniTest::Assertion
puts "expected:"
puts str
puts
puts "got:"
puts xml.target!
puts
raise
end
end
def test_string_array
desc = [
{
'name' => 'blah',
'is-array' => true,
'is-optional' => true,
'wsdl_type' => 'xsd:string',
}
]
check desc, <<-EOS, MO, :blah => ['a', 'b', 'c']
<root xmlns="urn:vim25">
<_this type="VirtualMachine">foo</_this>
<blah>a</blah>
<blah>b</blah>
<blah>c</blah>
</root>
EOS
end
def test_required_param
desc = [
{
'name' => 'blah',
'is-array' => false,
'is-optional' => false,
'wsdl_type' => 'xsd:string',
}
]
check desc, <<-EOS, MO, :blah => 'a'
<root xmlns="urn:vim25">
<_this type="VirtualMachine">foo</_this>
<blah>a</blah>
</root>
EOS
assert_raise RuntimeError do
check desc, <<-EOS, MO, {}
<root xmlns="urn:vim25">
<_this type="VirtualMachine">foo</_this>
</root>
EOS
end
end
def test_optional_param
desc = [
{
'name' => 'blah',
'is-array' => false,
'is-optional' => true,
'wsdl_type' => 'xsd:string',
}
]
check desc, <<-EOS, MO, {}
<root xmlns="urn:vim25">
<_this type="VirtualMachine">foo</_this>
</root>
EOS
end
def test_nil_optional_param
desc = [
{
'name' => 'blah',
'is-array' => false,
'is-optional' => true,
'wsdl_type' => 'xsd:string',
}
]
check desc, <<-EOS, MO, :blah => nil
<root xmlns="urn:vim25">
<_this type="VirtualMachine">foo</_this>
</root>
EOS
end
def test_string_key
desc = [
{
'name' => 'blah',
'is-array' => false,
'is-optional' => false,
'wsdl_type' => 'xsd:string',
}
]
check desc, <<-EOS, MO, 'blah' => 'a'
<root xmlns="urn:vim25">
<_this type="VirtualMachine">foo</_this>
<blah>a</blah>
</root>
EOS
end
def disabled_test_required_property
assert_raise RuntimeError do
VIM::AboutInfo()
end
end
end
|