soaspec 0.0.38 → 0.0.39

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49098321c361f4bb95c10c5eb204986e9595848a
4
- data.tar.gz: 0bb08c64d7b9ca33f807227d1e0f4b02751d7271
3
+ metadata.gz: 299efa5595bfbfa534193ee070b9398165219c39
4
+ data.tar.gz: dba13a67d92ac44c2b0619ab17d1aa72804986e0
5
5
  SHA512:
6
- metadata.gz: eb427fdc9820aabe14be289f8dc6f36cfefe2c1acdadfa2cc129153a852f53066d6a55648c9d3305f966ae0e73a9e18c2999ff51fc1c4564326653645c8aa6eb
7
- data.tar.gz: a64e8a28b2661e26038d72910c7965c60edadd38d7486ad2d017c03f5bc43b1d6e968234afce959af3269e2ab23f7d169a15df9170db6e943e77eb13b771aca3
6
+ metadata.gz: a5cff7eea1849ba64e8e6f7df40e9fe7ea697f7d0e66df54c7865f7fe2aa92a6599131de8d50ada6131fbb31cfdff4b7911574468837b329311fd75eac4bfe76
7
+ data.tar.gz: e1e5be5d598535d8039b27bbac361c5ca6cb26e5541f70940a95eee623d8b8d17d0593a1987eac671434f741ab35edf268981b96053b906f97c3d8cb9abc4b9b
data/ChangeLog CHANGED
@@ -1,3 +1,11 @@
1
+ Version 0.0.39
2
+ * Spec
3
+ * Create task to use soaspec-init to create test structure and test it.
4
+ * Enhancements
5
+ * Take away need to use Environment namespace
6
+ * Added response headers to REST response log
7
+ * Now using virtual Web Service for SOAP
8
+
1
9
  Version 0.0.38 / 2018-3-15
2
10
  * Bug fix
3
11
  * Fixed error in soaspec-generate. TODO: Test this in CI
data/Gemfile CHANGED
@@ -16,3 +16,5 @@ gem 'rspec_junit_formatter'
16
16
  gem 'xml-simple'
17
17
  gem 'jsonpath'
18
18
  gem 'simplecov'
19
+ gem 'sinatra'
20
+ gem 'rack-test'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- soaspec (0.0.38)
4
+ soaspec (0.0.39)
5
5
  jsonpath
6
6
  rest-client (>= 2.0)
7
7
  rspec (~> 3.0)
@@ -45,6 +45,7 @@ GEM
45
45
  mime-types-data (3.2016.0521)
46
46
  mini_portile2 (2.3.0)
47
47
  multi_json (1.13.1)
48
+ mustermann (1.0.2)
48
49
  netrc (0.11.0)
49
50
  nokogiri (1.8.2)
50
51
  mini_portile2 (~> 2.3.0)
@@ -52,6 +53,10 @@ GEM
52
53
  mini_portile2 (~> 2.3.0)
53
54
  nori (2.6.0)
54
55
  rack (2.0.4)
56
+ rack-protection (2.0.1)
57
+ rack
58
+ rack-test (0.6.3)
59
+ rack (>= 1.0)
55
60
  rake (12.2.1)
56
61
  require_all (1.5.0)
57
62
  rest-client (2.0.2)
@@ -94,7 +99,13 @@ GEM
94
99
  json (>= 1.8, < 3)
95
100
  simplecov-html (~> 0.10.0)
96
101
  simplecov-html (0.10.2)
102
+ sinatra (2.0.1)
103
+ mustermann (~> 1.0)
104
+ rack (~> 2.0)
105
+ rack-protection (= 2.0.1)
106
+ tilt (~> 2.0)
97
107
  socksify (1.7.1)
108
+ tilt (2.0.8)
98
109
  to_regexp (0.2.1)
99
110
  unf (0.1.4)
100
111
  unf_ext
@@ -115,6 +126,7 @@ DEPENDENCIES
115
126
  data_magic
116
127
  jsonpath
117
128
  nokogiri
129
+ rack-test
118
130
  rake (= 12.2.1)
119
131
  require_all
120
132
  rest-client
@@ -123,8 +135,9 @@ DEPENDENCIES
123
135
  rspec_junit_formatter
124
136
  savon
125
137
  simplecov
138
+ sinatra
126
139
  soaspec!
127
140
  xml-simple
128
141
 
129
142
  BUNDLED WITH
130
- 1.16.0
143
+ 1.16.1
data/README.md CHANGED
@@ -1,10 +1,9 @@
1
-
2
1
  # Soaspec
