lib/soaspec/exe_helpers.rb in soaspec-0.0.76 vs lib/soaspec/exe_helpers.rb in soaspec-0.0.77
- old
+ new
@@ -253,8 +253,228 @@
GetBank.response_for request
end
FILEEOF
end
+ def weather_web_service
+ <<-WEATH_WEB
+ require 'soaspec'
+
+ # This class is not part of the gem. It's an example of a class you can make
+ # to describe your APIs. Usually this would exist in the 'lib' directory
+ # Common configuration for the Savon client should go here
+ class BLZService < Soaspec::SoapHandler
+ # Add to or override default Savon client options
+ def savon_options
+ {
+ # wsdl: 'http://www.thomas-bayer.com/axis2/services/BLZService?wsdl' # External
+ wsdl: File.join('spec', 'test_data', 'wsdl', 'get_bank.wsdl')
+ }
+ end
+
+ # # Specifying that get_weather_result must be present in the SOAP response
+ mandatory_elements [:plz]
+
+ # Example of xpath value that must be true for all success scenarios
+ mandatory_xpath_values 'ns1:bezeichnung' => 'Deutsche Bank'
+
+ # Example of setting an attribute on the root XML element
+ root_attributes 'Version' => '1' # TODO: Create test on request for this
+
+ end
+
+ WEATH_WEB
+ end
+
+ def soap_spec_content
+ <<-SOAP_SPEC
+
+ require 'spec_helper'
+
+ Soaspec.strip_namespaces = true # This allows namespace not to be used. Be careful with this
+
+ id = '70070010'
+ # BLZService.new(template_name: 'soap_template') Use this instead of default_hash to use template approach
+
+ context 'Test Examples' do
+ context BLZService.new('Get Bank', operation: :get_bank, default_hash: { blz: id }) do
+
+ describe Exchange.new(:default) do
+ it { is_expected.to contain_value id }
+ it { is_expected.to include_in_body id }
+ it_behaves_like 'success scenario'
+ after(:all) { described_class.store(:title, 'bezeichnung') }
+ end
+
+ describe Exchange.new(:xpath_eg, blz: 100000) do
+ its(['plz']) { is_expected.to eq '100000' }
+ it { is_expected.to have_xpath_value '//ns1:bezeichnung' => 'Deutsche Bank' }
+ context 'Handle retrieving stored value' do
+ it { is_expected.to have_xpath_value 'bezeichnung' => described_class.retrieve(:title) }
+ end
+ end
+
+ describe Exchange.new(:yaml_eg, data_for(:small_id)) do
+ it_behaves_like 'success scenario'
+ end
+
+ # Retry for success more for web services that intermittently fail
+ describe Exchange.new(:short_hand_xpath).retry_for_success do
+ # Be careful. If you call a method that does not use namespaces, calling one that does may not find the element
+ its(['ns1:bezeichnung']) { is_expected.to eq 'Deutsche Bank' } # '//' is not required at the beginning
+ end
+ describe Exchange.new('Check existence of elements') do
+ it { is_expected.to have_element_at_xpath '//ns1:bezeichnung' }
+ it { is_expected.not_to have_element_at_xpath '//ns1:bezeichnung_pretend' }
+ end
+
+ end
+ end
+
+ error_example = BLZService.new('Error example')
+ error_example.operation = :get_bank
+ error_example.default_hash = {}
+
+ context 'Error Examples' do
+ context error_example do
+ describe Exchange.new(:no_blz_error) do
+ it_behaves_like 'error scenario'
+ end
+ end
+ end
+
+
+ SOAP_SPEC
+ end
+
+ def shared_examples_content
+ <<-SHARE_EG
+
+ require 'rspec'
+
+ shared_examples_for 'error scenario' do
+ it 'does not have status code of 200' do
+ expect(described_class.status_code).not_to eq 200
+ end
+ end
+
+ SHARE_EG
+ end
+
+ def soap_template_content
+ <<-SOAP_TEMP
+ <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">
+ <env:Body>
+ <tns:getBank>
+ <tns:blz><%= test_values[:blz] || '70070010' %></tns:blz>
+ </tns:getBank>
+ </env:Body>
+ </env:Envelope>
+ SOAP_TEMP
+ end
+
+ def default_yaml_content
+ <<-DEF_YAML
+ small_id:
+ blz: 100
+
+ DEF_YAML
+ end
+
+ def test_wsdl_content
+ <<TEST_WSDL
+ <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/">
+ <wsdl:documentation>BLZService</wsdl:documentation>
+ <wsdl:types>
+ <xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://thomas-bayer.com/blz/">
+ <xsd:element name="getBank" type="tns:getBankType"/>
+ <xsd:element name="getBankResponse" type="tns:getBankResponseType"/>
+ <xsd:complexType name="getBankType">
+ <xsd:sequence>
+ <xsd:element name="blz" type="xsd:string"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ <xsd:complexType name="getBankResponseType">
+ <xsd:sequence>
+ <xsd:element name="details" type="tns:detailsType"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ <xsd:complexType name="detailsType">
+ <xsd:sequence>
+ <xsd:element minOccurs="0" name="bezeichnung" type="xsd:string"/>
+ <xsd:element minOccurs="0" name="bic" type="xsd:string"/>
+ <xsd:element minOccurs="0" name="ort" type="xsd:string"/>
+ <xsd:element minOccurs="0" name="plz" type="xsd:string"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:schema>
+ </wsdl:types>
+ <wsdl:message name="getBank">
+ <wsdl:part name="parameters" element="tns:getBank"/>
+ </wsdl:message>
+ <wsdl:message name="getBankResponse">
+ <wsdl:part name="parameters" element="tns:getBankResponse"/>
+ </wsdl:message>
+ <wsdl:portType name="BLZServicePortType">
+ <wsdl:operation name="getBank">
+ <wsdl:input message="tns:getBank"/>
+ <!--<wsdl:output message="tns:getBankResponse" wsaw:Action="http://thomas-bayer.com/blz/BLZService/getBankResponse"/>-->
+ <wsdl:output message="tns:getBankResponse" wsaw:Action="http://localhost:4567/BLZService/getBankResponse"/>
+ </wsdl:operation>
+ </wsdl:portType>
+ <wsdl:binding name="BLZServiceSOAP11Binding" type="tns:BLZServicePortType">
+ <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
+ <wsdl:operation name="getBank">
+ <soap:operation style="document" soapAction=""/>
+ <wsdl:input>
+ <soap:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output>
+ <soap:body use="literal"/>
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:binding name="BLZServiceSOAP12Binding" type="tns:BLZServicePortType">
+ <soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
+ <wsdl:operation name="getBank">
+ <soap12:operation style="document" soapAction=""/>
+ <wsdl:input>
+ <soap12:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output>
+ <soap12:body use="literal"/>
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:binding name="BLZServiceHttpBinding" type="tns:BLZServicePortType">
+ <http:binding verb="POST"/>
+ <wsdl:operation name="getBank">
+ <http:operation location="BLZService/getBank"/>
+ <wsdl:input>
+ <mime:content part="getBank" type="text/xml"/>
+ </wsdl:input>
+ <wsdl:output>
+ <mime:content part="getBank" type="text/xml"/>
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:service name="BLZService">
+ <wsdl:port name="BLZServiceSOAP11port_http" binding="tns:BLZServiceSOAP11Binding">
+ <!-- <soap:address location="http://www.thomas-bayer.com/axis2/services/BLZService"/> -->
+ <soap:address location="http://localhost:4567/BLZService"/>
+ </wsdl:port>
+ <wsdl:port name="BLZServiceSOAP12port_http" binding="tns:BLZServiceSOAP12Binding">
+ <!--<soap12:address location="http://www.thomas-bayer.com/axis2/services/BLZService"/>-->
+ <soap12:address location="http://localhost:4567/BLZService"/>
+ </wsdl:port>
+ <wsdl:port name="BLZServiceHttpport" binding="tns:BLZServiceHttpBinding">
+ <!--<http:address location="http://www.thomas-bayer.com/axis2/services/BLZService"/>-->
+ <soap:address location="http://localhost:4567/BLZService"/>
+ </wsdl:port>
+ </wsdl:service>
+ </wsdl:definitions>
+
+TEST_WSDL
+ end
end
end
\ No newline at end of file