soaspec 0.0.81 → 0.0.82
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +15 -15
- data/.gitlab-ci.yml +31 -31
- data/.rspec +3 -3
- data/.rubocop.yml +2 -2
- data/.travis.yml +5 -5
- data/CODE_OF_CONDUCT.md +74 -74
- data/ChangeLog +345 -341
- data/Gemfile +6 -6
- data/LICENSE.txt +21 -21
- data/README.md +85 -85
- data/Rakefile +24 -24
- data/Todo.md +6 -6
- data/exe/soaspec +123 -123
- data/exe/soaspec-virtual-server +98 -92
- data/exe/xml_to_yaml_file +60 -60
- data/lib/soaspec.rb +86 -85
- data/lib/soaspec/core_ext/hash.rb +83 -83
- data/lib/soaspec/exchange.rb +230 -230
- data/lib/soaspec/exchange_handlers/exchange_handler.rb +98 -98
- data/lib/soaspec/exchange_handlers/handler_accessors.rb +95 -95
- data/lib/soaspec/exchange_handlers/rest_handler.rb +367 -367
- data/lib/soaspec/exchange_handlers/rest_methods.rb +44 -44
- data/lib/soaspec/exchange_handlers/soap_handler.rb +231 -231
- data/lib/soaspec/exe_helpers.rb +56 -56
- data/lib/soaspec/generator/.rspec.erb +5 -5
- data/lib/soaspec/generator/.travis.yml.erb +5 -5
- data/lib/soaspec/generator/Gemfile.erb +8 -8
- data/lib/soaspec/generator/README.md.erb +29 -29
- data/lib/soaspec/generator/Rakefile.erb +19 -19
- data/lib/soaspec/generator/config/data/default.yml.erb +1 -1
- data/lib/soaspec/generator/lib/blz_service.rb.erb +24 -24
- data/lib/soaspec/generator/lib/dynamic_class_content.rb.erb +12 -12
- data/lib/soaspec/generator/lib/shared_example.rb.erb +8 -8
- data/lib/soaspec/generator/spec/dynamic_soap_spec.rb.erb +14 -14
- data/lib/soaspec/generator/spec/soap_spec.rb.erb +53 -53
- data/lib/soaspec/generator/spec/spec_helper.rb.erb +20 -20
- data/lib/soaspec/generator/template/soap_template.xml +6 -6
- data/lib/soaspec/interpreter.rb +25 -25
- data/lib/soaspec/matchers.rb +65 -65
- data/lib/soaspec/not_found_errors.rb +13 -13
- data/lib/soaspec/soaspec_shared_examples.rb +24 -24
- data/lib/soaspec/spec_logger.rb +27 -27
- data/lib/soaspec/test_server/bank.wsdl +90 -90
- data/lib/soaspec/test_server/get_bank.rb +160 -160
- data/lib/soaspec/test_server/invoices.rb +27 -27
- data/lib/soaspec/test_server/namespace.xml +15 -0
- data/lib/soaspec/test_server/note.xml +5 -5
- data/lib/soaspec/test_server/puppy_service.rb +20 -20
- data/lib/soaspec/test_server/test_attribute.rb +13 -13
- data/lib/soaspec/test_server/test_namespace.rb +13 -0
- data/lib/soaspec/version.rb +2 -2
- data/lib/soaspec/wsdl_generator.rb +93 -93
- data/soaspec.gemspec +45 -45
- data/test.wsdl +116 -116
- data/test.xml +10 -10
- data/test_rest.rb +97 -97
- data/test_wsdl.rb +43 -43
- metadata +5 -3
data/exe/soaspec-virtual-server
CHANGED
@@ -1,93 +1,99 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
4
|
-
require 'soaspec'
|
5
|
-
require 'sinatra'
|
6
|
-
require 'sinatra/basic_auth'
|
7
|
-
require 'nokogiri'
|
8
|
-
require 'erb'
|
9
|
-
require 'json'
|
10
|
-
require 'faker'
|
11
|
-
|
12
|
-
class SoaspecVirtualServer < Sinatra::Application
|
13
|
-
|
14
|
-
# Used to run virtual web service on localhost. This makes tests more reliable and faster
|
15
|
-
|
16
|
-
set :port, 4999
|
17
|
-
|
18
|
-
# Used to test attributes
|
19
|
-
get '/test_attribute' do
|
20
|
-
Soaspec::TestServer::TestAttribute.note
|
21
|
-
end
|
22
|
-
|
23
|
-
#
|
24
|
-
|
25
|
-
Soaspec::TestServer::
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
[200,
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
JSON.generate
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
4
|
+
require 'soaspec'
|
5
|
+
require 'sinatra'
|
6
|
+
require 'sinatra/basic_auth'
|
7
|
+
require 'nokogiri'
|
8
|
+
require 'erb'
|
9
|
+
require 'json'
|
10
|
+
require 'faker'
|
11
|
+
|
12
|
+
class SoaspecVirtualServer < Sinatra::Application
|
13
|
+
|
14
|
+
# Used to run virtual web service on localhost. This makes tests more reliable and faster
|
15
|
+
|
16
|
+
set :port, 4999
|
17
|
+
|
18
|
+
# Used to test attributes
|
19
|
+
get '/test_attribute' do
|
20
|
+
Soaspec::TestServer::TestAttribute.note
|
21
|
+
end
|
22
|
+
|
23
|
+
# Used to test attributes
|
24
|
+
get '/namespace' do
|
25
|
+
# Soaspec::TestServer::TestAttribute.note
|
26
|
+
Soaspec::TestServer::TestNamespace.food
|
27
|
+
end
|
28
|
+
|
29
|
+
# This is the one being hit by SOAP actions
|
30
|
+
post '/BLZService' do
|
31
|
+
Soaspec::TestServer::GetBank.response_for request
|
32
|
+
end
|
33
|
+
|
34
|
+
# This is returned when a query for the WSDL is made
|
35
|
+
get '/BLZService' do
|
36
|
+
[200, { 'Content-Type' => 'text/xml' }, Soaspec::TestServer::GetBank.test_wsdl]
|
37
|
+
end
|
38
|
+
|
39
|
+
# Simulate retrieving an ouath token. Passed to '/invoices'
|
40
|
+
post '/as/token.oauth2' do
|
41
|
+
Soaspec::TestServer::Invoices.user_used = request.env['rack.request.form_hash']['username']
|
42
|
+
[200, Soaspec::TestServer::Invoices.oauth_headers, JSON.generate(Soaspec::TestServer::Invoices.oauth_body)]
|
43
|
+
end
|
44
|
+
|
45
|
+
get '/invoice/:id' do |id|
|
46
|
+
JSON.generate(customer_id: id, oauth: request.env['HTTP_AUTHORIZATION'], user: Soaspec::TestServer::Invoices.user_used)
|
47
|
+
end
|
48
|
+
|
49
|
+
authorize do |username, password|
|
50
|
+
username == 'admin' && password == 'secret'
|
51
|
+
end
|
52
|
+
|
53
|
+
protect do
|
54
|
+
get '/basic_secrets' do
|
55
|
+
'Secret data'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Used for testing storage of data
|
60
|
+
post '/test/puppy' do
|
61
|
+
request_hash = JSON.parse(request.body.string)
|
62
|
+
id = Soaspec::TestServer::PuppyService.new_id
|
63
|
+
Soaspec::TestServer::PuppyService.data[id][:Name] = request_hash['Name']
|
64
|
+
Soaspec::TestServer::PuppyService.data[id][:Failure_Type__c] = request_hash['Failure_Type__c'] if request_hash['Failure_Type__c']
|
65
|
+
response_hash = { result: { Status: 'success', Data: Soaspec::TestServer::PuppyService.data[id] } }
|
66
|
+
JSON.generate response_hash
|
67
|
+
end
|
68
|
+
|
69
|
+
# Used for testing retrieving storage of data
|
70
|
+
get '/test/puppy/:id' do |id|
|
71
|
+
result = Soaspec::TestServer::PuppyService.data[id.to_i]
|
72
|
+
JSON.generate result
|
73
|
+
end
|
74
|
+
|
75
|
+
get '/test/multiple_json' do
|
76
|
+
<<-BOOKS
|
77
|
+
{"store":
|
78
|
+
{"bicycle":
|
79
|
+
{"price":19.95, "color":"red"},
|
80
|
+
"book":[
|
81
|
+
{"price":8.95, "category":"reference", "title":"Sayings of the Century", "author":"Nigel Rees"},
|
82
|
+
{"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"},
|
83
|
+
{"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville","color":"blue"},
|
84
|
+
{"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"Tolkien"}
|
85
|
+
]
|
86
|
+
}
|
87
|
+
}
|
88
|
+
BOOKS
|
89
|
+
end
|
90
|
+
|
91
|
+
patch '/test/puppy/:id' do |id|
|
92
|
+
request_hash = JSON.parse(request.body.string)
|
93
|
+
Soaspec::TestServer::PuppyService.data[id.to_i][:Name] = request_hash['Name']
|
94
|
+
response_hash = { result: { Status: 'updated', With: request_hash['Name'] } }
|
95
|
+
JSON.generate response_hash
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
93
99
|
SoaspecVirtualServer.run!
|
data/exe/xml_to_yaml_file
CHANGED
@@ -1,61 +1,61 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'xmlsimple'
|
4
|
-
require 'yaml'
|
5
|
-
require 'fileutils'
|
6
|
-
|
7
|
-
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
8
|
-
|
9
|
-
require 'soaspec'
|
10
|
-
|
11
|
-
include Soaspec::ExeHelpers
|
12
|
-
|
13
|
-
default_output_file = 'output.yml'
|
14
|
-
|
15
|
-
# Create file if not present. If present but different give warning
|
16
|
-
def create_file(options)
|
17
|
-
filename = options[:filename]
|
18
|
-
raise 'Need to pass filename' unless filename
|
19
|
-
content = options[:content]
|
20
|
-
raise 'Need to pass contents to insert into file' unless content
|
21
|
-
if File.exist? filename
|
22
|
-
old_content = File.read(filename)
|
23
|
-
if old_content != content
|
24
|
-
warn "!! #{filename} already exists and differs from template"
|
25
|
-
end
|
26
|
-
else
|
27
|
-
File.open(filename, 'w') do |f|
|
28
|
-
f.puts content
|
29
|
-
end
|
30
|
-
puts 'Created: ' + filename
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# For all keys in a Hash, convert Camelcase to underscore separated
|
35
|
-
def convert_hash_keys(value)
|
36
|
-
case value
|
37
|
-
when Array
|
38
|
-
value.map { |v| convert_hash_keys(v) }
|
39
|
-
when Hash
|
40
|
-
Hash[value.map { |k, v| [k.snakecase, convert_hash_keys(v)] }]
|
41
|
-
else
|
42
|
-
value
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# Remove arrays created as another string
|
47
|
-
def clean_up_yaml(yaml_string)
|
48
|
-
yaml_string = yaml_string.gsub(/\R+(\s*)-/, '').gsub(/{}/, "''") # Remove arrays, {} -> ''
|
49
|
-
# Insert new line where there are 2 ':' on 1 line. Issue from first gsub
|
50
|
-
yaml_string.gsub(/:(\s)(\w*):/){|s| s.insert(1, "\n")}
|
51
|
-
end
|
52
|
-
|
53
|
-
if ARGV[0]
|
54
|
-
warn "Using '#{default_output_file}' as default output file since no 2nd argument passed" unless ARGV[1]
|
55
|
-
hash = XmlSimple.xml_in(ARGV[0])
|
56
|
-
converted = convert_hash_keys hash
|
57
|
-
yaml_file = clean_up_yaml(converted.to_yaml)
|
58
|
-
create_file(filename: ARGV[1] || default_output_file, content: yaml_file)
|
59
|
-
else
|
60
|
-
puts 'usage: xml_to_yaml_file [input.xml] [output.yml] '
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'xmlsimple'
|
4
|
+
require 'yaml'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
8
|
+
|
9
|
+
require 'soaspec'
|
10
|
+
|
11
|
+
include Soaspec::ExeHelpers
|
12
|
+
|
13
|
+
default_output_file = 'output.yml'
|
14
|
+
|
15
|
+
# Create file if not present. If present but different give warning
|
16
|
+
def create_file(options)
|
17
|
+
filename = options[:filename]
|
18
|
+
raise 'Need to pass filename' unless filename
|
19
|
+
content = options[:content]
|
20
|
+
raise 'Need to pass contents to insert into file' unless content
|
21
|
+
if File.exist? filename
|
22
|
+
old_content = File.read(filename)
|
23
|
+
if old_content != content
|
24
|
+
warn "!! #{filename} already exists and differs from template"
|
25
|
+
end
|
26
|
+
else
|
27
|
+
File.open(filename, 'w') do |f|
|
28
|
+
f.puts content
|
29
|
+
end
|
30
|
+
puts 'Created: ' + filename
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# For all keys in a Hash, convert Camelcase to underscore separated
|
35
|
+
def convert_hash_keys(value)
|
36
|
+
case value
|
37
|
+
when Array
|
38
|
+
value.map { |v| convert_hash_keys(v) }
|
39
|
+
when Hash
|
40
|
+
Hash[value.map { |k, v| [k.snakecase, convert_hash_keys(v)] }]
|
41
|
+
else
|
42
|
+
value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Remove arrays created as another string
|
47
|
+
def clean_up_yaml(yaml_string)
|
48
|
+
yaml_string = yaml_string.gsub(/\R+(\s*)-/, '').gsub(/{}/, "''") # Remove arrays, {} -> ''
|
49
|
+
# Insert new line where there are 2 ':' on 1 line. Issue from first gsub
|
50
|
+
yaml_string.gsub(/:(\s)(\w*):/){|s| s.insert(1, "\n")}
|
51
|
+
end
|
52
|
+
|
53
|
+
if ARGV[0]
|
54
|
+
warn "Using '#{default_output_file}' as default output file since no 2nd argument passed" unless ARGV[1]
|
55
|
+
hash = XmlSimple.xml_in(ARGV[0])
|
56
|
+
converted = convert_hash_keys hash
|
57
|
+
yaml_file = clean_up_yaml(converted.to_yaml)
|
58
|
+
create_file(filename: ARGV[1] || default_output_file, content: yaml_file)
|
59
|
+
else
|
60
|
+
puts 'usage: xml_to_yaml_file [input.xml] [output.yml] '
|
61
61
|
end
|
data/lib/soaspec.rb
CHANGED
@@ -1,85 +1,86 @@
|
|
1
|
-
require 'rest-client' # REST
|
2
|
-
require 'erb' # Embedded ruby
|
3
|
-
require 'yaml' # Reading yaml
|
4
|
-
require 'rspec' # Testing framework
|
5
|
-
require 'rspec/its'
|
6
|
-
require 'savon' # SOAP
|
7
|
-
require 'nokogiri' # XPath
|
8
|
-
require 'date'
|
9
|
-
require 'jsonpath'
|
10
|
-
|
11
|
-
require 'soaspec/version'
|
12
|
-
require 'soaspec/exchange_handlers/soap_handler'
|
13
|
-
require 'soaspec/exchange_handlers/exchange_handler'
|
14
|
-
require 'soaspec/exchange_handlers/rest_methods'
|
15
|
-
require 'soaspec/exchange'
|
16
|
-
require 'soaspec/matchers'
|
17
|
-
require 'soaspec/soaspec_shared_examples'
|
18
|
-
require 'soaspec/core_ext/hash'
|
19
|
-
require 'soaspec/spec_logger'
|
20
|
-
require 'soaspec/exe_helpers'
|
21
|
-
require 'soaspec/exchange_handlers/rest_handler'
|
22
|
-
require 'soaspec/exchange_handlers/handler_accessors'
|
23
|
-
require 'soaspec/interpreter'
|
24
|
-
require 'soaspec/not_found_errors'
|
25
|
-
require 'soaspec/test_server/get_bank'
|
26
|
-
require 'soaspec/test_server/test_attribute'
|
27
|
-
require 'soaspec/test_server/puppy_service'
|
28
|
-
require 'soaspec/test_server/invoices'
|
29
|
-
require 'soaspec/
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
#
|
38
|
-
#
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
#
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
#
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
|
1
|
+
require 'rest-client' # REST
|
2
|
+
require 'erb' # Embedded ruby
|
3
|
+
require 'yaml' # Reading yaml
|
4
|
+
require 'rspec' # Testing framework
|
5
|
+
require 'rspec/its'
|
6
|
+
require 'savon' # SOAP
|
7
|
+
require 'nokogiri' # XPath
|
8
|
+
require 'date'
|
9
|
+
require 'jsonpath'
|
10
|
+
|
11
|
+
require 'soaspec/version'
|
12
|
+
require 'soaspec/exchange_handlers/soap_handler'
|
13
|
+
require 'soaspec/exchange_handlers/exchange_handler'
|
14
|
+
require 'soaspec/exchange_handlers/rest_methods'
|
15
|
+
require 'soaspec/exchange'
|
16
|
+
require 'soaspec/matchers'
|
17
|
+
require 'soaspec/soaspec_shared_examples'
|
18
|
+
require 'soaspec/core_ext/hash'
|
19
|
+
require 'soaspec/spec_logger'
|
20
|
+
require 'soaspec/exe_helpers'
|
21
|
+
require 'soaspec/exchange_handlers/rest_handler'
|
22
|
+
require 'soaspec/exchange_handlers/handler_accessors'
|
23
|
+
require 'soaspec/interpreter'
|
24
|
+
require 'soaspec/not_found_errors'
|
25
|
+
require 'soaspec/test_server/get_bank'
|
26
|
+
require 'soaspec/test_server/test_attribute'
|
27
|
+
require 'soaspec/test_server/puppy_service'
|
28
|
+
require 'soaspec/test_server/invoices'
|
29
|
+
require 'soaspec/test_server/test_namespace'
|
30
|
+
require 'soaspec/wsdl_generator'
|
31
|
+
|
32
|
+
# Gem for handling SOAP and REST api tests
|
33
|
+
module Soaspec
|
34
|
+
|
35
|
+
class << self
|
36
|
+
|
37
|
+
# Folder used to store credentials
|
38
|
+
# Used in auth2_file command
|
39
|
+
# @param [String] folder
|
40
|
+
def credentials_folder=(folder)
|
41
|
+
@credentials_folder = folder
|
42
|
+
end
|
43
|
+
|
44
|
+
# Credentials folder used to store secret data (not in source control) E.g passwords
|
45
|
+
def credentials_folder
|
46
|
+
@credentials_folder
|
47
|
+
end
|
48
|
+
|
49
|
+
# Used so that exchange class knows what context it's in
|
50
|
+
# @param [ExchangeHandler] handler A class inheriting from Soaspec::ExchangeHandler. Exchange class uses this
|
51
|
+
def api_handler=(handler)
|
52
|
+
@api_handler = handler
|
53
|
+
end
|
54
|
+
|
55
|
+
# Exchange Handler class currently being used
|
56
|
+
def api_handler
|
57
|
+
@api_handler
|
58
|
+
end
|
59
|
+
|
60
|
+
# Set whether to transform strings to keys in request automatically
|
61
|
+
# @param [Boolean] use_keys
|
62
|
+
def always_use_keys=(use_keys)
|
63
|
+
@always_use_keys = use_keys
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [Boolean] Whether to transform strings to keys in request automatically
|
67
|
+
def always_use_keys?
|
68
|
+
@always_use_keys || true
|
69
|
+
end
|
70
|
+
|
71
|
+
# Whether to remove namespaces from response in Xpath assertion automatically
|
72
|
+
# For why this may not be a good thing in general see
|
73
|
+
# http://tenderlovemaking.com/2009/04/23/namespaces-in-xml.html
|
74
|
+
# This will be overridden if xpath has a ':' in it
|
75
|
+
def strip_namespaces=(remove_namespaces)
|
76
|
+
@strip_namespaces = remove_namespaces
|
77
|
+
end
|
78
|
+
|
79
|
+
# Whether to remove namespaces in xpath assertion automatically
|
80
|
+
def strip_namespaces?
|
81
|
+
@strip_namespaces || false
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
RestClient.log = Soaspec::SpecLogger.create
|