3
2
 
4
3
  This gem helps to represent multiple API tests against a backend briefly, concisely and clearly. It is essentially a wrapper around the Savon and RestClient gems. Note it is still in early stages of development.
5
4
 
6
5
  [![Build Status](https://gitlab.com/samuel-garratt/soaspec/badges/master/build.svg)](https://gitlab.com/samuel-garratt/soaspec/pipelines)
7
-
6
+ [![Coverage](https://gitlab.com/samuel-garratt/soaspec/badges/master/coverage.svg)](https://samuel-garratt.gitlab.io/soaspec)
8
7
  ## Installation
9
8
 
10
9
  Add this line to your application's Gemfile:
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ ENV['folder'] ||= ''
6
6
  ENV['test'] ||= ''
7
7
 
8
8
  RSpec::Core::RakeTask.new(:run_spec) do |t|
9
- t.pattern = "spec/*/#{ENV['folder']}*/#{ENV['test']}*_spec.rb"
9
+ t.pattern = "{spec/*/#{ENV['folder']}*/#{ENV['test']},tmp/*/spec/}*_spec.rb"
10
10
  end
11
11
 
12
12
  desc 'Prepare log files'
@@ -15,9 +15,24 @@ task :logs do
15
15
  touch 'logs/traffic.log'
16
16
  end
17
17
 
18
+ desc 'Use soaspec_init in tmp to generate test files. Used for verifying it'
19
+ task :use_soaspec_init do
20
+ mkdir_p 'tmp'
21
+ mkdir_p 'tmp/init'
22
+ puts `cd tmp/init && ruby ../../exe/soaspec-init`
23
+ end
24
+
25
+
18
26
  desc 'Run tests'
19
- task :spec => %w[logs run_spec]
27
+ task :spec => %w[clean clobber use_soaspec_init logs start_test_server run_spec]
20
28
 
21
29
  task :default => :spec
22
30
 
31
+ CLEAN.include 'tmp/*'
23
32
  CLOBBER.include 'logs/*'
33
+
34
+ desc 'Start virtual web service'
35
+ task :start_test_server do
36
+ ENV['test_server_pid'] = Process.spawn('ruby', 'spec/test_server.rb').to_s #, err: "/dev/null").to_s - TODO: use to turn off debugging
37
+ puts 'Running test server at pid ' + ENV['test_server_pid']
38
+ end
data/Todo.md ADDED
@@ -0,0 +1,2 @@
1
+ * SoapHandler - define xhange method for each SOAP operation
2
+ * exchange add fields to overide parameters to support cucumber steps. exchange[from_temp]
@@ -1,6 +1,5 @@
1
- japan:
2
- city_name: 'Tokyo'
3
- country_name: 'Japan'
1
+ small_id:
2
+ blz: 100
4
3
 
5
4
  pet:
6
5
  id: '1122334400'
@@ -16,23 +16,23 @@ require 'soaspec'
16
16
  # This class is not part of the gem. It's an example of a class you can make
17
17
  # to describe your APIs. Usually this would exist in the 'lib' directory
18
18
  # Common configuration for the Savon client should go here
19
- class WeatherWebService < Soaspec::SoapHandler
19
+ class BLZService < Soaspec::SoapHandler
20
20
  # Add to or override default Savon client options
21
21
  def savon_options
22
22
  {
23
- wsdl: 'http://www.webservicex.com/globalweather.asmx?wsdl',
24
- convert_request_keys_to: :camelcase
23
+ # wsdl: 'http://www.thomas-bayer.com/axis2/services/BLZService?wsdl' # External
24
+ wsdl: File.join('spec', 'wsdl', 'get_bank.wsdl') # Virtual service
25
25
  }
26
26
  end
27
27
 
28
- # Specifying that get_weather_result must be present in the SOAP response
29
- mandatory_elements [:get_weather_result]
28
+ # # Specifying that get_weather_result must be present in the SOAP response
29
+ mandatory_elements [:plz]
30
30
 
31
31
  # Example of xpath value that must be true for all success scenarios
32
- mandatory_xpath_values '//xmlns:GetWeatherResult' => 'Data Not Found'
32
+ mandatory_xpath_values 'ns1:bezeichnung' => 'Deutsche Bank'
33
33
 
34
34
  # Example of setting an attribute on the root XML element
35
- root_attributes 'Version' => '1'
35
+ root_attributes 'Version' => '1' # TODO: Create test on request for this
36
36
 
37
37
  end
38
38
 
@@ -42,42 +42,58 @@ soap_spec_content = <<-EOF
42
42
 
43
43
  require 'spec_helper'
44
44
 
45
- Soaspec::Environment.strip_namespaces = true # This allows namespace not to be used. Be careful with this
45
+ Soaspec.strip_namespaces = true # This allows namespace not to be used. Be careful with this
46
46
 
47
- soap_example = WeatherWebService.new('Get Weather')
48
- soap_example.operation = :get_weather
49
- soap_example.default_hash = { city_name: 'Sydney', country_name: 'Australia' }
50
- # soap_example.template_name = 'soap_template' # Use this if you'd rather use template file and comment out previous line
47
+ hash_example = BLZService.new('Get Bank')
48
+ hash_example.operation = :get_bank
51
49
 
50
+ id = '70070010'
51
+ #hash_example.template_name = 'soap_template' Use this instead of default_hash to use template approach
52
+ hash_example.default_hash = { blz: id }
53
+
54
+
55
+ context 'BasicSoapHandler', '#default_hash' do
56
+ context hash_example do
52
57
 
53
- context soap_example do
54
58
  describe Exchange.new(:default) do
55
- it { is_expected.to contain_value 'Data Not Found' }
59
+ it { is_expected.to contain_value id }
60
+ it { is_expected.to include_in_body id }
56
61
  it_behaves_like 'success scenario'
62
+ after(:all) { hash_example.store(:bezeichnung, described_class['bezeichnung']) }
57
63
  end
58
64
 
59
- describe Exchange.new(:china, city_name: 'Shanghai', country_name: 'China') do
60
- it_behaves_like 'success scenario'
61
- context 'handle xpath' do
62
- its(['GetWeatherResult']) { is_expected.to eq 'Data Not Found' } # Don't need to use namespace
63
- it { is_expected.to have_element_at_xpath '//xmlns:GetWeatherResult' }
64
- it { is_expected.to have_xpath_value '//xmlns:GetWeatherResult' => 'Data Not Found' }
65
+ describe Exchange.new(:xpath_eg, blz: 100000) do
66
+ its(['plz']) { is_expected.to eq '100000' }
67
+ it { is_expected.to have_xpath_value '//ns1:bezeichnung' => 'Deutsche Bank' }
68
+ context 'Handle retrieving stored value' do
69
+ it { is_expected.to have_xpath_value 'bezeichnung' => hash_example.bezeichnung }
65
70
  end
66
71
  end
67
72
 
68
- describe Exchange.new(:japan, data_for('default/japan')) do
73
+ describe Exchange.new(:yaml_eg, data_for(:small_id)) do
69
74
  it_behaves_like 'success scenario'
70
- its(['//xmlns:GetWeatherResult']) { is_expected.to eq 'Data Not Found' } # Can specify namespace if wanted
75
+ end
76
+
77
+ # Retry for success more for web services that intermittently fail
78
+ describe Exchange.new(:short_hand_xpath).retry_for_success do
79
+ # Be careful. If you call a method that does not use namespaces, calling one that does may not find the element
80
+ its(['ns1:bezeichnung']) { is_expected.to eq 'Deutsche Bank' } # '//' is not required at the beginning
81
+ end
82
+ describe Exchange.new('Check existence of elements') do
83
+ it { is_expected.to have_element_at_xpath '//ns1:bezeichnung' }
84
+ it { is_expected.not_to have_element_at_xpath '//ns1:bezeichnung_pretend' }
71
85
  end
72
86
 
73
87
  end
88
+ end
89
+
90
+ error_example = BLZService.new('Error example')
91
+ error_example.operation = :get_bank
92
+ error_example.default_hash = {}
74
93
 
75
- error_example = WeatherWebService.new('Get Weather')
76
- error_example.operation = :get_weather
77
- error_example.default_hash = { city_name: 'Washington' }
78
94
  context 'error scenarios' do
79
95
  context error_example do
80
- describe Exchange.new(:error) do
96
+ describe Exchange.new(:no_blz_error) do
81
97
  it_behaves_like 'error scenario'
82
98
  end
83
99
  end
@@ -99,37 +115,129 @@ end
99
115
  EOF
100
116
 
101
117
  soap_template_content = <<-EOF
102
- <s12:Envelope xmlns:s12='http://www.w3.org/2003/05/soap-envelope'>
103
- <s12:Body>
104
- <ns1:GetWeather xmlns:ns1='http://www.webserviceX.NET'>
105
- <!-- optional -->
106
- <ns1:CityName><%= test_values[:city_name] || 'Wellington' %></ns1:CityName>
107
- <!-- optional -->
108
- <ns1:CountryName><%= test_values[:country] || 'New Zealand' %></ns1:CountryName>
109
- </ns1:GetWeather>
110
- </s12:Body>
111
- </s12:Envelope>
118
+ <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://thomas-bayer.com/blz/" xmlns:env="http://www.w3.org/2003/05/soap-envelope">
119
+ <env:Body>
120
+ <tns:getBank>
121
+ <tns:blz><%= test_values[:blz] || '70070010' %></tns:blz>
122
+ </tns:getBank>
123
+ </env:Body>
124
+ </env:Envelope>
112
125
  EOF
113
126
 
114
127
  default_yaml_content = <<-EOF
115
- japan:
116
- city_name: 'Tokyo'
117
- country_name: 'Japan'
128
+ small_id:
129
+ blz: 100
130
+
131
+ EOF
118
132
 
133
+ test_wsdl_content = <<EOF
134
+ <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:tns="http://thomas-bayer.com/blz/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://thomas-bayer.com/blz/">
135
+ <wsdl:documentation>BLZService</wsdl:documentation>
136
+ <wsdl:types>
137
+ <xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://thomas-bayer.com/blz/">
138
+ <xsd:element name="getBank" type="tns:getBankType"/>
139
+ <xsd:element name="getBankResponse" type="tns:getBankResponseType"/>
140
+ <xsd:complexType name="getBankType">
141
+ <xsd:sequence>
142
+ <xsd:element name="blz" type="xsd:string"/>
143
+ </xsd:sequence>
144
+ </xsd:complexType>
145
+ <xsd:complexType name="getBankResponseType">
146
+ <xsd:sequence>
147
+ <xsd:element name="details" type="tns:detailsType"/>
148
+ </xsd:sequence>
149
+ </xsd:complexType>
150
+ <xsd:complexType name="detailsType">
151
+ <xsd:sequence>
152
+ <xsd:element minOccurs="0" name="bezeichnung" type="xsd:string"/>
153
+ <xsd:element minOccurs="0" name="bic" type="xsd:string"/>
154
+ <xsd:element minOccurs="0" name="ort" type="xsd:string"/>
155
+ <xsd:element minOccurs="0" name="plz" type="xsd:string"/>
156
+ </xsd:sequence>
157
+ </xsd:complexType>
158
+ </xsd:schema>
159
+ </wsdl:types>
160
+ <wsdl:message name="getBank">
161
+ <wsdl:part name="parameters" element="tns:getBank"/>
162
+ </wsdl:message>
163
+ <wsdl:message name="getBankResponse">
164
+ <wsdl:part name="parameters" element="tns:getBankResponse"/>
165
+ </wsdl:message>
166
+ <wsdl:portType name="BLZServicePortType">
167
+ <wsdl:operation name="getBank">
168
+ <wsdl:input message="tns:getBank"/>
169
+ <!--<wsdl:output message="tns:getBankResponse" wsaw:Action="http://thomas-bayer.com/blz/BLZService/getBankResponse"/>-->
170
+ <wsdl:output message="tns:getBankResponse" wsaw:Action="http://localhost:4567/BLZService/getBankResponse"/>
171
+ </wsdl:operation>
172
+ </wsdl:portType>
173
+ <wsdl:binding name="BLZServiceSOAP11Binding" type="tns:BLZServicePortType">
174
+ <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
175
+ <wsdl:operation name="getBank">
176
+ <soap:operation style="document" soapAction=""/>
177
+ <wsdl:input>
178
+ <soap:body use="literal"/>
179
+ </wsdl:input>
180
+ <wsdl:output>
181
+ <soap:body use="literal"/>
182
+ </wsdl:output>
183
+ </wsdl:operation>
184
+ </wsdl:binding>
185
+ <wsdl:binding name="BLZServiceSOAP12Binding" type="tns:BLZServicePortType">
186
+ <soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
187
+ <wsdl:operation name="getBank">
188
+ <soap12:operation style="document" soapAction=""/>
189
+ <wsdl:input>
190
+ <soap12:body use="literal"/>
191
+ </wsdl:input>
192
+ <wsdl:output>
193
+ <soap12:body use="literal"/>
194
+ </wsdl:output>
195
+ </wsdl:operation>
196
+ </wsdl:binding>
197
+ <wsdl:binding name="BLZServiceHttpBinding" type="tns:BLZServicePortType">
198
+ <http:binding verb="POST"/>
199
+ <wsdl:operation name="getBank">
200
+ <http:operation location="BLZService/getBank"/>
201
+ <wsdl:input>
202
+ <mime:content part="getBank" type="text/xml"/>
203
+ </wsdl:input>
204
+ <wsdl:output>
205
+ <mime:content part="getBank" type="text/xml"/>
206
+ </wsdl:output>
207
+ </wsdl:operation>
208
+ </wsdl:binding>
209
+ <wsdl:service name="BLZService">
210
+ <wsdl:port name="BLZServiceSOAP11port_http" binding="tns:BLZServiceSOAP11Binding">
211
+ <!-- <soap:address location="http://www.thomas-bayer.com/axis2/services/BLZService"/> -->
212
+ <soap:address location="http://localhost:4567/BLZService"/>
213
+ </wsdl:port>
214
+ <wsdl:port name="BLZServiceSOAP12port_http" binding="tns:BLZServiceSOAP12Binding">
215
+ <!--<soap12:address location="http://www.thomas-bayer.com/axis2/services/BLZService"/>-->
216
+ <soap12:address location="http://localhost:4567/BLZService"/>
217
+ </wsdl:port>
218
+ <wsdl:port name="BLZServiceHttpport" binding="tns:BLZServiceHttpBinding">
219
+ <!--<http:address location="http://www.thomas-bayer.com/axis2/services/BLZService"/>-->
220
+ <soap:address location="http://localhost:4567/BLZService"/>
221
+ </wsdl:port>
222
+ </wsdl:service>
223
+ </wsdl:definitions>
119
224
  EOF
120
225
 
121
226
  create_file(filename: 'Gemfile', content: gem_content)
122
227
  create_file(filename: 'Rakefile', content: rake_content)
123
228
  create_file(filename: 'README.md', content: readme_content)
124
229
  create_folder 'lib'
125
- create_file(filename: 'lib/weather_web_service.rb', content: weather_web_service)
230
+ create_file(filename: 'lib/blz_service.rb', content: weather_web_service)
126
231
  create_file filename: 'lib/shared_example.rb', content: shared_examples_content
127
232
  create_folder 'config'
128
233
  create_folder 'config/data'
129
234
  create_file(filename: 'config/data/default.yml', content: default_yaml_content)
130
235
  create_folder 'spec'
236
+ create_folder 'spec/wsdl'
131
237
  create_file(filename: 'spec/spec_helper.rb', content: spec_helper_content)
132
238
  create_file(filename: 'spec/soap_spec.rb', content: soap_spec_content)
239
+ create_file(filename: 'spec/test_server.rb', content: test_server_content)
240
+ create_file(filename: 'spec/wsdl/get_bank.wsdl', content: test_wsdl_content)
133
241
  create_folder 'template'
134
242
  create_file(filename: 'template/soap_template.xml', content: soap_template_content)
135
243
  create_folder 'logs'
@@ -32,30 +32,63 @@ module Soaspec
32
32
  @credentials_folder = folder
33
33
  end
34
34
 
35
- # Credentials folder used
35
+ # Credentials folder used to store secret data (not in source control) E.g passwords
36
36
  def self.credentials_folder
37
37
  @credentials_folder
38
38
  end
39
39
 
40
+ # Used so that exchange class knows what context it's in
41
+ # @param [ExchangeHandler] handler A class inheriting from Soaspec::ExchangeHandler. Exchange class uses this
42
+ def self.api_handler=(handler)
43
+ @api_handler = handler
44
+ end
45
+
46
+ def self.api_handler
47
+ @api_handler
48
+ end
49
+
50
+ # Whether to transform strings to keys automatically
51
+ def self.always_use_keys=(use_keys)
52
+ @always_use_keys = use_keys
53
+ end
54
+
55
+ def self.always_use_keys?
56
+ @always_use_keys || true
57
+ end
58
+
59
+ # Whether to remove namespaces from response in Xpath assertion automatically
60
+ # For why this may not be a good thing in general see
61
+ # http://tenderlovemaking.com/2009/04/23/namespaces-in-xml.html
62
+ # This will be overridden if xpath has a ':' in it
63
+ def self.strip_namespaces=(remove_namespaces_from_response)
64
+ @strip_namespaces = remove_namespaces_from_response
65
+ end
66
+
67
+ # Whether to remove namespaces in xpath assertion automatically
68
+ def self.strip_namespaces?
69
+ @strip_namespaces || false
70
+ end
71
+
72
+ # -Deprecated- for favour of putting directly in Soaspec
40
73
  # Represents Environment parameters used in Soaspec tests
41
74
  module Environment
42
75
 
43
76
  # Used so that exchange class knows what context it's in
44
77
  def self.api_handler=(handler)
45
- @api_handler = handler
78
+ Soaspec.api_handler = handler
46
79
  end
47
80
 
48
81
  def self.api_handler
49
- @api_handler
82
+ Soaspec.api_handler
50
83
  end
51
84
 
52
85
  # Whether to transform strings to keys automatically
53
86
  def self.always_use_keys=(use_keys)
54
- @always_use_keys = use_keys
87
+ Soaspec.always_use_keys = use_keys
55
88
  end
56
89
 
57
90
  def self.always_use_keys?
58
- @always_use_keys || true
91
+ Soaspec.always_use_keys? || true
59
92
  end
60
93
 
61
94
  # Whether to remove namespaces from response in Xpath assertion automatically
@@ -63,12 +96,12 @@ module Soaspec
63
96
  # http://tenderlovemaking.com/2009/04/23/namespaces-in-xml.html
64
97
  # This will be overridden if xpath has a ':' in it
65
98
  def self.strip_namespaces=(remove_namespaces_from_response)
66
- @strip_namespaces = remove_namespaces_from_response
99
+ Soaspec.strip_namespaces = remove_namespaces_from_response
67
100
  end
68
101
 
69
102
  # Whether to remove namespaces in xpath assertion automatically
70
103
  def self.strip_namespaces?
71
- @strip_namespaces || false
104
+ Soaspec.strip_namespaces? || false
72
105
  end
73
106
 
74
107
  end
@@ -23,7 +23,7 @@ class Exchange
23
23
  # @param [Hash] override_parameters Parameters to override for default params
24
24
  def initialize(name, override_parameters = {})
25
25
  @test_name = name.to_s
26
- @api_class = Soaspec::Environment.api_handler
26
+ @api_class = Soaspec.api_handler
27
27
  @override_parameters = override_parameters
28
28
  @retry_for_success = false
29
29
  self.retry_count = 3
@@ -17,7 +17,7 @@ module Soaspec
17
17
  # Sets api handler variable globally. This is used in 'Exchange' class
18
18
  # @return [String] Name set upon initialisation
19
19
  def to_s
20
- Soaspec::Environment.api_handler = self
20
+ Soaspec.api_handler = self
21
21
  @name.to_s
22
22
  end
23
23
 
@@ -124,7 +124,8 @@ module Soaspec
124
124
  rescue RestClient::ExceptionWithResponse => e
125
125
  response = e.response
126
126
  end
127
- Soaspec::SpecLogger.add_to(response)
127
+ Soaspec::SpecLogger.add_to('response_headers: ' + response.headers.to_s)
128
+ Soaspec::SpecLogger.add_to('response_body: ' + response.to_s)
128
129
  response
129
130
  end
130
131
 
@@ -205,7 +206,7 @@ module Soaspec
205
206
  response = exchange.response
206
207
  raise "Can't perform XPATH if response is not XML" unless Interpreter.response_type_for(response) == :xml
207
208
  result =
208
- if Soaspec::Environment.strip_namespaces? && !xpath.include?(':')
209
+ if Soaspec.strip_namespaces? && !xpath.include?(':')
209
210
  temp_doc = Nokogiri.parse response.body
210
211
  temp_doc.remove_namespaces!
211
212
  temp_doc.xpath(xpath).first
@@ -83,7 +83,7 @@ module Soaspec
83
83
  def make_request(override_parameters)
84
84
  test_values = override_parameters # Used in Erb
85
85
  # Erb parses template file, executing Ruby code in `<% %>` blocks to work out final request
86
- test_values = test_values.transform_keys_to_symbols if Soaspec::Environment.always_use_keys?
86
+ test_values = test_values.transform_keys_to_symbols if Soaspec.always_use_keys?
87
87
  begin
88
88
  if @request_option == :template
89
89
  request_body = File.read('template/' + template_name + '.xml')
@@ -101,7 +101,7 @@ module Soaspec
101
101
  # This will set the @request_option instance variable too
102
102
  def default_hash=(hash)
103
103
  @request_option = :hash
104
- @default_hash = Soaspec::Environment.always_use_keys? ? hash.transform_keys_to_symbols : hash
104
+ @default_hash = Soaspec.always_use_keys? ? hash.transform_keys_to_symbols : hash
105
105
  end
106
106
 
107
107
  # @param [Hash] format Format of expected result
@@ -146,7 +146,7 @@ module Soaspec
146
146
  def xpath_value_for(exchange: nil, xpath: nil)
147
147
  raise ArgumentError unless exchange && xpath
148
148
  result =
149
- if Soaspec::Environment.strip_namespaces? && !xpath.include?(':')
149
+ if Soaspec.strip_namespaces? && !xpath.include?(':')
150
150
  temp_doc = exchange.response.doc
151
151
  temp_doc.remove_namespaces!
152
152
  temp_doc.xpath(xpath).first
@@ -39,14 +39,23 @@ module Soaspec
39
39
  require 'rspec/core/rake_task' # See See https://relishapp.com/rspec/rspec-core/docs/command-line/rake-task for details
40
40
 
41
41
  # This runs `rspec` command with the following options. Type `rake spec` to run this task
42
- RSpec::Core::RakeTask.new(:spec) do |t|
42
+ RSpec::Core::RakeTask.new(:run_spec) do |t|
43
43
  t.pattern = "spec/*_spec.rb" # Run all specs in 'spec' folder ending in '_spec'
44
44
  # Next line shows output on the screen, Junit xml report and an HTML report
45
45
  t.rspec_opts = "--format documentation --format RspecJunitFormatter --out logs/spec.xml --format html --out logs/spec.html"
46
46
  t.fail_on_error = false
47
47
  end
48
48
 
49
+ task :spec => %w[start_test_server run_spec]
50
+
49
51
  task :default => :spec # This runs the 'spec' task by default when no task is mentioned. E.g., if only `rake` is typed
52
+
53
+ desc 'Start virtual web service'
54
+ task :start_test_server do
55
+ ENV['test_server_pid'] = Process.spawn('ruby', 'spec/test_server.rb').to_s #, err: "/dev/null").to_s - TODO: use to turn off debugging
56
+ puts 'Running test server at pid ' + ENV['test_server_pid']
57
+ end
58
+
50
59
  EOF
51
60
  end
52
61
 
@@ -59,6 +68,7 @@ gem 'require_all'
59
68
  gem 'rspec_junit_formatter'
60
69
  gem 'rake'
61
70
  gem 'soaspec'
71
+ gem 'sinatra'
62
72
 
63
73
  EOF
64
74
  end
@@ -78,6 +88,12 @@ RSpec.configure do |config|
78
88
  config.backtrace_exclusion_patterns = [
79
89
  /rspec/
80
90
  ]
91
+
92
+ # Close test server after all RSpec tests have run
93
+ config.after(:suite) do
94
+ Process.kill(:QUIT, ENV['test_server_pid'].to_i) # && Process.wait - causes failure
95
+ end
96
+
81
97
  end
82
98
 
83
99
  EOF
@@ -123,5 +139,108 @@ Reports are shown in the 'logs' folder. By default Rake produces a junit, an htm
123
139
  EOF
124
140
  end
125
141
 
142
+ def test_server_content
143
+ <<-FILEEOF
144
+ # Used to run virtual web service on localhost. This makes tests more reliable and faster
145
+
146
+ require 'sinatra'
147
+ require 'nokogiri'
148
+ require 'erb'
149
+
150
+ # Representing a GetBank SOAP service
151
+ class GetBank
152
+
153
+ def self.success_response_template
154
+ <<-EOF
155
+ <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
156
+ <soapenv:Body>
157
+ <ns1:getBankResponse xmlns:ns1="http://thomas-bayer.com/blz/">
158
+ <ns1:details>
159
+ <ns1:bezeichnung>Deutsche Bank</ns1:bezeichnung>
160
+ <ns1:bic>DEUTDEMMXXX <%= soap_action %></ns1:bic>
161
+ <ns1:ort>München</ns1:ort>
162
+ <ns1:plz><%= @test_id %></ns1:plz>
163
+ </ns1:details>
164
+ </ns1:getBankResponse>
165
+ </soapenv:Body>
166
+ </soapenv:Envelope>
167
+ EOF
168
+ end
169
+
170
+ def self.error_response_template
171
+ <<-EOF
172
+ <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
173
+ <soapenv:Body>
174
+ <soapenv:Fault>
175
+ <soapenv:Code>
176
+ <soapenv:Value>soapenv:Receiver</soapenv:Value>
177
+ </soapenv:Code>
178
+ <soapenv:Reason>
179
+ <soapenv:Text xml:lang="en-US">org.apache.axis2.databinding.ADBException: Unexpected subelement getBank</soapenv:Text>
180
+ </soapenv:Reason>
181
+ <soapenv:Detail>
182
+ <Exception>org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement getBank
183
+ at org.apache.axis2.AxisFault.makeFault(AxisFault.java:417)
184
+ at com.thomas_bayer.blz.BLZServiceMessageReceiverInOut.fromOM(BLZServiceMessageReceiverInOut.java:124)
185
+ at com.thomas_bayer.blz.BLZServiceMessageReceiverInOut.invokeBusinessLogic(BLZServiceMessageReceiverInOut.java:43)
186
+ at org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver.invokeBusinessLogic(AbstractInOutSyncMessageReceiver.java:42)
187
+ at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:96)
188
+ at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:145)
189
+ at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275)
190
+ at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:120)
191
+ at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
192
+ at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
193
+ at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
194
+ at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
195
+ at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
196
+ at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
197
+ at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
198
+ at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
199
+ at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
200
+ at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
201
+ at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
202
+ at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
203
+ at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
204
+ at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
205
+ at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
206
+ at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
207
+ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
208
+ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
209
+ at java.lang.Thread.run(Thread.java:745)
210
+ Caused by: java.lang.Exception: org.apache.axis2.databinding.ADBException: Unexpected subelement getBank
211
+ at com.thomas_bayer.adb.GetBankType$Factory.parse(GetBankType.java:423)
212
+ at com.thomas_bayer.adb.GetBank$Factory.parse(GetBank.java:304)
213
+ at com.thomas_bayer.blz.BLZServiceMessageReceiverInOut.fromOM(BLZServiceMessageReceiverInOut.java:117)
214
+ ... 25 more
215
+ Caused by: org.apache.axis2.databinding.ADBException: Unexpected subelement getBank
216
+ at com.thomas_bayer.adb.GetBankType$Factory.parse(GetBankType.java:410)
217
+ ... 27 more
218
+ </Exception>
219
+ </soapenv:Detail>
220
+ </soapenv:Fault>
221
+ </soapenv:Body>
222
+ </soapenv:Envelope>
223
+ EOF
224
+ end
225
+
226
+ def self.response_for(request)
227
+ request_body = request.body
228
+ soap_action = request.env['HTTP_SOAPACTION'].strip
229
+ doc = Nokogiri::XML(request_body)
230
+ blz_element = doc.xpath('//tns:blz').first
231
+ return 500, error_response_template unless blz_element
232
+ @test_id = blz_element.inner_text
233
+ ERB.new(success_response_template).result(binding)
234
+ end
235
+ end
236
+
237
+ # This is the one being hit
238
+ post '/BLZService' do
239
+ GetBank.response_for request
240
+ end
241
+ FILEEOF
242
+ end
243
+
244
+
126
245
  end
