savon-SU 2.11.1b

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.travis.yml +15 -0
  4. data/.yardopts +6 -0
  5. data/CHANGELOG.md +1098 -0
  6. data/CONTRIBUTING.md +46 -0
  7. data/Gemfile +18 -0
  8. data/LICENSE +20 -0
  9. data/README.md +69 -0
  10. data/Rakefile +14 -0
  11. data/donate.png +0 -0
  12. data/lib/savon.rb +27 -0
  13. data/lib/savon/block_interface.rb +26 -0
  14. data/lib/savon/builder.rb +205 -0
  15. data/lib/savon/client.rb +102 -0
  16. data/lib/savon/core_ext/string.rb +29 -0
  17. data/lib/savon/header.rb +93 -0
  18. data/lib/savon/http_error.rb +27 -0
  19. data/lib/savon/log_message.rb +52 -0
  20. data/lib/savon/message.rb +37 -0
  21. data/lib/savon/mock.rb +5 -0
  22. data/lib/savon/mock/expectation.rb +80 -0
  23. data/lib/savon/mock/spec_helper.rb +62 -0
  24. data/lib/savon/model.rb +84 -0
  25. data/lib/savon/operation.rb +144 -0
  26. data/lib/savon/options.rb +410 -0
  27. data/lib/savon/qualified_message.rb +50 -0
  28. data/lib/savon/request.rb +97 -0
  29. data/lib/savon/request_logger.rb +48 -0
  30. data/lib/savon/response.rb +113 -0
  31. data/lib/savon/soap_fault.rb +50 -0
  32. data/lib/savon/version.rb +3 -0
  33. data/savon-SU.gemspec +46 -0
  34. data/spec/fixtures/gzip/message.gz +0 -0
  35. data/spec/fixtures/response/another_soap_fault.xml +14 -0
  36. data/spec/fixtures/response/authentication.xml +14 -0
  37. data/spec/fixtures/response/f5.xml +39 -0
  38. data/spec/fixtures/response/header.xml +13 -0
  39. data/spec/fixtures/response/list.xml +18 -0
  40. data/spec/fixtures/response/multi_ref.xml +39 -0
  41. data/spec/fixtures/response/soap_fault.xml +8 -0
  42. data/spec/fixtures/response/soap_fault12.xml +18 -0
  43. data/spec/fixtures/response/soap_fault_funky.xml +8 -0
  44. data/spec/fixtures/response/taxcloud.xml +1 -0
  45. data/spec/fixtures/ssl/client_cert.pem +16 -0
  46. data/spec/fixtures/ssl/client_encrypted_key.pem +30 -0
  47. data/spec/fixtures/ssl/client_encrypted_key_cert.pem +24 -0
  48. data/spec/fixtures/ssl/client_key.pem +15 -0
  49. data/spec/fixtures/wsdl/authentication.xml +63 -0
  50. data/spec/fixtures/wsdl/betfair.xml +2981 -0
  51. data/spec/fixtures/wsdl/edialog.xml +15416 -0
  52. data/spec/fixtures/wsdl/interhome.xml +2137 -0
  53. data/spec/fixtures/wsdl/lower_camel.xml +52 -0
  54. data/spec/fixtures/wsdl/multiple_namespaces.xml +92 -0
  55. data/spec/fixtures/wsdl/multiple_types.xml +60 -0
  56. data/spec/fixtures/wsdl/no_message_tag.xml +1267 -0
  57. data/spec/fixtures/wsdl/taxcloud.xml +934 -0
  58. data/spec/fixtures/wsdl/team_software.xml +1 -0
  59. data/spec/fixtures/wsdl/vies.xml +176 -0
  60. data/spec/fixtures/wsdl/wasmuth.xml +153 -0
  61. data/spec/integration/centra_spec.rb +66 -0
  62. data/spec/integration/email_example_spec.rb +32 -0
  63. data/spec/integration/random_quote_spec.rb +23 -0
  64. data/spec/integration/ratp_example_spec.rb +28 -0
  65. data/spec/integration/stockquote_example_spec.rb +28 -0
  66. data/spec/integration/support/application.rb +82 -0
  67. data/spec/integration/support/server.rb +84 -0
  68. data/spec/integration/temperature_example_spec.rb +46 -0
  69. data/spec/integration/zipcode_example_spec.rb +42 -0
  70. data/spec/savon/builder_spec.rb +137 -0
  71. data/spec/savon/client_spec.rb +271 -0
  72. data/spec/savon/core_ext/string_spec.rb +37 -0
  73. data/spec/savon/features/message_tag_spec.rb +61 -0
  74. data/spec/savon/http_error_spec.rb +49 -0
  75. data/spec/savon/log_message_spec.rb +44 -0
  76. data/spec/savon/message_spec.rb +70 -0
  77. data/spec/savon/mock_spec.rb +174 -0
  78. data/spec/savon/model_spec.rb +182 -0
  79. data/spec/savon/observers_spec.rb +92 -0
  80. data/spec/savon/operation_spec.rb +230 -0
  81. data/spec/savon/options_spec.rb +1064 -0
  82. data/spec/savon/qualified_message_spec.rb +20 -0
  83. data/spec/savon/request_logger_spec.rb +37 -0
  84. data/spec/savon/request_spec.rb +496 -0
  85. data/spec/savon/response_spec.rb +270 -0
  86. data/spec/savon/soap_fault_spec.rb +131 -0
  87. data/spec/spec_helper.rb +30 -0
  88. data/spec/support/adapters.rb +48 -0
  89. data/spec/support/endpoint.rb +25 -0
  90. data/spec/support/fixture.rb +39 -0
  91. data/spec/support/integration.rb +9 -0
  92. data/spec/support/stdout.rb +25 -0
  93. metadata +317 -0
