johnreitano-savon 0.7.2.1 → 0.7.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +36 -4
- data/README.rdoc +78 -0
- data/Rakefile +15 -9
- data/lib/savon.rb +18 -20
- data/lib/savon/client.rb +60 -32
- data/lib/savon/core_ext.rb +8 -3
- data/lib/savon/core_ext/array.rb +31 -0
- data/lib/savon/core_ext/datetime.rb +1 -1
- data/lib/savon/core_ext/hash.rb +74 -50
- data/lib/savon/core_ext/net_http.rb +1 -2
- data/lib/savon/core_ext/object.rb +1 -3
- data/lib/savon/core_ext/string.rb +23 -4
- data/lib/savon/core_ext/uri.rb +3 -3
- data/lib/savon/logger.rb +56 -0
- data/lib/savon/request.rb +61 -60
- data/lib/savon/response.rb +68 -12
- data/lib/savon/soap.rb +180 -54
- data/lib/savon/wsdl.rb +77 -62
- data/lib/savon/wsdl_stream.rb +85 -0
- data/lib/savon/wsse.rb +45 -18
- data/spec/basic_spec_helper.rb +0 -1
- data/spec/endpoint_helper.rb +1 -0
- data/spec/fixtures/wsdl/xml/geotrust.xml +156 -0
- data/spec/http_stubs.rb +3 -0
- data/spec/savon/client_spec.rb +6 -2
- data/spec/savon/core_ext/array_spec.rb +19 -0
- data/spec/savon/core_ext/datetime_spec.rb +1 -1
- data/spec/savon/core_ext/hash_spec.rb +104 -64
- data/spec/savon/core_ext/object_spec.rb +1 -1
- data/spec/savon/core_ext/string_spec.rb +21 -2
- data/spec/savon/core_ext/uri_spec.rb +4 -0
- data/spec/savon/request_spec.rb +12 -8
- data/spec/savon/soap_spec.rb +141 -111
- data/spec/savon/wsdl_spec.rb +18 -0
- metadata +39 -19
- data/README.textile +0 -75
- data/spec/savon/savon_spec.rb +0 -23
data/spec/http_stubs.rb
CHANGED
@@ -21,3 +21,6 @@ FakeWeb.register_uri :get, EndpointHelper.wsdl_endpoint(:no_namespace), :body =>
|
|
21
21
|
|
22
22
|
# WSDL request returning a WSDL document with namespaced SOAP actions.
|
23
23
|
FakeWeb.register_uri :get, EndpointHelper.wsdl_endpoint(:namespaced_actions), :body => WSDLFixture.namespaced_actions
|
24
|
+
|
25
|
+
# WSDL request returning a WSDL document with geotrust SOAP actions.
|
26
|
+
FakeWeb.register_uri :get, EndpointHelper.wsdl_endpoint(:geotrust), :body => WSDLFixture.geotrust
|
data/spec/savon/client_spec.rb
CHANGED
@@ -37,7 +37,7 @@ describe Savon::Client do
|
|
37
37
|
|
38
38
|
it "should disable the Savon::WSDL when passed a method with an exclamation mark" do
|
39
39
|
@client.wsdl.enabled?.should be_true
|
40
|
-
[:
|
40
|
+
[:operations, :namespace_uri, :soap_endpoint].each do |method|
|
41
41
|
Savon::WSDL.any_instance.expects(method).never
|
42
42
|
end
|
43
43
|
|
@@ -70,8 +70,12 @@ describe Savon::Client do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
+
it "should have a call method that forwards to method_missing for SOAP actions named after existing methods" do
|
74
|
+
@client.call(:authenticate) { |soap| soap.should be_a(Savon::SOAP) }
|
75
|
+
end
|
76
|
+
|
73
77
|
it "should raise a NoMethodError when the method does not match an available SOAP action or method" do
|
74
78
|
lambda { @client.some_undefined_method }.should raise_error(NoMethodError)
|
75
79
|
end
|
76
80
|
|
77
|
-
end
|
81
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Array do
|
4
|
+
|
5
|
+
describe "to_soap_xml" do
|
6
|
+
describe "should return SOAP request compatible XML" do
|
7
|
+
it "for an Array of Hashes" do
|
8
|
+
hash, result = [{ :name => "Eve" }], "<findUser><name>Eve</name></findUser>"
|
9
|
+
hash.to_soap_xml("findUser").should == result
|
10
|
+
end
|
11
|
+
|
12
|
+
it "for an Array of Strings and other Objects" do
|
13
|
+
hash, result = [:id, :name], "<someValues>id</someValues><someValues>name</someValues>"
|
14
|
+
hash.to_soap_xml("someValues").should == result
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -3,135 +3,175 @@ require "spec_helper"
|
|
3
3
|
describe Hash do
|
4
4
|
|
5
5
|
describe "find_soap_body" do
|
6
|
-
it "
|
7
|
-
{ "soap:Envelope" => { "soap:Body" => "content" } }
|
6
|
+
it "should return the content from the 'soap:Body' element" do
|
7
|
+
soap_body = { "soap:Envelope" => { "soap:Body" => "content" } }
|
8
|
+
soap_body.find_soap_body.should == "content"
|
8
9
|
end
|
9
10
|
|
10
|
-
it "
|
11
|
-
{ "some_hash" => "content" }
|
11
|
+
it "should return an empty Hash in case the 'soap:Body' element could not be found" do
|
12
|
+
soap_body = { "some_hash" => "content" }
|
13
|
+
soap_body.find_soap_body.should == {}
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
15
17
|
describe "to_soap_xml" do
|
16
|
-
describe "
|
18
|
+
describe "should return SOAP request compatible XML" do
|
17
19
|
it "for a simple Hash" do
|
18
|
-
{ :some => "user" }
|
20
|
+
hash, result = { :some => "user" }, "<some>user</some>"
|
21
|
+
hash.to_soap_xml.should == result
|
19
22
|
end
|
20
23
|
|
21
24
|
it "for a nested Hash" do
|
22
|
-
{ :some => { :new => "user" } }
|
23
|
-
|
25
|
+
hash, result = { :some => { :new => "user" } }, "<some><new>user</new></some>"
|
26
|
+
hash.to_soap_xml.should == result
|
24
27
|
end
|
25
28
|
|
26
29
|
it "for a Hash with multiple keys" do
|
27
|
-
|
28
|
-
|
29
|
-
soap_xml.should include("<all>users</all>")
|
30
|
-
soap_xml.should include("<before>whatever</before>")
|
30
|
+
hash = { :all => "users", :before => "whatever" }
|
31
|
+
hash.to_soap_xml.should include("<all>users</all>", "<before>whatever</before>")
|
31
32
|
end
|
32
33
|
|
33
34
|
it "for a Hash containing an Array" do
|
34
|
-
{ :some => ["user", "gorilla"] }
|
35
|
-
|
35
|
+
hash, result = { :some => ["user", "gorilla"] }, "<some>user</some><some>gorilla</some>"
|
36
|
+
hash.to_soap_xml.should == result
|
36
37
|
end
|
37
38
|
|
38
39
|
it "for a Hash containing an Array of Hashes" do
|
39
|
-
{ :some => [{ :new => "user" }, { :old => "gorilla" }] }
|
40
|
-
|
40
|
+
hash = { :some => [{ :new => "user" }, { :old => "gorilla" }] }
|
41
|
+
result = "<some><new>user</new></some><some><old>gorilla</old></some>"
|
42
|
+
|
43
|
+
hash.to_soap_xml.should == result
|
41
44
|
end
|
42
45
|
end
|
43
46
|
|
44
|
-
it "
|
45
|
-
{ :find_or_create => "user" }
|
46
|
-
|
47
|
+
it "should convert Hash key Symbols to lowerCamelCase" do
|
48
|
+
hash, result = { :find_or_create => "user" }, "<findOrCreate>user</findOrCreate>"
|
49
|
+
hash.to_soap_xml.should == result
|
47
50
|
end
|
48
51
|
|
49
|
-
it "
|
50
|
-
{ "find_or_create" => "user" }
|
51
|
-
|
52
|
+
it "should not convert Hash key Strings" do
|
53
|
+
hash, result = { "find_or_create" => "user" }, "<find_or_create>user</find_or_create>"
|
54
|
+
hash.to_soap_xml.should == result
|
52
55
|
end
|
53
56
|
|
54
|
-
it "
|
55
|
-
{ :before => DateTime.new(2012, 03, 22, 16, 22, 33) }
|
56
|
-
|
57
|
+
it "should convert DateTime objects to xs:dateTime compliant Strings" do
|
58
|
+
hash = { :before => DateTime.new(2012, 03, 22, 16, 22, 33) }
|
59
|
+
result = "<before>2012-03-22T16:22:33Z</before>"
|
60
|
+
|
61
|
+
hash.to_soap_xml.should == result
|
57
62
|
end
|
58
63
|
|
59
|
-
it "
|
64
|
+
it "should convert Objects responding to to_datetime to xs:dateTime compliant Strings" do
|
60
65
|
singleton = Object.new
|
61
66
|
def singleton.to_datetime
|
62
67
|
DateTime.new(2012, 03, 22, 16, 22, 33)
|
63
68
|
end
|
64
69
|
|
65
|
-
{ :before => singleton }
|
66
|
-
|
70
|
+
hash, result = { :before => singleton }, "<before>2012-03-22T16:22:33Z</before>"
|
71
|
+
hash.to_soap_xml.should == result
|
67
72
|
end
|
68
73
|
|
69
|
-
it "
|
74
|
+
it "should call to_s on Strings even if they respond to to_datetime" do
|
70
75
|
object = "gorilla"
|
71
|
-
object.expects(:to_s).returns object
|
72
76
|
object.expects(:to_datetime).never
|
73
77
|
|
74
|
-
{ :name => object }
|
78
|
+
hash, result = { :name => object }, "<name>gorilla</name>"
|
79
|
+
hash.to_soap_xml.should == result
|
75
80
|
end
|
76
81
|
|
77
|
-
it "call to_s on any other Object" do
|
82
|
+
it "should call to_s on any other Object" do
|
78
83
|
[666, true, false, nil].each do |object|
|
79
84
|
{ :some => object }.to_soap_xml.should == "<some>#{object}</some>"
|
80
85
|
end
|
81
86
|
end
|
82
87
|
|
83
|
-
it "
|
84
|
-
{ :find_user => { :name => "Lucy", :id => 666,
|
85
|
-
|
88
|
+
it "should preserve the order of Hash keys and values specified through :order!" do
|
89
|
+
hash = { :find_user => { :name => "Lucy", :id => 666, :order! => [:id, :name] } }
|
90
|
+
result = "<findUser><id>666</id><name>Lucy</name></findUser>"
|
91
|
+
hash.to_soap_xml.should == result
|
92
|
+
|
93
|
+
hash = { :find_user => { :mname => "in the", :lname => "Sky", :fname => "Lucy", :order! => [:fname, :mname, :lname] } }
|
94
|
+
result = "<findUser><fname>Lucy</fname><mname>in the</mname><lname>Sky</lname></findUser>"
|
95
|
+
hash.to_soap_xml.should == result
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should raise an error if the :order! Array does not match the Hash keys" do
|
99
|
+
hash = { :name => "Lucy", :id => 666, :order! => [:name] }
|
100
|
+
lambda { hash.to_soap_xml }.should raise_error(ArgumentError)
|
86
101
|
|
87
|
-
|
88
|
-
|
89
|
-
"<findUser><byName><fname>Lucy</fname><mname>in the</mname><lname>Sky</lname></byName></findUser>"
|
102
|
+
hash = { :by_name => { :name => "Lucy", :lname => "Sky", :order! => [:mname, :name] } }
|
103
|
+
lambda { hash.to_soap_xml }.should raise_error(ArgumentError)
|
90
104
|
end
|
91
105
|
|
92
|
-
it "
|
93
|
-
|
94
|
-
|
106
|
+
it "should add attributes to Hash keys specified through :attributes!" do
|
107
|
+
hash = { :find_user => { :person => "Lucy", :attributes! => { :person => { :id => 666 } } } }
|
108
|
+
result = '<findUser><person id="666">Lucy</person></findUser>'
|
109
|
+
hash.to_soap_xml.should == result
|
110
|
+
|
111
|
+
hash = { :find_user => { :person => "Lucy", :attributes! => { :person => { :id => 666, :city => "Hamburg" } } } }
|
112
|
+
soap_xml = hash.to_soap_xml
|
113
|
+
soap_xml.should include('id="666"', 'city="Hamburg"')
|
114
|
+
end
|
95
115
|
|
96
|
-
|
97
|
-
|
116
|
+
it "should add attributes to duplicate Hash keys specified through :attributes!" do
|
117
|
+
hash = { :find_user => { :person => ["Lucy", "Anna"], :attributes! => { :person => { :id => [1, 3] } } } }
|
118
|
+
result = '<findUser><person id="1">Lucy</person><person id="3">Anna</person></findUser>'
|
119
|
+
hash.to_soap_xml.should == result
|
120
|
+
|
121
|
+
hash = { :find_user => { :person => ["Lucy", "Anna"], :attributes! => { :person => { :active => "true" } } } }
|
122
|
+
result = '<findUser><person active="true">Lucy</person><person active="true">Anna</person></findUser>'
|
123
|
+
hash.to_soap_xml.should == result
|
98
124
|
end
|
99
125
|
end
|
100
126
|
|
101
127
|
describe "map_soap_response" do
|
102
|
-
it "
|
103
|
-
{ "userResponse" => { "accountStatus" => "active" } }
|
104
|
-
|
128
|
+
it "should convert Hash key Strings to snake_case Symbols" do
|
129
|
+
soap_response = { "userResponse" => { "accountStatus" => "active" } }
|
130
|
+
result = { :user_response => { :account_status => "active" } }
|
131
|
+
|
132
|
+
soap_response.map_soap_response.should == result
|
105
133
|
end
|
106
134
|
|
107
|
-
it "
|
108
|
-
{ "ns:userResponse" => { "ns2:id" => "666" } }
|
109
|
-
|
135
|
+
it "should strip namespaces from Hash keys" do
|
136
|
+
soap_response = { "ns:userResponse" => { "ns2:id" => "666" } }
|
137
|
+
result = { :user_response => { :id => "666" } }
|
138
|
+
|
139
|
+
soap_response.map_soap_response.should == result
|
110
140
|
end
|
111
141
|
|
112
|
-
it "
|
113
|
-
{ "response" => [{ "name" => "dude" }, { "name" => "gorilla" }] }
|
114
|
-
|
142
|
+
it "should convert Hash keys and values in Arrays" do
|
143
|
+
soap_response = { "response" => [{ "name" => "dude" }, { "name" => "gorilla" }] }
|
144
|
+
result = { :response=> [{ :name => "dude" }, { :name => "gorilla" }] }
|
145
|
+
|
146
|
+
soap_response.map_soap_response.should == result
|
115
147
|
end
|
116
148
|
|
117
|
-
it "
|
118
|
-
{ "userResponse" => { "xsi:nil" => "true" } }
|
119
|
-
|
149
|
+
it "should convert xsi:nil values to nil Objects" do
|
150
|
+
soap_response = { "userResponse" => { "xsi:nil" => "true" } }
|
151
|
+
result = { :user_response => nil }
|
152
|
+
|
153
|
+
soap_response.map_soap_response.should == result
|
120
154
|
end
|
121
155
|
|
122
|
-
it "
|
123
|
-
{ "response" => { "at" => "2012-03-22T16:22:33" } }
|
124
|
-
|
156
|
+
it "should convert Hash values matching the xs:dateTime format into DateTime Objects" do
|
157
|
+
soap_response = { "response" => { "at" => "2012-03-22T16:22:33" } }
|
158
|
+
result = { :response => { :at => DateTime.new(2012, 03, 22, 16, 22, 33) } }
|
159
|
+
|
160
|
+
soap_response.map_soap_response.should == result
|
125
161
|
end
|
126
162
|
|
127
|
-
it "
|
128
|
-
{ "response" => { "active" => "false" } }
|
129
|
-
|
163
|
+
it "should convert Hash values matching 'true' to TrueClass" do
|
164
|
+
soap_response = { "response" => { "active" => "false" } }
|
165
|
+
result = { :response => { :active => false } }
|
166
|
+
|
167
|
+
soap_response.map_soap_response.should == result
|
130
168
|
end
|
131
169
|
|
132
|
-
it "
|
133
|
-
{ "response" => { "active" => "true" } }
|
134
|
-
|
170
|
+
it "should convert Hash values matching 'false' to FalseClass" do
|
171
|
+
soap_response = { "response" => { "active" => "true" } }
|
172
|
+
result = { :response => { :active => true } }
|
173
|
+
|
174
|
+
soap_response.map_soap_response.should == result
|
135
175
|
end
|
136
176
|
end
|
137
177
|
|
@@ -29,7 +29,7 @@ describe Object do
|
|
29
29
|
DateTime.new(2012, 03, 22, 16, 22, 33)
|
30
30
|
end
|
31
31
|
|
32
|
-
singleton.to_soap_value.should == "2012-03-22T16:22:
|
32
|
+
singleton.to_soap_value.should == "2012-03-22T16:22:33Z"
|
33
33
|
end
|
34
34
|
|
35
35
|
it "calls to_s unless the Object responds to to_datetime" do
|
@@ -30,6 +30,21 @@ describe String do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
describe "starts_with?" do
|
34
|
+
it "should return whether it starts with a given suffix" do
|
35
|
+
"authenticate".starts_with?("auth").should be_true
|
36
|
+
"authenticate".starts_with?("cate").should be_false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "ends_with?" do
|
41
|
+
it "should return whether it ends with a given suffix" do
|
42
|
+
"authenticate!".ends_with?("!").should be_true
|
43
|
+
"authenticate".ends_with?("cate").should be_true
|
44
|
+
"authenticate".ends_with?("?").should be_false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
33
48
|
describe "strip_namespace" do
|
34
49
|
it "strips the namespace from a namespaced String" do
|
35
50
|
"ns:customer".strip_namespace.should == "customer"
|
@@ -60,8 +75,12 @@ describe String do
|
|
60
75
|
end
|
61
76
|
|
62
77
|
describe "to_soap_value" do
|
63
|
-
it "
|
64
|
-
"string".to_soap_value.should == "string"
|
78
|
+
it "should return the string value and escape special characters" do
|
79
|
+
"string".to_soap_value.should == "string"
|
80
|
+
"<tag>".to_soap_value.should == "<tag>"
|
81
|
+
"at&t".to_soap_value.should == "at&t"
|
82
|
+
'"quotes"'.to_soap_value.should == ""quotes""
|
83
|
+
"'apos'".to_soap_value.should == "'apos'"
|
65
84
|
end
|
66
85
|
end
|
67
86
|
|
data/spec/savon/request_spec.rb
CHANGED
@@ -4,10 +4,8 @@ describe Savon::Request do
|
|
4
4
|
before { @request = Savon::Request.new EndpointHelper.wsdl_endpoint }
|
5
5
|
|
6
6
|
it "contains the ContentType for each supported SOAP version" do
|
7
|
-
|
8
|
-
|
9
|
-
Savon::Request::ContentType[soap_version].should_not be_empty
|
10
|
-
end
|
7
|
+
content_type = { 1 => "text/xml;charset=UTF-8", 2 => "application/soap+xml;charset=UTF-8" }
|
8
|
+
content_type.each { |version, type| Savon::Request::ContentType[version].should == type }
|
11
9
|
end
|
12
10
|
|
13
11
|
# defaults to log request and response. disabled for spec execution
|
@@ -24,8 +22,8 @@ describe Savon::Request do
|
|
24
22
|
end
|
25
23
|
|
26
24
|
it "has both getter and setter for the logger to use (global setting)" do
|
27
|
-
Savon::Request.logger =
|
28
|
-
Savon::Request.logger.should
|
25
|
+
Savon::Request.logger = {}
|
26
|
+
Savon::Request.logger.should be_a(Hash)
|
29
27
|
Savon::Request.logger = Logger.new STDOUT
|
30
28
|
end
|
31
29
|
|
@@ -78,12 +76,18 @@ describe Savon::Request do
|
|
78
76
|
end
|
79
77
|
|
80
78
|
it "executes a SOAP request and returns the Net::HTTP response" do
|
81
|
-
|
82
|
-
|
79
|
+
operation = WSDLFixture.authentication(:operations)[:authenticate]
|
80
|
+
action, input = operation[:action], operation[:input]
|
81
|
+
soap = Savon::SOAP.new action, input, EndpointHelper.soap_endpoint
|
83
82
|
soap_response = @request.soap soap
|
84
83
|
|
85
84
|
soap_response.should be_a(Net::HTTPResponse)
|
86
85
|
soap_response.body.should == ResponseFixture.authentication
|
87
86
|
end
|
88
87
|
|
88
|
+
it "should not include host when creating HTTP requests" do
|
89
|
+
request = @request.send(:request, :wsdl)
|
90
|
+
request.path.should_not include("example.com")
|
91
|
+
end
|
92
|
+
|
89
93
|
end
|
data/spec/savon/soap_spec.rb
CHANGED
@@ -2,170 +2,200 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Savon::SOAP do
|
4
4
|
before do
|
5
|
-
@
|
6
|
-
@
|
5
|
+
@operation = WSDLFixture.authentication(:operations)[:authenticate]
|
6
|
+
@action, @input = @operation[:action], @operation[:input]
|
7
|
+
@soap = Savon::SOAP.new @action, @input, EndpointHelper.soap_endpoint
|
7
8
|
end
|
8
9
|
|
9
|
-
it "
|
10
|
-
Savon::
|
11
|
-
Savon::SOAP::
|
12
|
-
Savon::SOAP::
|
10
|
+
it "should contain the SOAP namespace for each supported SOAP version" do
|
11
|
+
Savon::SOAP::Versions.each do |soap_version|
|
12
|
+
Savon::SOAP::Namespace[soap_version].should be_a(String)
|
13
|
+
Savon::SOAP::Namespace[soap_version].should_not be_empty
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
|
-
it "
|
17
|
-
Savon::
|
17
|
+
it "should contain the Content-Types for each supported SOAP version" do
|
18
|
+
Savon::SOAP::Versions.each do |soap_version|
|
18
19
|
Savon::SOAP::ContentType[soap_version].should be_a(String)
|
19
20
|
Savon::SOAP::ContentType[soap_version].should_not be_empty
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
|
-
it "
|
24
|
-
Savon::SOAP.
|
24
|
+
it "should contain an Array of supported SOAP versions" do
|
25
|
+
Savon::SOAP::Versions.should be_an(Array)
|
26
|
+
Savon::SOAP::Versions.should_not be_empty
|
25
27
|
end
|
26
28
|
|
27
|
-
it "
|
28
|
-
|
29
|
-
|
30
|
-
Savon::SOAP.version.should == soap_version
|
31
|
-
end
|
32
|
-
end
|
29
|
+
it "should contain the xs:dateTime format" do
|
30
|
+
Savon::SOAP::DateTimeFormat.should be_a(String)
|
31
|
+
Savon::SOAP::DateTimeFormat.should_not be_empty
|
33
32
|
|
34
|
-
|
35
|
-
|
33
|
+
DateTime.new(2012, 03, 22, 16, 22, 33).strftime(Savon::SOAP::DateTimeFormat).
|
34
|
+
should == "2012-03-22T16:22:33Z"
|
36
35
|
end
|
37
36
|
|
38
|
-
it "
|
39
|
-
|
40
|
-
|
41
|
-
@soap.action = "someAction"
|
42
|
-
@soap.action.should == "someAction"
|
37
|
+
it "should contain a Regexp matching the xs:dateTime format" do
|
38
|
+
Savon::SOAP::DateTimeRegexp.should be_a(Regexp)
|
39
|
+
(Savon::SOAP::DateTimeRegexp === "2012-03-22T16:22:33").should be_true
|
43
40
|
end
|
44
41
|
|
45
|
-
it "
|
46
|
-
|
42
|
+
it "should default to SOAP 1.1" do
|
43
|
+
Savon::SOAP.version.should == 1
|
47
44
|
end
|
48
45
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
describe "xml returned via to_xml" do
|
47
|
+
before do
|
48
|
+
@xml_declaration = '<?xml version="1.0" encoding="UTF-8"?>'
|
49
|
+
@namespace = { "xmlns:ns" => "http://example.com" }
|
50
|
+
@namespace_string = 'xmlns:ns="http://example.com"'
|
51
|
+
@namespaces = { "xmlns:ns" => "http://ns.example.com", "xmlns:ns2" => "http://ns2.example.com" }
|
52
|
+
|
53
|
+
# reset to defaults
|
54
|
+
Savon::SOAP.version = 1
|
55
|
+
Savon::SOAP.header = {}
|
56
|
+
Savon::SOAP.namespaces = {}
|
57
|
+
end
|
53
58
|
|
54
|
-
|
55
|
-
|
59
|
+
it "should contain an xml declaration" do
|
60
|
+
@soap.to_xml.should include(@xml_declaration)
|
61
|
+
end
|
56
62
|
|
57
|
-
|
58
|
-
@soap.header.should be_a(Hash)
|
59
|
-
@soap.header.should be_empty
|
63
|
+
# namespaces
|
60
64
|
|
61
|
-
|
62
|
-
|
63
|
-
|
65
|
+
it "should contain the namespace for SOAP 1.1" do
|
66
|
+
@soap.to_xml.should include('xmlns:env="' + Savon::SOAP::Namespace[1] + '"')
|
67
|
+
end
|
64
68
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
+
it "should contain the namespace for SOAP 1.2 when defined globally" do
|
70
|
+
Savon::SOAP.version = 2
|
71
|
+
@soap.to_xml.should include('xmlns:env="' + Savon::SOAP::Namespace[2] + '"')
|
72
|
+
end
|
69
73
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
74
|
+
it "should contain the namespace for SOAP 1.2 when defined per request" do
|
75
|
+
@soap.version = 2
|
76
|
+
@soap.to_xml.should include('xmlns:env="' + Savon::SOAP::Namespace[2] + '"')
|
77
|
+
end
|
75
78
|
|
76
|
-
|
77
|
-
|
78
|
-
@soap.
|
79
|
+
it "should containg a xmlns:wsdl namespace defined via the :namespace shortcut method" do
|
80
|
+
@soap.namespace = "http://wsdl.example.com"
|
81
|
+
@soap.to_xml.should include('xmlns:wsdl="http://wsdl.example.com"')
|
79
82
|
end
|
80
83
|
|
81
|
-
it "
|
82
|
-
|
83
|
-
@soap.
|
84
|
+
it "should accept custom namespaces when defined globally" do
|
85
|
+
Savon::SOAP.namespaces = @namespace
|
86
|
+
@soap.to_xml.should include("<env:Envelope " + @namespace_string)
|
84
87
|
end
|
85
|
-
end
|
86
88
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
89
|
+
it "should accept custom namespaces when defined per request" do
|
90
|
+
@soap.namespaces = @namespace
|
91
|
+
@soap.to_xml.should include("<env:Envelope " + @namespace_string)
|
92
|
+
end
|
91
93
|
|
92
|
-
|
93
|
-
|
94
|
+
it "should merge global and per request namespaces" do
|
95
|
+
Savon::SOAP.namespaces = @namespaces
|
96
|
+
@soap.namespaces = @namespace
|
97
|
+
@soap.to_xml.should include(
|
98
|
+
'xmlns:ns="http://example.com"',
|
99
|
+
'xmlns:ns2="http://ns2.example.com"'
|
100
|
+
)
|
101
|
+
end
|
94
102
|
|
95
|
-
|
96
|
-
@soap.namespaces.should == { "xmlns:env" => "http://schemas.xmlsoap.org/soap/envelope/" }
|
103
|
+
# header
|
97
104
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
105
|
+
it "should not contain a header tag unless specified" do
|
106
|
+
@soap.to_xml.should_not include("<env:Header>")
|
107
|
+
end
|
102
108
|
|
103
|
-
|
104
|
-
|
109
|
+
it "should accept a custom (String) header defined globally" do
|
110
|
+
Savon::SOAP.header = "<key>value</key>"
|
111
|
+
@soap.to_xml.should include("<env:Header><key>value</key></env:Header>")
|
112
|
+
end
|
105
113
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
114
|
+
it "should accept a custom (Hash) header defined globally" do
|
115
|
+
Savon::SOAP.header[:key] = "value"
|
116
|
+
@soap.to_xml.should include("<env:Header><key>value</key></env:Header>")
|
117
|
+
end
|
110
118
|
|
111
|
-
|
112
|
-
|
113
|
-
|
119
|
+
it "should accept a custom (String) header defined per request" do
|
120
|
+
@soap.header = "<key>value</key>"
|
121
|
+
@soap.to_xml.should include("<env:Header><key>value</key></env:Header>")
|
122
|
+
end
|
114
123
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
124
|
+
it "should accept a custom (Hash) header defined per request" do
|
125
|
+
@soap.header[:key] = "value"
|
126
|
+
@soap.to_xml.should include("<env:Header><key>value</key></env:Header>")
|
127
|
+
end
|
119
128
|
|
120
|
-
|
121
|
-
|
129
|
+
it "should merge global and per request headers defined as Strings" do
|
130
|
+
Savon::SOAP.header = "<key2>other value</key2>"
|
131
|
+
@soap.header = "<key>value</key>"
|
132
|
+
@soap.to_xml.should include(
|
133
|
+
"<env:Header><key2>other value</key2><key>value</key></env:Header>"
|
134
|
+
)
|
135
|
+
end
|
122
136
|
|
123
|
-
it "
|
124
|
-
|
125
|
-
@soap.
|
137
|
+
it "should merge global and per request headers defined as Hashes" do
|
138
|
+
Savon::SOAP.header = { :key => "value", :key2 => "global value" }
|
139
|
+
@soap.header[:key2] = "request value"
|
140
|
+
@soap.to_xml.should include(
|
141
|
+
"<env:Header><key>value</key><key2>request value</key2></env:Header>"
|
142
|
+
)
|
143
|
+
end
|
126
144
|
|
127
|
-
|
128
|
-
|
129
|
-
|
145
|
+
it "should use the :header method from a given WSSE object to include a WSSE header" do
|
146
|
+
wsse = "some compliant object"
|
147
|
+
wsse.stubs(:header).returns("<wsse>authentication</wsse>")
|
148
|
+
|
149
|
+
@soap.wsse = wsse
|
150
|
+
@soap.to_xml.should include("<env:Header><wsse>authentication</wsse></env:Header>")
|
130
151
|
end
|
131
152
|
|
132
|
-
|
133
|
-
|
153
|
+
# input tag
|
154
|
+
|
155
|
+
it "should contain a :wsdl namespaced input tag matching the :input property on instantiation" do
|
156
|
+
@soap = Savon::SOAP.new "someAction", "someInput", EndpointHelper.soap_endpoint
|
157
|
+
@soap.to_xml.should include('<wsdl:someInput>')
|
134
158
|
end
|
135
159
|
|
136
|
-
it "
|
137
|
-
@soap
|
138
|
-
@soap.to_xml.should include(
|
160
|
+
it "should fall back to using the :action property whem :input is blank" do
|
161
|
+
@soap = Savon::SOAP.new "someAction", "", EndpointHelper.soap_endpoint
|
162
|
+
@soap.to_xml.should include('<wsdl:someAction>')
|
139
163
|
end
|
140
164
|
|
141
|
-
it "
|
142
|
-
|
143
|
-
@soap
|
165
|
+
it "should containg namespaces defined via an input tag Array containing the tag name and a Hash of namespaces" do
|
166
|
+
input = ["someInput", { "otherNs" => "http://otherns.example.com" }]
|
167
|
+
@soap = Savon::SOAP.new "someAction", input, EndpointHelper.soap_endpoint
|
168
|
+
@soap.to_xml.should include('<wsdl:someInput otherNs="http://otherns.example.com">')
|
144
169
|
end
|
145
170
|
|
146
|
-
|
147
|
-
|
148
|
-
|
171
|
+
# xml body
|
172
|
+
|
173
|
+
it "should contain the SOAP body defined as a Hash" do
|
174
|
+
@soap.body = { :someTag => "some value" }
|
175
|
+
@soap.to_xml.should include("<someTag>some value</someTag>")
|
176
|
+
end
|
149
177
|
|
150
|
-
|
151
|
-
@soap.
|
178
|
+
it "should contain the SOAP body defined as an Object responding to :to_s" do
|
179
|
+
@soap.body = "<someTag>some value</someTag>"
|
180
|
+
@soap.to_xml.should include(@soap.body)
|
152
181
|
end
|
153
182
|
|
154
|
-
|
155
|
-
Savon::SOAP.header = "<API-KEY>secret</API-KEY>"
|
156
|
-
@soap.header = "<SOME-KEY>somethingelse</SOME-KEY>"
|
183
|
+
# xml
|
157
184
|
|
158
|
-
|
159
|
-
@soap.
|
185
|
+
it "should be a completely custom XML when specified" do
|
186
|
+
@soap.xml = "custom SOAP body"
|
187
|
+
@soap.to_xml.should == @soap.xml
|
160
188
|
end
|
161
189
|
|
162
|
-
|
163
|
-
Savon::SOAP.namespaces = { "xmlns:wsdl" => "namespace", "xmlns:v1" => "v1namespace" }
|
164
|
-
@soap.namespaces["xmlns:v1"] = "newV1namespace"
|
190
|
+
# safety check
|
165
191
|
|
166
|
-
|
167
|
-
@soap.to_xml.should include(
|
192
|
+
it "should be a valid SOAP request" do
|
193
|
+
@soap.to_xml.should include(
|
194
|
+
@xml_declaration +
|
195
|
+
'<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">' <<
|
196
|
+
'<env:Body><wsdl:authenticate></wsdl:authenticate></env:Body>' <<
|
197
|
+
'</env:Envelope>'
|
198
|
+
)
|
168
199
|
end
|
169
200
|
end
|
170
|
-
|
171
|
-
end
|
201
|
+
end
|