127
246
  end
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.0.38'
2
+ VERSION = '0.0.39'
3
3
  end
@@ -1,10 +1,7 @@
1
- <s12:Envelope xmlns:s12='http://www.w3.org/2003/05/soap-envelope'>
2
- <s12:Body>
3
- <ns1:GetWeather xmlns:ns1='http://www.webserviceX.NET'>
4
- <!-- optional -->
5
- <ns1:CityName><%= test_values[:city_name] || 'Wellington' %></ns1:CityName>
6
- <!-- optional -->
7
- <ns1:CountryName><%= test_values[:country] || 'New Zealand' %></ns1:CountryName>
8
- </ns1:GetWeather>
9
- </s12:Body>
10
- </s12:Envelope>
1
+ <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://thomas-bayer.com/blz/" xmlns:env="http://www.w3.org/2003/05/soap-envelope">
2
+ <env:Body>
3
+ <tns:getBank>
4
+ <tns:blz><%= test_values[:blz] || '70070010' %></tns:blz>
5
+ </tns:getBank>
6
+ </env:Body>
7
+ </env:Envelope>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soaspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.38
4
+ version: 0.0.39
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-20 00:00:00.000000000 Z
11
+ date: 2018-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -159,6 +159,7 @@ files:
159
159
  - LICENSE.txt
160
160
  - README.md
161
161
  - Rakefile
162
+ - Todo.md
162
163
  - bin/console
163
164
  - bin/setup
164
165
  - config/data/default.yml