smacks-savon 0.1.61 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +27 -50
- data/Rakefile +48 -0
- data/VERSION +1 -0
- data/lib/savon.rb +47 -4
- data/lib/savon/service.rb +64 -90
- data/lib/savon/wsdl.rb +41 -46
- data/spec/fixtures/soap_fault.xml +8 -0
- data/spec/fixtures/user_response.xml +13 -0
- data/spec/fixtures/user_wsdl.xml +106 -0
- data/spec/savon/service_spec.rb +64 -0
- data/spec/savon/wsdl_spec.rb +65 -0
- data/spec/spec_helper.rb +100 -0
- metadata +47 -20
- data/lib/savon/response.rb +0 -173
- data/test/factories/wsdl.rb +0 -127
- data/test/fixtures/soap_response_fixture.rb +0 -75
- data/test/helper.rb +0 -48
- data/test/savon/test_response.rb +0 -191
- data/test/savon/test_service.rb +0 -35
- data/test/savon/test_wsdl.rb +0 -52
- data/test/test_savon.rb +0 -4
@@ -0,0 +1,13 @@
|
|
1
|
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
2
|
+
<soap:Body>
|
3
|
+
<ns2:findUserResponse xmlns:ns2="http://v1_0.ws.user.example.com">
|
4
|
+
<return>
|
5
|
+
<id>123</id>
|
6
|
+
<email>thedude@example.com</email>
|
7
|
+
<username>thedude</username>
|
8
|
+
<firstname>The</firstname>
|
9
|
+
<lastname>Dude</lastname>
|
10
|
+
</return>
|
11
|
+
</ns2:findUserResponse>
|
12
|
+
</soap:Body>
|
13
|
+
</soap:Envelope>
|
@@ -0,0 +1,106 @@
|
|
1
|
+
<wsdl:definitions
|
2
|
+
name="UserWebService"
|
3
|
+
targetNamespace="http://v1_0.ws.user.example.com"
|
4
|
+
xmlns:ns1="http://cxf.apache.org/bindings/xformat"
|
5
|
+
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
|
6
|
+
xmlns:tns="http://v1_0.ws.user.example.com"
|
7
|
+
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
|
8
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
9
|
+
|
10
|
+
<wsdl:types>
|
11
|
+
<xs:schema
|
12
|
+
attributeFormDefault="unqualified"
|
13
|
+
elementFormDefault="unqualified"
|
14
|
+
targetNamespace="http://v1_0.ws.user.example.com"
|
15
|
+
xmlns:tns="http://v1_0.ws.user.example.com"
|
16
|
+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
17
|
+
<xs:element name="findUser" type="tns:findUser" />
|
18
|
+
<xs:element name="findUserRequest" type="tns:findUserRequest" />
|
19
|
+
<xs:element name="baseFindUserRequest" type="tns:baseFindUserRequest" />
|
20
|
+
<xs:element name="idCredential" type="tns:idCredential" />
|
21
|
+
<xs:element name="emailCredential" type="tns:emailCredential" />
|
22
|
+
<xs:element name="findUserResponse" type="tns:findUserResponse" />
|
23
|
+
<xs:element name="userResponse" type="tns:userResponse" />
|
24
|
+
|
25
|
+
<xs:complexType name="findUser">
|
26
|
+
<xs:sequence>
|
27
|
+
<xs:element minOccurs="1" name="requestData" type="tns:findUserRequest" />
|
28
|
+
</xs:sequence>
|
29
|
+
</xs:complexType>
|
30
|
+
<xs:complexType name="findUserRequest">
|
31
|
+
<xs:complexContent>
|
32
|
+
<xs:extension base="tns:baseFindUserRequest">
|
33
|
+
<xs:sequence>
|
34
|
+
<xs:element minOccurs="0" name="mandant" type="tns:mandant" />
|
35
|
+
</xs:sequence>
|
36
|
+
</xs:extension>
|
37
|
+
</xs:complexContent>
|
38
|
+
</xs:complexType>
|
39
|
+
<xs:complexType name="baseFindUserRequest">
|
40
|
+
<xs:choice>
|
41
|
+
<xs:element ref="tns:idCredential" />
|
42
|
+
<xs:element ref="tns:emailCredential" />
|
43
|
+
</xs:choice>
|
44
|
+
</xs:complexType>
|
45
|
+
<xs:complexType name="idCredential">
|
46
|
+
<xs:sequence>
|
47
|
+
<xs:element name="id" type="xs:string" />
|
48
|
+
<xs:element name="token" type="xs:string" />
|
49
|
+
</xs:sequence>
|
50
|
+
</xs:complexType>
|
51
|
+
<xs:complexType name="emailCredential">
|
52
|
+
<xs:sequence>
|
53
|
+
<xs:element name="email" type="xs:string" />
|
54
|
+
<xs:element name="token" type="xs:string" />
|
55
|
+
</xs:sequence>
|
56
|
+
</xs:complexType>
|
57
|
+
<xs:complexType name="findUserResponse">
|
58
|
+
<xs:sequence>
|
59
|
+
<xs:element minOccurs="0" name="return" type="tns:userResponse" />
|
60
|
+
</xs:sequence>
|
61
|
+
</xs:complexType>
|
62
|
+
<xs:complexType name="userResponse">
|
63
|
+
<xs:sequence>
|
64
|
+
<xs:element minOccurs="0" name="id" type="xs:string" />
|
65
|
+
<xs:element minOccurs="0" name="email" type="xs:string" />
|
66
|
+
<xs:element minOccurs="0" name="username" type="xs:string" />
|
67
|
+
<xs:element minOccurs="0" name="firstname" type="xs:string" />
|
68
|
+
<xs:element minOccurs="0" name="lastname" type="xs:string" />
|
69
|
+
</xs:sequence>
|
70
|
+
</xs:complexType>
|
71
|
+
</xs:schema>
|
72
|
+
</wsdl:types>
|
73
|
+
|
74
|
+
<wsdl:message name="findUser">
|
75
|
+
<wsdl:part element="tns:findUser" name="parameters"></wsdl:part>
|
76
|
+
</wsdl:message>
|
77
|
+
<wsdl:message name="findUserResponse">
|
78
|
+
<wsdl:part element="tns:findUserResponse" name="parameters"></wsdl:part>
|
79
|
+
</wsdl:message>
|
80
|
+
|
81
|
+
<wsdl:portType name="UserWebService">
|
82
|
+
<wsdl:operation name="findUser">
|
83
|
+
<wsdl:input message="tns:findUser" name="findUser"></wsdl:input>
|
84
|
+
<wsdl:output message="tns:findUserResponse" name="findUserResponse"></wsdl:output>
|
85
|
+
</wsdl:operation>
|
86
|
+
</wsdl:portType>
|
87
|
+
|
88
|
+
<wsdl:binding name="UserWebServiceSoapBinding" type="tns:UserWebService">
|
89
|
+
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
|
90
|
+
<wsdl:operation name="findUser">
|
91
|
+
<soap:operation soapAction="" style="document" />
|
92
|
+
<wsdl:input name="findUser">
|
93
|
+
<soap:body use="literal" />
|
94
|
+
</wsdl:input>
|
95
|
+
<wsdl:output name="findUserResponse">
|
96
|
+
<soap:body use="literal" />
|
97
|
+
</wsdl:output>
|
98
|
+
</wsdl:operation>
|
99
|
+
</wsdl:binding>
|
100
|
+
|
101
|
+
<wsdl:service name="UserWebService">
|
102
|
+
<wsdl:port binding="tns:UserWebServiceSoapBinding" name="UserWebServicePort">
|
103
|
+
<soap:address location="http://example.com/user/1.0/UserService" />
|
104
|
+
</wsdl:port>
|
105
|
+
</wsdl:service>
|
106
|
+
</wsdl:definitions>
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
2
|
+
|
3
|
+
describe Savon::Service do
|
4
|
+
include SpecHelper
|
5
|
+
|
6
|
+
# initialize
|
7
|
+
describe "initialize" do
|
8
|
+
it "raises an ArgumentError when called with an invalid endpoint" do
|
9
|
+
["", nil, "invalid", 123].each do |arg|
|
10
|
+
lambda { Savon::Service.new(arg) }.should raise_error(ArgumentError)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# wsdl
|
16
|
+
describe "wsdl" do
|
17
|
+
before { @service = new_service_instance }
|
18
|
+
|
19
|
+
it "returns an instance of Savon::WSDL" do
|
20
|
+
@service.wsdl.should be_a(Savon::WSDL)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns the exact same Savon::WSDL instance every time" do
|
24
|
+
@service.wsdl.should equal(@service.wsdl)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# method_missing
|
29
|
+
describe "method_missing" do
|
30
|
+
before { @service = new_service_instance }
|
31
|
+
|
32
|
+
it "raises a NoMethodError when called with an invalid soap_action" do
|
33
|
+
lambda { @service.invalid_action }.should raise_error(NoMethodError)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "by default returns content from the response using the '//return' XPath" do
|
37
|
+
@service.find_user.should == { :firstname => "The", :lastname => "Dude",
|
38
|
+
:email => "thedude@example.com", :username => "thedude", :id => "123" }
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns the content of the response starting at a custom XPath" do
|
42
|
+
@service.find_user(nil, "//email").should == "thedude@example.com"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns nil if a given XPath does not match anything in the SOAP response" do
|
46
|
+
@service.find_user(nil, "//doesNotMatchAnything").should be_nil
|
47
|
+
end
|
48
|
+
|
49
|
+
it "raises a Savon::SOAPFault in case of a SOAP fault" do
|
50
|
+
@service = new_service_instance(:soap_fault => true)
|
51
|
+
lambda { @service.find_user }.should raise_error(Savon::SOAPFault)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "raises a Savon::HTTPError in case the server returned an error code and no SOAP fault" do
|
55
|
+
@service = new_service_instance(:http_error => true)
|
56
|
+
lambda { @service.find_user }.should raise_error(Savon::HTTPError)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "raises a Savon::SOAPFault in case the server returned an error code and a SOAP fault" do
|
60
|
+
@service = new_service_instance(:soap_fault => true, :http_error => true)
|
61
|
+
lambda { @service.find_user }.should raise_error(Savon::SOAPFault)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
2
|
+
|
3
|
+
describe Savon::WSDL do
|
4
|
+
include SpecHelper
|
5
|
+
|
6
|
+
#namespace_uri
|
7
|
+
describe "namespace_uri" do
|
8
|
+
before { @wsdl = new_wsdl }
|
9
|
+
|
10
|
+
it "returns the namespace URI from the WSDL" do
|
11
|
+
@wsdl.namespace_uri == UserFixture.namespace_uri
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns the same object every time" do
|
15
|
+
@wsdl.namespace_uri.should equal(@wsdl.namespace_uri)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# soap_actions
|
20
|
+
describe "soap_actions" do
|
21
|
+
before { @wsdl = new_wsdl }
|
22
|
+
|
23
|
+
it "returns the SOAP actions from the WSDL" do
|
24
|
+
@wsdl.soap_actions == UserFixture.soap_actions
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns the same object every time" do
|
28
|
+
@wsdl.soap_actions.should equal(@wsdl.soap_actions)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# choice_elements
|
33
|
+
describe "choice_elements" do
|
34
|
+
before { @wsdl = new_wsdl }
|
35
|
+
|
36
|
+
it "returns the choice elements from the WSDL" do
|
37
|
+
@wsdl.choice_elements == UserFixture.choice_elements
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns the same object every time" do
|
41
|
+
@wsdl.choice_elements.should equal(@wsdl.choice_elements)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# initialize
|
46
|
+
describe "initialize" do
|
47
|
+
it "expects an endpoint URI and a Net::HTTP instance" do
|
48
|
+
@wsdl = Savon::WSDL.new(some_uri, some_http)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# to_s
|
53
|
+
describe "to_s" do
|
54
|
+
before { @wsdl = new_wsdl }
|
55
|
+
|
56
|
+
it "returns nil before the WSDL document was retrieved" do
|
57
|
+
@wsdl.to_s.should be_nil
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns the response body when available" do
|
61
|
+
@wsdl.soap_actions # trigger http request
|
62
|
+
@wsdl.to_s.should == UserFixture.user_wsdl
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
gem "rspec", ">= 1.2.8"
|
3
|
+
require "spec"
|
4
|
+
require "rr"
|
5
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "savon")
|
6
|
+
|
7
|
+
Spec::Runner.configure do |config|
|
8
|
+
config.mock_with :rr
|
9
|
+
end
|
10
|
+
|
11
|
+
module SpecHelper
|
12
|
+
def some_url
|
13
|
+
"http://example.com"
|
14
|
+
end
|
15
|
+
|
16
|
+
def some_uri
|
17
|
+
URI(some_url)
|
18
|
+
end
|
19
|
+
|
20
|
+
def some_http
|
21
|
+
Net::HTTP.new(some_uri.host, some_uri.port)
|
22
|
+
end
|
23
|
+
|
24
|
+
def new_wsdl
|
25
|
+
Savon::WSDL.new(some_uri, UserFixture.http_mock)
|
26
|
+
end
|
27
|
+
|
28
|
+
def new_service_instance(options = {})
|
29
|
+
service = Savon::Service.new(some_url)
|
30
|
+
service.instance_variable_set("@http", UserFixture.http_mock(options))
|
31
|
+
service
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class UserFixture
|
36
|
+
extend RR::Adapters::RRMethods
|
37
|
+
|
38
|
+
class << self
|
39
|
+
include SpecHelper
|
40
|
+
|
41
|
+
def namespace_uri
|
42
|
+
"http://v1_0.ws.user.example.com"
|
43
|
+
end
|
44
|
+
|
45
|
+
def soap_actions
|
46
|
+
%w(findUser)
|
47
|
+
end
|
48
|
+
|
49
|
+
def choice_elements
|
50
|
+
%w(idCredential emailCredential)
|
51
|
+
end
|
52
|
+
|
53
|
+
def user_wsdl
|
54
|
+
load_fixture("user_wsdl.xml")
|
55
|
+
end
|
56
|
+
|
57
|
+
def user_response
|
58
|
+
load_fixture("user_response.xml")
|
59
|
+
end
|
60
|
+
|
61
|
+
def soap_fault
|
62
|
+
load_fixture("soap_fault.xml")
|
63
|
+
end
|
64
|
+
|
65
|
+
def http_mock(options = {})
|
66
|
+
response_body = options[:soap_fault] ? soap_fault : user_response
|
67
|
+
response_code = options[:http_error] ? 500 : 200
|
68
|
+
response_body = "" if options[:http_error] && !options[:soap_fault]
|
69
|
+
generate_http_mock(soap_response_mock(response_body, response_code))
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def load_fixture(file)
|
75
|
+
file_path = File.join(File.dirname(__FILE__), "fixtures", file)
|
76
|
+
IO.readlines(file_path, "").to_s
|
77
|
+
end
|
78
|
+
|
79
|
+
def generate_http_mock(soap_response)
|
80
|
+
mock = some_http
|
81
|
+
stub(mock).get(anything) { wsdl_response_mock(user_wsdl) }
|
82
|
+
stub(mock).request_post(anything, anything, anything) { soap_response }
|
83
|
+
mock
|
84
|
+
end
|
85
|
+
|
86
|
+
def wsdl_response_mock(response_body)
|
87
|
+
mock = mock()
|
88
|
+
stub(mock).body { response_body }
|
89
|
+
mock
|
90
|
+
end
|
91
|
+
|
92
|
+
def soap_response_mock(response_body, response_code)
|
93
|
+
mock = mock()
|
94
|
+
stub(mock).body { response_body }
|
95
|
+
stub(mock).code { response_code }
|
96
|
+
stub(mock).message { "whatever" }
|
97
|
+
mock
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smacks-savon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Harrington
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-30 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - "="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
23
|
+
version: 0.8.241
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: smacks-apricoteatsgorilla
|
@@ -30,10 +30,30 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.5.2
|
34
34
|
version:
|
35
|
-
|
36
|
-
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.2.8
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: rr
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.10.0
|
54
|
+
version:
|
55
|
+
description: SOAP client library to enjoy.
|
56
|
+
email: me@d-harrington.com
|
37
57
|
executables: []
|
38
58
|
|
39
59
|
extensions: []
|
@@ -42,17 +62,28 @@ extra_rdoc_files:
|
|
42
62
|
- README.rdoc
|
43
63
|
files:
|
44
64
|
- README.rdoc
|
65
|
+
- Rakefile
|
66
|
+
- VERSION
|
45
67
|
- lib/savon.rb
|
46
68
|
- lib/savon/service.rb
|
47
69
|
- lib/savon/wsdl.rb
|
48
|
-
-
|
70
|
+
- spec/fixtures/soap_fault.xml
|
71
|
+
- spec/fixtures/user_response.xml
|
72
|
+
- spec/fixtures/user_wsdl.xml
|
73
|
+
- spec/savon/service_spec.rb
|
74
|
+
- spec/savon/wsdl_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
49
76
|
has_rdoc: true
|
50
77
|
homepage: http://github.com/smacks/savon
|
51
|
-
licenses:
|
52
78
|
post_install_message:
|
53
79
|
rdoc_options:
|
54
|
-
- --inline-source
|
55
80
|
- --charset=UTF-8
|
81
|
+
- --title
|
82
|
+
- Savon
|
83
|
+
- --main
|
84
|
+
- README.rdoc
|
85
|
+
- --line-numbers
|
86
|
+
- --inline-source
|
56
87
|
require_paths:
|
57
88
|
- lib
|
58
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -67,18 +98,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
98
|
- !ruby/object:Gem::Version
|
68
99
|
version: "0"
|
69
100
|
version:
|
70
|
-
requirements:
|
71
|
-
|
101
|
+
requirements: []
|
102
|
+
|
72
103
|
rubyforge_project:
|
73
|
-
rubygems_version: 1.
|
104
|
+
rubygems_version: 1.2.0
|
74
105
|
signing_key:
|
75
106
|
specification_version: 2
|
76
|
-
summary:
|
107
|
+
summary: SOAP client library to enjoy.
|
77
108
|
test_files:
|
78
|
-
-
|
79
|
-
-
|
80
|
-
-
|
81
|
-
- test/fixtures/soap_response_fixture.rb
|
82
|
-
- test/savon/test_service.rb
|
83
|
-
- test/savon/test_response.rb
|
84
|
-
- test/savon/test_wsdl.rb
|
109
|
+
- spec/savon/service_spec.rb
|
110
|
+
- spec/savon/wsdl_spec.rb
|
111
|
+
- spec/spec_helper.rb
|