soaspec 0.0.20 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +5 -0
- data/Gemfile.lock +1 -1
- data/exe/soaspec-generate +151 -0
- data/exe/xml_to_yaml_file +1 -0
- data/lib/soaspec/file_helpers.rb +35 -0
- data/lib/soaspec/version.rb +1 -1
- data/lib/soaspec.rb +1 -0
- data/test.wsdl +116 -0
- data/test.xml +11 -0
- data/test_wsdl.rb +24 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b09938e8351c03ff15494fa89c411b85bd8af58c
|
4
|
+
data.tar.gz: ce6cfc6a66d8d6c3e5d5fdba9a610641aed66dff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ba1180cc9d2fe32b560c78580d46ce12beb6a15c9bda03bddfac3349baa1fffb4fafdac92e1e5d0d030b5030965227401bc8e8ecd471b133f6aef726d9c4309
|
7
|
+
data.tar.gz: f817ca8fa2e596e939c079a3ef04dca40961ee278195ceece0829dd53b5ecd62f8e334c160535d1f0992410ac21e01f2bbd530e14a37c685b582bfe3aaf05c63
|
data/ChangeLog
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
Version 0.0.21 / 2018-1-29
|
2
|
+
* Enhancements
|
3
|
+
* Added soaspec-generate - still in POC mode to generate files from a WSDL.
|
4
|
+
* Added test_wsdl to start at validating xml according to WSDL. Still needs polishing
|
5
|
+
|
1
6
|
Version 0.0.20 / 2018-1-26
|
2
7
|
* Enhancements
|
3
8
|
* Added ability to strip namespaces 'Soaspec::Environment.strip_namespaces = true'. See spec for example
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,151 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Generate Soaspec tests from a WSDL. Later Swagger, other definitions will be added
|
4
|
+
#
|
5
|
+
#http://www.webservicex.com/globalweather.asmx?wsdl
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
8
|
+
|
9
|
+
require 'savon'
|
10
|
+
require 'soaspec'
|
11
|
+
|
12
|
+
def fill_in_field_from_type(type)
|
13
|
+
case type
|
14
|
+
when 'string'
|
15
|
+
'test string'
|
16
|
+
else
|
17
|
+
'test'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.ask_wsdl
|
22
|
+
prompt = <<-EOF
|
23
|
+
Enter WSDL:
|
24
|
+
EOF
|
25
|
+
print prompt.chop
|
26
|
+
@wsdl = $stdin.gets.strip
|
27
|
+
puts
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.name_of_wsdl
|
31
|
+
prompt = <<-EOF
|
32
|
+
Enter what you would like to name WSDL (CamelCase):
|
33
|
+
EOF
|
34
|
+
print prompt.chop
|
35
|
+
@name = $stdin.gets.strip
|
36
|
+
puts
|
37
|
+
end
|
38
|
+
|
39
|
+
def camel_case(underscore_seperated)
|
40
|
+
underscore_seperated.to_s.split('_').collect(&:capitalize).join
|
41
|
+
end
|
42
|
+
|
43
|
+
@class_content = <<-EOF
|
44
|
+
|
45
|
+
require 'soaspec'
|
46
|
+
|
47
|
+
class <%= @name %> < Soaspec::BasicSoapHandler
|
48
|
+
# Add to or override default Savon client options
|
49
|
+
def savon_options
|
50
|
+
{
|
51
|
+
wsdl: '<%= @wsdl %>',
|
52
|
+
convert_request_keys_to: :camelcase # Remove this if request is not in camelcase
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
EOF
|
58
|
+
|
59
|
+
@soap_spec_content = <<-EOF
|
60
|
+
|
61
|
+
require 'spec_helper'
|
62
|
+
|
63
|
+
Soaspec::Environment.strip_namespaces = true # This allows namespace not to be used. Be careful with this
|
64
|
+
|
65
|
+
<%= operation %> = <%= @name %>.new('<%= camel_case(operation) %>')
|
66
|
+
<%= operation %>.operation = :<%= operation %>
|
67
|
+
<%= operation %>.default_hash = data_for '<%= operation %>/default'
|
68
|
+
|
69
|
+
context <%= operation %> do
|
70
|
+
describe Exchange.new(:default) do
|
71
|
+
it_behaves_like 'success scenario'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
EOF
|
76
|
+
|
77
|
+
rake_content = <<-EOF
|
78
|
+
# The list of task for a Rake file can be seen with `rake -T`
|
79
|
+
require 'rspec/core/rake_task' # See See https://relishapp.com/rspec/rspec-core/docs/command-line/rake-task for details
|
80
|
+
|
81
|
+
# This runs `rspec` command with the following options. Type `rake spec` to run this task
|
82
|
+
RSpec::Core::RakeTask.new(:spec) do |t, task_args|
|
83
|
+
t.pattern = "spec/*_spec.rb" # Run all specs in 'spec' folder ending in '_spec'
|
84
|
+
# Next line shows output on the screen, Junit xml report and an HTML report
|
85
|
+
t.rspec_opts = "--format documentation --format RspecJunitFormatter --out logs/spec.xml --format html --out logs/spec.html"
|
86
|
+
t.fail_on_error = false
|
87
|
+
end
|
88
|
+
|
89
|
+
task :default => :spec # This runs the 'spec' task by default when no task is mentioned. E.g., if only `rake` is typed
|
90
|
+
EOF
|
91
|
+
|
92
|
+
|
93
|
+
gem_content = <<-EOF
|
94
|
+
|
95
|
+
source 'https://rubygems.org'
|
96
|
+
|
97
|
+
gem 'data_magic'
|
98
|
+
gem 'require_all'
|
99
|
+
gem 'rspec_junit_formatter'
|
100
|
+
gem 'rake'
|
101
|
+
gem 'soaspec'
|
102
|
+
|
103
|
+
EOF
|
104
|
+
|
105
|
+
spec_helper_content = <<-EOF
|
106
|
+
|
107
|
+
require 'soaspec'
|
108
|
+
require 'require_all'
|
109
|
+
require_all 'lib'
|
110
|
+
require 'data_magic'
|
111
|
+
|
112
|
+
include DataMagic # Used as example of loading data smartly. Use 'data_for' method to load yml data
|
113
|
+
|
114
|
+
RSpec.configure do |config|
|
115
|
+
# This will make backtrace much shorter by removing many lines from rspec failure message
|
116
|
+
config.backtrace_exclusion_patterns = [
|
117
|
+
/rspec/
|
118
|
+
]
|
119
|
+
end
|
120
|
+
|
121
|
+
EOF
|
122
|
+
|
123
|
+
name_of_wsdl
|
124
|
+
ask_wsdl
|
125
|
+
|
126
|
+
wsdl_doc = Savon.client(wsdl: @wsdl).wsdl
|
127
|
+
|
128
|
+
# Basics. May already be there
|
129
|
+
Soaspec::FileHelpers.create_file filename: 'Rakefile', content: rake_content, ignore_if_present: true
|
130
|
+
Soaspec::FileHelpers.create_file filename: 'Gemfile', content: gem_content, ignore_if_present: true
|
131
|
+
Soaspec::FileHelpers.create_folder 'spec'
|
132
|
+
Soaspec::FileHelpers.create_file(filename: 'spec/spec_helper.rb', content: spec_helper_content)
|
133
|
+
|
134
|
+
module Soaspec::FileHelpers
|
135
|
+
create_folder 'logs'
|
136
|
+
create_folder 'config'
|
137
|
+
create_folder 'config/data'
|
138
|
+
create_folder 'lib'
|
139
|
+
end
|
140
|
+
Soaspec::FileHelpers.create_file filename: "lib/#{@name}.rb", content: ERB.new(@class_content).result(binding)
|
141
|
+
|
142
|
+
wsdl_doc.operations.each do |operation, details|
|
143
|
+
puts "Creating files for operation: #{operation}"
|
144
|
+
@content = "default:\n"
|
145
|
+
details[:parameters].each do |element, details|
|
146
|
+
@content += " #{element.to_s}: #{fill_in_field_from_type(details[:type])} \n"
|
147
|
+
end
|
148
|
+
|
149
|
+
Soaspec::FileHelpers.create_file(filename: "config/data/#{operation}.yml", content: @content)
|
150
|
+
Soaspec::FileHelpers.create_file(filename: "spec/#{operation}_spec.rb", content: ERB.new(@soap_spec_content).result(binding))
|
151
|
+
end
|
data/exe/xml_to_yaml_file
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
module Soaspec
|
3
|
+
module FileHelpers
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
def self.create_file(options)
|
7
|
+
filename = options[:filename]
|
8
|
+
raise 'Need to pass filename' unless filename
|
9
|
+
content = options[:content]
|
10
|
+
raise 'Need to pass contents to insert into file' unless content
|
11
|
+
if File.exist? filename
|
12
|
+
old_content = File.read(filename)
|
13
|
+
if old_content != content && !options[:ignore_if_present]
|
14
|
+
warn "!! #{filename} already exists and differs from template"
|
15
|
+
end
|
16
|
+
else
|
17
|
+
File.open(filename, 'w') do |f|
|
18
|
+
f.puts content
|
19
|
+
end
|
20
|
+
puts 'Created: ' + filename
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.create_folder(folder)
|
25
|
+
if File.exists? folder
|
26
|
+
unless File.directory? folder
|
27
|
+
$stderr.puts "!! #{folder} already exists and is not a directory"
|
28
|
+
end
|
29
|
+
else
|
30
|
+
FileUtils.mkdir folder
|
31
|
+
puts "Created folder: #{folder}/"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/soaspec/version.rb
CHANGED
data/lib/soaspec.rb
CHANGED
data/test.wsdl
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
<wsdl:definitions
|
2
|
+
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
|
3
|
+
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
|
4
|
+
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
|
5
|
+
xmlns:tns="http://Example.org"
|
6
|
+
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
|
7
|
+
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
|
8
|
+
xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy"
|
9
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
10
|
+
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract"
|
11
|
+
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
|
12
|
+
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
|
13
|
+
xmlns:wsa10="http://www.w3.org/2005/08/addressing"
|
14
|
+
xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" targetNamespace="http://Example.org"
|
15
|
+
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
|
16
|
+
<wsdl:types>
|
17
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
18
|
+
targetNamespace="https://www.w3schools.com"
|
19
|
+
xmlns="https://www.w3schools.com"
|
20
|
+
elementFormDefault="qualified">
|
21
|
+
|
22
|
+
<xs:element name="note">
|
23
|
+
<xs:complexType>
|
24
|
+
<xs:sequence>
|
25
|
+
<xs:element name="to" type="xs:string"/>
|
26
|
+
<xs:element name="from" type="xs:string"/>
|
27
|
+
<xs:element name="heading" type="xs:string"/>
|
28
|
+
<xs:element name="body" type="xs:string"/>
|
29
|
+
</xs:sequence>
|
30
|
+
</xs:complexType>
|
31
|
+
</xs:element>
|
32
|
+
|
33
|
+
</xs:schema>
|
34
|
+
<s:schema xmlns:s="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.webserviceX.NET">
|
35
|
+
<s:element name="GetWeather">
|
36
|
+
<s:complexType>
|
37
|
+
<s:sequence>
|
38
|
+
<s:element minOccurs="0" maxOccurs="1" name="CityName" type="s:string"/>
|
39
|
+
<s:element minOccurs="0" maxOccurs="1" name="CountryName" type="s:string"/>
|
40
|
+
</s:sequence>
|
41
|
+
</s:complexType>
|
42
|
+
</s:element>
|
43
|
+
<s:element name="GetWeatherResponse">
|
44
|
+
<s:complexType>
|
45
|
+
<s:sequence>
|
46
|
+
<s:element minOccurs="0" maxOccurs="1" name="GetWeatherResult" type="s:string"/>
|
47
|
+
</s:sequence>
|
48
|
+
</s:complexType>
|
49
|
+
</s:element>
|
50
|
+
<s:element name="GetCitiesByCountry">
|
51
|
+
<s:complexType>
|
52
|
+
<s:sequence>
|
53
|
+
<s:element minOccurs="0" maxOccurs="1" name="CountryName" type="s:string"/>
|
54
|
+
</s:sequence>
|
55
|
+
</s:complexType>
|
56
|
+
</s:element>
|
57
|
+
<s:element name="GetCitiesByCountryResponse">
|
58
|
+
<s:complexType>
|
59
|
+
<s:sequence>
|
60
|
+
<s:element minOccurs="0" maxOccurs="1" name="GetCitiesByCountryResult" type="s:string"/>
|
61
|
+
</s:sequence>
|
62
|
+
</s:complexType>
|
63
|
+
</s:element>
|
64
|
+
<s:element name="string" nillable="true" type="s:string"/>
|
65
|
+
</s:schema>
|
66
|
+
|
67
|
+
</wsdl:types>
|
68
|
+
<wsdl:message name="ICalculator_Add_InputMessage">
|
69
|
+
<wsdl:part name="parameters" element="tns:Add" />
|
70
|
+
</wsdl:message>
|
71
|
+
<wsdl:message name="ICalculator_Add_OutputMessage">
|
72
|
+
<wsdl:part name="parameters" element="tns:AddResponse" />
|
73
|
+
</wsdl:message>
|
74
|
+
<wsdl:message name="ICalculator_Subtract_InputMessage">
|
75
|
+
<wsdl:part name="parameters" element="tns:Subtract" />
|
76
|
+
</wsdl:message>
|
77
|
+
<wsdl:message name="ICalculator_Subtract_OutputMessage">
|
78
|
+
<wsdl:part name="parameters" element="tns:SubtractResponse" />
|
79
|
+
</wsdl:message>
|
80
|
+
<wsdl:portType name="ICalculator">
|
81
|
+
<wsdl:operation name="Add">
|
82
|
+
<wsdl:input wsaw:Action="http://Example.org/ICalculator/Add" message="tns:ICalculator_Add_InputMessage" />
|
83
|
+
<wsdl:output wsaw:Action="http://Example.org/ICalculator/AddResponse" message="tns:ICalculator_Add_OutputMessage" />
|
84
|
+
</wsdl:operation>
|
85
|
+
<wsdl:operation name="Subtract">
|
86
|
+
<wsdl:input wsaw:Action="http://Example.org/ICalculator/Subtract" message="tns:ICalculator_Subtract_InputMessage" />
|
87
|
+
<wsdl:output wsaw:Action="http://Example.org/ICalculator/SubtractResponse" message="tns:ICalculator_Subtract_OutputMessage" />
|
88
|
+
</wsdl:operation>
|
89
|
+
</wsdl:portType>
|
90
|
+
<wsdl:binding name="DefaultBinding_ICalculator" type="tns:ICalculator">
|
91
|
+
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
|
92
|
+
<wsdl:operation name="Add">
|
93
|
+
<soap:operation soapAction="http://Example.org/ICalculator/Add" style="document" />
|
94
|
+
<wsdl:input>
|
95
|
+
<soap:body use="literal" />
|
96
|
+
</wsdl:input>
|
97
|
+
<wsdl:output>
|
98
|
+
<soap:body use="literal" />
|
99
|
+
</wsdl:output>
|
100
|
+
</wsdl:operation>
|
101
|
+
<wsdl:operation name="Subtract">
|
102
|
+
<soap:operation soapAction="http://Example.org/ICalculator/Subtract" style="document" />
|
103
|
+
<wsdl:input>
|
104
|
+
<soap:body use="literal" />
|
105
|
+
</wsdl:input>
|
106
|
+
<wsdl:output>
|
107
|
+
<soap:body use="literal" />
|
108
|
+
</wsdl:output>
|
109
|
+
</wsdl:operation>
|
110
|
+
</wsdl:binding>
|
111
|
+
<wsdl:service name="CalculatorService">
|
112
|
+
<wsdl:port name="ICalculator" binding="tns:DefaultBinding_ICalculator">
|
113
|
+
<soap:address location="http://Example.org/ICalculator" />
|
114
|
+
</wsdl:port>
|
115
|
+
</wsdl:service>
|
116
|
+
</wsdl:definitions>
|
data/test.xml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
|
3
|
+
<note
|
4
|
+
xmlns="https://www.w3schools.com"
|
5
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
6
|
+
xsi:schemaLocation="https://www.w3schools.com/xml/note.xsd">
|
7
|
+
<to>Tove</to>
|
8
|
+
<from>123.2</from>
|
9
|
+
<heading>Reminder</heading>
|
10
|
+
<body>Don't forget me this weekend!</body>
|
11
|
+
</note>
|
data/test_wsdl.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
require 'wasabi'
|
3
|
+
require 'savon'
|
4
|
+
|
5
|
+
|
6
|
+
document = Savon.client(wsdl: 'test.wsdl').wsdl
|
7
|
+
#document = Savon.client(wsdl: 'http://www.webservicex.com/globalweather.asmx?wsdl').wsdl
|
8
|
+
#document = Wasabi.document File.read('test.wsdl')
|
9
|
+
parser = document.parser
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
parser.schemas.each do |schema|
|
14
|
+
puts 'SCHEMA * '
|
15
|
+
puts schema
|
16
|
+
|
17
|
+
xsd = Nokogiri::XML::Schema(schema.to_s)
|
18
|
+
|
19
|
+
doc = Nokogiri::XML(File.read('test.xml'))
|
20
|
+
|
21
|
+
xsd.validate(doc).each do |error|
|
22
|
+
puts error.message
|
23
|
+
end
|
24
|
+
end
|
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.
|
4
|
+
version: 0.0.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SamuelGarrattIQA
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -127,6 +127,7 @@ description: "Helps to create RSpec specs for SOAP or REST apis. Easily represen
|
|
127
127
|
email:
|
128
128
|
- samuel.garratt@integrationqa.com
|
129
129
|
executables:
|
130
|
+
- soaspec-generate
|
130
131
|
- soaspec-init
|
131
132
|
- xml_to_yaml_file
|
132
133
|
extensions: []
|
@@ -145,11 +146,13 @@ files:
|
|
145
146
|
- bin/console
|
146
147
|
- bin/setup
|
147
148
|
- config/data/default.yml
|
149
|
+
- exe/soaspec-generate
|
148
150
|
- exe/soaspec-init
|
149
151
|
- exe/xml_to_yaml_file
|
150
152
|
- lib/soaspec.rb
|
151
153
|
- lib/soaspec/basic_soap_handler.rb
|
152
154
|
- lib/soaspec/exchange.rb
|
155
|
+
- lib/soaspec/file_helpers.rb
|
153
156
|
- lib/soaspec/hash_methods.rb
|
154
157
|
- lib/soaspec/matchers.rb
|
155
158
|
- lib/soaspec/soaspec_shared_examples.rb
|
@@ -159,6 +162,9 @@ files:
|
|
159
162
|
- lib/soaspec/xpath_not_found.rb
|
160
163
|
- soaspec.gemspec
|
161
164
|
- template/soap_template.xml
|
165
|
+
- test.wsdl
|
166
|
+
- test.xml
|
167
|
+
- test_wsdl.rb
|
162
168
|
homepage: https://gitlab.com/samuel-garratt/soaspec
|
163
169
|
licenses:
|
164
170
|
- MIT
|