@@ -0,0 +1,70 @@
1
+ require "spec_helper"
2
+ require "integration/support/server"
3
+
4
+ describe Savon::Message do
5
+
6
+ before do
7
+ @server = IntegrationServer.run
8
+ end
9
+
10
+ after do
11
+ @server.stop
12
+ end
13
+
14
+ let(:client_config) {
15
+ {
16
+ :endpoint => @server.url(:repeat),
17
+ :namespace => 'http://example.com',
18
+ :log => false,
19
+
20
+ :element_form_default => :qualified,
21
+ :convert_request_keys_to => :camelcase,
22
+
23
+ :convert_response_tags_to => nil
24
+ }
25
+ }
26
+
27
+ let(:client) { Savon.client(client_config) }
28
+
29
+ context "with a qualified message" do
30
+ let(:message) {
31
+ {
32
+ :email_count => 3,
33
+ :user_name => 'josh',
34
+ :order! => [:user_name, :email_count]
35
+ }
36
+ }
37
+
38
+ let(:converted_keys) {
39
+ '<wsdl:UserName>josh</wsdl:UserName><wsdl:EmailCount>3</wsdl:EmailCount>'
40
+ }
41
+ it "converts request Hash keys for which there is not namespace" do
42
+ response = client.call(:something, :message => message)
43
+ expect(response.xml).to include(converted_keys)
44
+ end
45
+ end
46
+
47
+ context 'use_wsa_headers' do
48
+ let(:client_config) { super().merge(use_wsa_headers: true) }
49
+
50
+ context 'headers' do
51
+ [ 'wsa:Action', 'wsa:To', 'wsa:MessageID' ].each do |header|
52
+ it "should include #{header} header" do
53
+ response = client.call(:something, message: {})
54
+ expect(response.xml).to include(header)
55
+ end
56
+ end
57
+ end
58
+
59
+ context 'wsa:MessageID' do
60
+ let(:message_id_tag) {
61
+ '<wsa:MessageID xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">'
62
+ }
63
+ it 'should include xmlns:wsa attribute' do
64
+ response = client.call(:something, message: {})
65
+ expect(response.xml).to include(message_id_tag)
66
+ end
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,174 @@
1
+ require "spec_helper"
2
+ require "savon/mock/spec_helper"
3
+
4
+ describe "Savon's mock interface" do
5
+ include Savon::SpecHelper
6
+
7
+ before :all do
8
+ savon.mock!
9
+ end
10
+
11
+ after :all do
12
+ savon.unmock!
13
+ end
14
+
15
+ it "can verify a request and return a fixture response" do
16
+ message = { :username => "luke", :password => "secret" }
17
+ savon.expects(:authenticate).with(:message => message).returns("<fixture/>")
18
+
19
+ response = new_client.call(:authenticate) do
20
+ message(:username => "luke", :password => "secret")
21
+ end
22
+
23
+ expect(response.http.body).to eq("<fixture/>")
24
+ end
25
+
26
+ it "can verify a request with any parameters and return a fixture response" do
27
+ message = { :username => "luke", :password => :any }
28
+ savon.expects(:authenticate).with(:message => message).returns("<fixture/>")
29
+
30
+ response = new_client.call(:authenticate) do
31
+ message(:username => "luke", :password => "secret")
32
+ end
33
+
34
+ expect(response.http.body).to eq("<fixture/>")
35
+ end
36
+
37
+ it "accepts a Hash to specify the response code, headers and body" do
38
+ soap_fault = Fixture.response(:soap_fault)
39
+ response = { :code => 500, :headers => { "X-Result" => "invalid" }, :body => soap_fault }
40
+
41
+ savon.expects(:authenticate).returns(response)
42
+ response = new_client(:raise_errors => false).call(:authenticate)
43
+
44
+ expect(response).to_not be_successful
45
+ expect(response).to be_a_soap_fault
46
+
47
+ expect(response.http.code).to eq(500)
48
+ expect(response.http.headers).to eq("X-Result" => "invalid")
49
+ expect(response.http.body).to eq(soap_fault)
50
+ end
51
+
52
+ it "works with multiple requests" do
53
+ authentication_message = { :username => "luke", :password => "secret" }
54
+ savon.expects(:authenticate).with(:message => authentication_message).returns("")
55
+
56
+ find_user_message = { :by_username => "lea" }
57
+ savon.expects(:find_user).with(:message => find_user_message).returns("")
58
+
59
+ new_client.call(:authenticate, :message => authentication_message)
60
+ new_client.call(:find_user, :message => find_user_message)
61
+ end
62
+
63
+ it "fails when the expected operation was not called" do
64
+ # TODO: find out how to test this! [dh, 2012-12-17]
65
+ #savon.expects(:authenticate)
66
+ end
67
+
68
+ it "fails when the return value for an expectation was not specified" do
69
+ savon.expects(:authenticate)
70
+
71
+ expect { new_client.call(:authenticate) }.
72
+ to raise_error(Savon::ExpectationError, "This expectation was not set up with a response.")
73
+ end
74
+
75
+ it "fails with an unexpected request" do
76
+ expect { new_client.call(:authenticate) }.
77
+ to raise_error(Savon::ExpectationError, "Unexpected request to the :authenticate operation.")
78
+ end
79
+
80
+ it "fails with multiple requests" do
81
+ authentication_message = { :username => "luke", :password => "secret" }
82
+ savon.expects(:authenticate).with(:message => authentication_message).returns("")
83
+
84
+ create_user_message = { :username => "lea" }
85
+ savon.expects(:create_user).with(:message => create_user_message).returns("")
86
+
87
+ find_user_message = { :by_username => "lea" }
88
+ savon.expects(:find_user).with(:message => find_user_message).returns("")
89
+
90
+ # reversed order from previous spec
91
+ new_client.call(:authenticate, :message => authentication_message)
92
+
93
+ expect { new_client.call(:find_user, :message => find_user_message) }.
94
+ to raise_error(Savon::ExpectationError, "Expected a request to the :create_user operation.\n" \
95
+ "Received a request to the :find_user operation instead.")
96
+ end
97
+
98
+ it "fails when the expected SOAP operation does not match the actual one" do
99
+ savon.expects(:logout).returns("<fixture/>")
100
+
101
+ expect { new_client.call(:authenticate) }.
102
+ to raise_error(Savon::ExpectationError, "Expected a request to the :logout operation.\n" \
103
+ "Received a request to the :authenticate operation instead.")
104
+ end
105
+
106
+ it "fails when there is no actual message to match" do
107
+ message = { :username => "luke" }
108
+ savon.expects(:find_user).with(:message => message).returns("<fixture/>")
109
+
110
+ expect { new_client.call(:find_user) }.
111
+ to raise_error(Savon::ExpectationError, "Expected a request to the :find_user operation\n" \
112
+ " with this message: #{message.inspect}\n" \
113
+ "Received a request to the :find_user operation\n" \
114
+ " with no message.")
115
+ end
116
+
117
+ it "fails when there is no expect but an actual message" do
118
+ savon.expects(:find_user).returns("<fixture/>")
119
+ message = { :username => "luke" }
120
+
121
+ expect { new_client.call(:find_user, :message => message) }.
122
+ to raise_error(Savon::ExpectationError, "Expected a request to the :find_user operation\n" \
123
+ " with no message.\n" \
124
+ "Received a request to the :find_user operation\n" \
125
+ " with this message: #{message.inspect}")
126
+ end
127
+
128
+ it "does not fail when any message is expected and an actual message" do
129
+ savon.expects(:find_user).with(:message => :any).returns("<fixture/>")
130
+ message = { :username => "luke" }
131
+
132
+ expect { new_client.call(:find_user, :message => message) }.to_not raise_error
133
+ end
134
+
135
+ it "does not fail when any message is expected and no actual message" do
136
+ savon.expects(:find_user).with(:message => :any).returns("<fixture/>")
137
+
138
+ expect { new_client.call(:find_user) }.to_not raise_error
139
+ end
140
+
141
+ it "matchers can be used to specify the message" do
142
+ savon.expects(:find_user).with(:message => include(:username)).returns("<fixture/>")
143
+ message = { :username => "Han Solo", password: "querty"}
144
+
145
+ expect { new_client.call(:find_user, :message => message) }.to_not raise_error
146
+ end
147
+
148
+ it "allows code to rescue Savon::Error and still report test failures" do
149
+ message = { :username => "luke" }
150
+ savon.expects(:find_user).with(:message => message).returns("<fixture/>")
151
+
152
+ expect {
153
+ begin
154
+ new_client.call(:find_user)
155
+ rescue Savon::Error => e
156
+ puts "any real error (e.g. SOAP fault or HTTP error) is OK in the big picture, move on"
157
+ end
158
+ }.to raise_error(Savon::ExpectationError, "Expected a request to the :find_user operation\n" \
159
+ " with this message: #{message.inspect}\n" \
160
+ "Received a request to the :find_user operation\n" \
161
+ " with no message.")
162
+ end
163
+
164
+ def new_client(globals = {})
165
+ defaults = {
166
+ :endpoint => "http://example.com",
167
+ :namespace => "http://v1.example.com",
168
+ :log => false
169
+ }
170
+
171
+ Savon.client defaults.merge(globals)
172
+ end
173
+
174
+ end
@@ -0,0 +1,182 @@
1
+ require "spec_helper"
2
+ require "integration/support/server"
3
+
4
+ describe Savon::Model do
5
+
6
+ before :all do
7
+ @server = IntegrationServer.run
8
+ end
9
+
10
+ after :all do
11
+ @server.stop
12
+ end
13
+
14
+ describe ".client" do
15
+ it "returns the memoized client" do
16
+ model = Class.new {
17
+ extend Savon::Model
18
+ client :wsdl => Fixture.wsdl(:authentication)
19
+ }
20
+
21
+ expect(model.client).to be_a(Savon::Client)
22
+ expect(model.client).to equal(model.client)
23
+ end
24
+
25
+ it "raises if the client was not initialized properly" do
26
+ model = Class.new { extend Savon::Model }
27
+
28
+ expect { model.client }.
29
+ to raise_error(Savon::InitializationError, /^Expected the model to be initialized/)
30
+ end
31
+ end
32
+
33
+ describe ".global" do
34
+ it "sets global options" do
35
+ model = Class.new {
36
+ extend Savon::Model
37
+
38
+ client :wsdl => Fixture.wsdl(:authentication)
39
+
40
+ global :soap_version, 2
41
+ global :open_timeout, 71
42
+ global :wsse_auth, "luke", "secret", :digest
43
+ }
44
+
45
+ expect(model.client.globals[:soap_version]).to eq(2)
46
+ expect(model.client.globals[:open_timeout]).to eq(71)
47
+ expect(model.client.globals[:wsse_auth]).to eq(["luke", "secret", :digest])
48
+ end
49
+ end
50
+
51
+ describe ".operations" do
52
+ it "defines class methods for each operation" do
53
+ model = Class.new {
54
+ extend Savon::Model
55
+
56
+ client :wsdl => Fixture.wsdl(:authentication)
57
+ operations :authenticate
58
+ }
59
+
60
+ expect(model).to respond_to(:authenticate)
61
+ end
62
+
63
+ it "executes class-level SOAP operations" do
64
+ repeat_url = @server.url(:repeat)
65
+
66
+ model = Class.new {
67
+ extend Savon::Model
68
+
69
+ client :endpoint => repeat_url, :namespace => "http://v1.example.com"
70
+ global :log, false
71
+
72
+ operations :authenticate
73
+ }
74
+
75
+ response = model.authenticate(:xml => Fixture.response(:authentication))
76
+ expect(response.body[:authenticate_response][:return]).to include(:authentication_value)
77
+ end
78
+
79
+ it "defines instance methods for each operation" do
80
+ model = Class.new {
81
+ extend Savon::Model
82
+
83
+ client :wsdl => Fixture.wsdl(:authentication)
84
+ operations :authenticate
85
+ }
86
+
87
+ model_instance = model.new
88
+ expect(model_instance).to respond_to(:authenticate)
89
+ end
90
+
91
+ it "executes instance-level SOAP operations" do
92
+ repeat_url = @server.url(:repeat)
93
+
94
+ model = Class.new {
95
+ extend Savon::Model
96
+
97
+ client :endpoint => repeat_url, :namespace => "http://v1.example.com"
98
+ global :log, false
99
+
100
+ operations :authenticate
101
+ }
102
+
103
+ model_instance = model.new
104
+ response = model_instance.authenticate(:xml => Fixture.response(:authentication))
105
+ expect(response.body[:authenticate_response][:return]).to include(:authentication_value)
106
+ end
107
+ end
108
+
109
+ it "allows to overwrite class operations" do
110
+ repeat_url = @server.url(:repeat)
111
+
112
+ model = Class.new {
113
+ extend Savon::Model
114
+ client :endpoint => repeat_url, :namespace => "http://v1.example.com"
115
+ }
116
+
117
+ supermodel = model.dup
118
+ supermodel.operations :authenticate
119
+
120
+ def supermodel.authenticate(locals = {})
121
+ p "super"
122
+ super
123
+ end
124
+
125
+ supermodel.client.expects(:call).with(:authenticate, :message => { :username => "luke", :password => "secret" })
126
+ supermodel.expects(:p).with("super") # stupid, but works
127
+
128
+ supermodel.authenticate(:message => { :username => "luke", :password => "secret" })
129
+ end
130
+
131
+ it "allows to overwrite instance operations" do
132
+ repeat_url = @server.url(:repeat)
133
+
134
+ model = Class.new {
135
+ extend Savon::Model
136
+ client :endpoint => repeat_url, :namespace => "http://v1.example.com"
137
+ }
138
+
139
+ supermodel = model.dup
140
+ supermodel.operations :authenticate
141
+ supermodel = supermodel.new
142
+
143
+ def supermodel.authenticate(lcoals = {})
144
+ p "super"
145
+ super
146
+ end
147
+
148
+ supermodel.client.expects(:call).with(:authenticate, :message => { :username => "luke", :password => "secret" })
149
+ supermodel.expects(:p).with("super") # stupid, but works
150
+
151
+ supermodel.authenticate(:message => { :username => "luke", :password => "secret" })
152
+ end
153
+
154
+ describe ".all_operations" do
155
+ it "should call operations with all available client operations" do
156
+ model = Class.new {
157
+ extend Savon::Model
158
+
159
+ client :wsdl => Fixture.wsdl(:taxcloud)
160
+ all_operations
161
+ }
162
+
163
+ [:verify_address,
164
+ :lookup_for_date,
165
+ :lookup,
166
+ :authorized,
167
+ :authorized_with_capture,
168
+ :captured,
169
+ :returned,
170
+ :get_tic_groups,
171
+ :get_ti_cs,
172
+ :get_ti_cs_by_group,
173
+ :add_exempt_certificate,
174
+ :delete_exempt_certificate,
175
+ :get_exempt_certificates].each do |method|
176
+ expect(model).to respond_to(method)
177
+ end
178
+ end
179
+
180
+ end
181
+
182
+ end
@@ -0,0 +1,92 @@
1
+ require "spec_helper"
2
+ require "integration/support/server"
3
+
4
+ describe Savon do
5
+
6
+ before :all do
7
+ @server = IntegrationServer.run
8
+ end
9
+
10
+ after :all do
11
+ @server.stop
12
+ end
13
+
14
+ describe ".observers" do
15
+ after :each do
16
+ Savon.observers.clear
17
+ end
18
+
19
+ it "allows to register an observer for every request" do
20
+ observer = Class.new {
21
+
22
+ def notify(operation_name, builder, globals, locals)
23
+ @operation_name = operation_name
24
+
25
+ @builder = builder
26
+ @globals = globals
27
+ @locals = locals
28
+
29
+ # return nil to execute the request
30
+ nil
31
+ end
32
+
33
+ attr_reader :operation_name, :builder, :globals, :locals
34
+
35
+ }.new
36
+
37
+ Savon.observers << observer
38
+
39
+ new_client.call(:authenticate)
40
+
41
+ expect(observer.operation_name).to eq(:authenticate)
42
+
43
+ expect(observer.builder).to be_a(Savon::Builder)
44
+ expect(observer.globals).to be_a(Savon::GlobalOptions)
45
+ expect(observer.locals).to be_a(Savon::LocalOptions)
46
+ end
47
+
48
+ it "allows to register an observer which mocks requests" do
49
+ observer = Class.new {
50
+
51
+ def notify(*)
52
+ # return a response to mock the request
53
+ HTTPI::Response.new(201, { "X-Result" => "valid" }, "valid!")
54
+ end
55
+
56
+ }.new
57
+
58
+ Savon.observers << observer
59
+
60
+ response = new_client.call(:authenticate)
61
+
62
+ expect(response.http.code).to eq(201)
63
+ expect(response.http.headers).to eq("X-Result" => "valid")
64
+ expect(response.http.body).to eq("valid!")
65
+ end
66
+
67
+ it "raises if an observer returns something other than nil or an HTTPI::Response" do
68
+ observer = Class.new {
69
+
70
+ def notify(*)
71
+ []
72
+ end
73
+
74
+ }.new
75
+
76
+ Savon.observers << observer
77
+
78
+ expect { new_client.call(:authenticate) }.
79
+ to raise_error(Savon::Error, "Observers need to return an HTTPI::Response " \
80
+ "to mock the request or nil to execute the request.")
81
+ end
82
+ end
83
+
84
+ def new_client
85
+ Savon.client(
86
+ :endpoint => @server.url(:repeat),
87
+ :namespace => "http://v1.example.com",
88
+ :log => false
89
+ )
90
+ end
91
+
92
+ end