Class: Soaspec::BasicSoapHandler
- Defined in:
- lib/soaspec/basic_soap_handler.rb
Overview
Wraps around Savon client defining default values dependent on the soap request
Instance Attribute Summary collapse
-
#client ⇒ Object
Savon client used to make SOAP calls.
-
#operation ⇒ Object
SOAP Operation to use by default.
Attributes inherited from Tester
Instance Method Summary collapse
- #default_hash=(hash) ⇒ Object
-
#default_options ⇒ Hash
Default Savon options.
-
#initialize(name, specific_options = {}) ⇒ BasicSoapHandler
constructor
Setup object to handle communicating with a particular SOAP WSDL.
-
#logging_options ⇒ Object
Options to log xml request and response.
-
#make_request(override_parameters) ⇒ Object
Used in together with Exchange request that passes such override parameters.
-
#mandatory_elements ⇒ Array
Override this to specify elements that must be present in the response Will be used in ‘success_scenarios’ shared examples.
-
#mandatory_xpath_values ⇒ Hash
Override this to specify xpath results that must be present in the response Will be used in ‘success_scenarios’ shared examples.
- #name(name) ⇒ Object
- #override(request_parameters) ⇒ Object
-
#root_attributes ⇒ Object
Attributes set at the root XML element of SOAP request.
-
#savon_options ⇒ Hash
Add values to here when extending this class to have default Savon options.
- #status_code_for(response) ⇒ Object
- #value_from_path(exchange, path) ⇒ Object
- #xpath_value_for(param) ⇒ Object
Methods inherited from Tester
Constructor Details
#initialize(name, specific_options = {}) ⇒ BasicSoapHandler
Setup object to handle communicating with a particular SOAP WSDL
50 51 52 53 54 55 56 |
# File 'lib/soaspec/basic_soap_handler.rb', line 50 def initialize(name, = {}) = .merge .merge! .merge!() @client = Savon.client() super end |
Instance Attribute Details
#client ⇒ Object
Savon client used to make SOAP calls
9 10 11 |
# File 'lib/soaspec/basic_soap_handler.rb', line 9 def client @client end |
#operation ⇒ Object
SOAP Operation to use by default
11 12 13 |
# File 'lib/soaspec/basic_soap_handler.rb', line 11 def operation @operation end |
Instance Method Details
#default_hash=(hash) ⇒ Object
83 84 85 86 |
# File 'lib/soaspec/basic_soap_handler.rb', line 83 def default_hash=(hash) @request_option = :hash @default_hash = hash end |
#default_options ⇒ Hash
Default Savon options. See savonrb.com/version2/globals.html for details
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/soaspec/basic_soap_handler.rb', line 25 def { ssl_verify_mode: :none, # Easier for testing. Not so secure follow_redirects: true, # Necessary for many API calls soap_version: 2, # use SOAP 1.2. You will get 415 error if this is incorrect raise_errors: false # HTTP errors not cause failure as often negative test scenarios expect not 200 response # Things could go wrong if not set properly # env_namespace: :soap, # Change environment namespace # namespace_identifier: :tst, # Change namespace element # element_form_default: :qualified # Populate each element with namespace # namespace: 'http://Extended_namespace.xsd' change root namespace # basic_auth: 'user', 'password' } end |
#logging_options ⇒ Object
Options to log xml request and response
14 15 16 17 18 19 20 21 |
# File 'lib/soaspec/basic_soap_handler.rb', line 14 def { log: true, # See request and response. (Put this in traffic file) log_level: :debug, logger: Soaspec::SpecLogger.create, pretty_print_xml: true # Prints XML pretty } end |
#make_request(override_parameters) ⇒ Object
Used in together with Exchange request that passes such override parameters
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/soaspec/basic_soap_handler.rb', line 70 def make_request(override_parameters) test_values = override_parameters # Used in Erb # Erb parses template file, executing Ruby code in `<% %>` blocks to work out final request test_values = test_values.transform_keys_to_symbols # Either string or symbol if @request_option == :template request_body = File.read('template/' + template_name + '.xml') render_body = ERB.new(request_body).result(binding) @client.call(operation, xml: render_body) # Call the SOAP operation with the request XML provided elsif @request_option == :hash @client.call(operation, message: @default_hash.merge(test_values), attributes: root_attributes) end end |
#mandatory_elements ⇒ Array
Override this to specify elements that must be present in the response Will be used in ‘success_scenarios’ shared examples
95 96 97 |
# File 'lib/soaspec/basic_soap_handler.rb', line 95 def mandatory_elements [] end |
#mandatory_xpath_values ⇒ Hash
Override this to specify xpath results that must be present in the response Will be used in ‘success_scenarios’ shared examples
102 103 104 |
# File 'lib/soaspec/basic_soap_handler.rb', line 102 def mandatory_xpath_values {} end |
#name(name) ⇒ Object
58 59 60 61 62 |
# File 'lib/soaspec/basic_soap_handler.rb', line 58 def name(name) @test_values = {} @test_name = name self end |
#override(request_parameters) ⇒ Object
64 65 66 67 |
# File 'lib/soaspec/basic_soap_handler.rb', line 64 def override(request_parameters) @test_values = request_parameters self end |
#root_attributes ⇒ Object
Attributes set at the root XML element of SOAP request
107 108 109 |
# File 'lib/soaspec/basic_soap_handler.rb', line 107 def root_attributes nil end |
#savon_options ⇒ Hash
Add values to here when extending this class to have default Savon options. See savonrb.com/version2/globals.html for details
43 44 45 46 |
# File 'lib/soaspec/basic_soap_handler.rb', line 43 def { } end |
#status_code_for(response) ⇒ Object
88 89 90 |
# File 'lib/soaspec/basic_soap_handler.rb', line 88 def status_code_for(response) response.http.code end |
#value_from_path(exchange, path) ⇒ Object
117 118 119 120 |
# File 'lib/soaspec/basic_soap_handler.rb', line 117 def value_from_path(exchange, path) path = '//' + path if path[0] != '/' xpath_value_for(exchange: exchange, xpath: path) end |
#xpath_value_for(param) ⇒ Object
111 112 113 114 115 |
# File 'lib/soaspec/basic_soap_handler.rb', line 111 def xpath_value_for(param) result = param[:exchange].response.xpath(param[:xpath]).first raise 'No value at Xpath' unless result result.inner_text end |