soaspec 0.1.6 → 0.1.7
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 +48 -48
- data/.rspec +3 -3
- data/.rubocop.yml +2 -2
- data/CODE_OF_CONDUCT.md +74 -74
- data/ChangeLog +408 -404
- data/Gemfile +6 -6
- data/LICENSE.txt +21 -21
- data/README.md +113 -113
- data/Rakefile +24 -24
- data/Todo.md +6 -6
- data/exe/soaspec +109 -109
- data/exe/soaspec-virtual-server +156 -156
- data/exe/xml_to_yaml_file +60 -60
- data/lib/soaspec.rb +107 -103
- data/lib/soaspec/core_ext/hash.rb +83 -83
- data/lib/soaspec/exchange.rb +235 -235
- data/lib/soaspec/exchange_handlers/exchange_handler.rb +103 -103
- data/lib/soaspec/exchange_handlers/handler_accessors.rb +106 -106
- data/lib/soaspec/exchange_handlers/rest_accessors.rb +54 -92
- data/lib/soaspec/exchange_handlers/rest_handler.rb +318 -314
- data/lib/soaspec/exchange_handlers/rest_methods.rb +44 -44
- data/lib/soaspec/exchange_handlers/soap_handler.rb +236 -236
- data/lib/soaspec/exe_helpers.rb +60 -60
- 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 +26 -26
- 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 +12 -12
- data/lib/soaspec/generator/spec/soap_spec.rb.erb +51 -51
- 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 +40 -40
- data/lib/soaspec/matchers.rb +65 -65
- data/lib/soaspec/not_found_errors.rb +13 -13
- data/lib/soaspec/o_auth2.rb +65 -0
- data/lib/soaspec/soaspec_shared_examples.rb +24 -24
- data/lib/soaspec/spec_logger.rb +34 -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/id_manager.rb +31 -31
- data/lib/soaspec/test_server/invoices.rb +27 -27
- data/lib/soaspec/test_server/namespace.xml +14 -14
- 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 +12 -12
- data/lib/soaspec/version.rb +2 -2
- data/lib/soaspec/wsdl_generator.rb +144 -144
- data/soaspec.gemspec +46 -46
- data/test.wsdl +116 -116
- data/test.xml +10 -10
- data/test_wsdl.rb +43 -43
- metadata +4 -3
data/exe/soaspec-virtual-server
CHANGED
@@ -1,156 +1,156 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
4
|
-
require 'soaspec'
|
5
|
-
require 'sinatra'
|
6
|
-
require 'sinatra/basic_auth'
|
7
|
-
require 'docdsl'
|
8
|
-
require 'nokogiri'
|
9
|
-
require 'erb'
|
10
|
-
require 'json'
|
11
|
-
require 'faker'
|
12
|
-
|
13
|
-
# Used to run virtual web service on localhost. This makes tests more reliable and faster
|
14
|
-
# First argument overrides the default port
|
15
|
-
class SoaspecVirtualServer < Sinatra::Application
|
16
|
-
set :bind, '0.0.0.0'
|
17
|
-
set :port, (ARGV[0] || 4999).to_i
|
18
|
-
|
19
|
-
register Sinatra::DocDsl
|
20
|
-
|
21
|
-
page do
|
22
|
-
title 'Soaspec Virtual Services'
|
23
|
-
header 'Perform efficient API testing with Ruby'
|
24
|
-
introduction 'This has some simple virtual services aimed at helping you with testing your Ruby API code.'
|
25
|
-
end
|
26
|
-
|
27
|
-
documentation 'Nothing under /. Go look at /docs' do
|
28
|
-
response 'redirects to the documentation page'
|
29
|
-
status 303
|
30
|
-
end
|
31
|
-
get '/' do
|
32
|
-
redirect '/docs'
|
33
|
-
end
|
34
|
-
|
35
|
-
doc_endpoint '/docs'
|
36
|
-
|
37
|
-
documentation 'Used to test attributes' do
|
38
|
-
response 'A simple Note XML with a date attribute'
|
39
|
-
end
|
40
|
-
get '/test_attribute' do
|
41
|
-
Soaspec::TestServer::TestAttribute.note
|
42
|
-
end
|
43
|
-
|
44
|
-
documentation 'Used to test namespaces' do
|
45
|
-
response 'XML with 2 namespaces and same elements inside it'
|
46
|
-
end
|
47
|
-
get '/namespace' do
|
48
|
-
Soaspec::TestServer::TestNamespace.food
|
49
|
-
end
|
50
|
-
|
51
|
-
documentation 'Used for showing a simple difference in value depending on the id used' do
|
52
|
-
param :num, 'Number of tester'
|
53
|
-
param :id, 'Test parameter'
|
54
|
-
response 'JSON with success or true or false and the id sent
|
55
|
-
Idea is for tester to find the id that causes a failure (the fake "defect")
|
56
|
-
'
|
57
|
-
end
|
58
|
-
get '/packages/:num/:id' do |num, id|
|
59
|
-
JSON.generate(success: Soaspec::TestServer::IdManager.result_for(num, id), id: id)
|
60
|
-
end
|
61
|
-
|
62
|
-
post '/packages/developed' do
|
63
|
-
Soaspec::TestServer::IdManager.developed = request.body.include?('true')
|
64
|
-
Soaspec::TestServer::IdManager.developed.to_s
|
65
|
-
end
|
66
|
-
|
67
|
-
# Used for simple testing of posing
|
68
|
-
documentation 'Simply sends the response body back'
|
69
|
-
post '/echoer' do
|
70
|
-
request.body
|
71
|
-
end
|
72
|
-
|
73
|
-
documentation "Simulate retrieving an ouath token Passed to '/invoices'"
|
74
|
-
post '/as/token.oauth2' do
|
75
|
-
Soaspec::TestServer::Invoices.user_used = request.env['rack.request.form_hash']['username']
|
76
|
-
[200, Soaspec::TestServer::Invoices.oauth_headers, JSON.generate(Soaspec::TestServer::Invoices.oauth_body)]
|
77
|
-
end
|
78
|
-
|
79
|
-
documentation 'Replies with HTTP authorization and user set in /as/token.oauth2'
|
80
|
-
get '/invoice/:id' do |id|
|
81
|
-
JSON.generate(customer_id: id, oauth: request.env['HTTP_AUTHORIZATION'], user: Soaspec::TestServer::Invoices.user_used)
|
82
|
-
end
|
83
|
-
|
84
|
-
documentation 'This is returned when a query for the WSDL is made' do
|
85
|
-
response 'WSDL containing SCHEMA information'
|
86
|
-
end
|
87
|
-
get '/BLZService' do
|
88
|
-
[200, { 'Content-Type' => 'text/xml' }, Soaspec::TestServer::GetBank.test_wsdl]
|
89
|
-
end
|
90
|
-
|
91
|
-
authorize do |username, password|
|
92
|
-
username == 'admin' && password == 'secret'
|
93
|
-
end
|
94
|
-
|
95
|
-
protect do
|
96
|
-
documentation "Get path used to test basic auth. User is 'admin' & password is 'secret'" do
|
97
|
-
response 'Secret text'
|
98
|
-
end
|
99
|
-
get '/basic_secrets' do
|
100
|
-
'Secret data'
|
101
|
-
end
|
102
|
-
|
103
|
-
documentation 'This is the basic service being hit by SOAP actions'
|
104
|
-
post '/BLZService' do
|
105
|
-
Soaspec::TestServer::GetBank.response_for request
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
documentation 'Used for testing storage of data' do
|
110
|
-
payload 'Puppy JSON',
|
111
|
-
Name: 'Test', Failure_Type__c: 'Fail'
|
112
|
-
end
|
113
|
-
post '/test/puppy' do
|
114
|
-
request_hash = JSON.parse(request.body.string)
|
115
|
-
id = Soaspec::TestServer::PuppyService.new_id
|
116
|
-
Soaspec::TestServer::PuppyService.data[id][:Name] = request_hash['Name']
|
117
|
-
Soaspec::TestServer::PuppyService.data[id][:Failure_Type__c] = request_hash['Failure_Type__c'] if request_hash['Failure_Type__c']
|
118
|
-
response_hash = { result: { Status: 'success', Data: Soaspec::TestServer::PuppyService.data[id] } }
|
119
|
-
JSON.generate response_hash
|
120
|
-
end
|
121
|
-
|
122
|
-
documentation 'Used for testing retrieving storage of data'
|
123
|
-
get '/test/puppy/:id' do |id|
|
124
|
-
result = Soaspec::TestServer::PuppyService.data[id.to_i]
|
125
|
-
JSON.generate result
|
126
|
-
end
|
127
|
-
|
128
|
-
documentation 'Used for testing updating data'
|
129
|
-
patch '/test/puppy/:id' do |id|
|
130
|
-
request_hash = JSON.parse(request.body.string)
|
131
|
-
Soaspec::TestServer::PuppyService.data[id.to_i][:Name] = request_hash['Name']
|
132
|
-
response_hash = { result: { Status: 'updated', With: request_hash['Name'] } }
|
133
|
-
JSON.generate response_hash
|
134
|
-
end
|
135
|
-
|
136
|
-
documentation 'Used for testing the handling of JSON path' do
|
137
|
-
response 'JSON with multiple elements of the same name at different nested levels'
|
138
|
-
end
|
139
|
-
get '/test/multiple_json' do
|
140
|
-
<<-BOOKS
|
141
|
-
{"store":
|
142
|
-
{"bicycle":
|
143
|
-
{"price":19.95, "color":"red"},
|
144
|
-
"book":[
|
145
|
-
{"price":8.95, "category":"reference", "title":"Sayings of the Century", "author":"Nigel Rees"},
|
146
|
-
{"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"},
|
147
|
-
{"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville","color":"blue"},
|
148
|
-
{"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"Tolkien"}
|
149
|
-
]
|
150
|
-
}
|
151
|
-
}
|
152
|
-
BOOKS
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
SoaspecVirtualServer.run!
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
4
|
+
require 'soaspec'
|
5
|
+
require 'sinatra'
|
6
|
+
require 'sinatra/basic_auth'
|
7
|
+
require 'docdsl'
|
8
|
+
require 'nokogiri'
|
9
|
+
require 'erb'
|
10
|
+
require 'json'
|
11
|
+
require 'faker'
|
12
|
+
|
13
|
+
# Used to run virtual web service on localhost. This makes tests more reliable and faster
|
14
|
+
# First argument overrides the default port
|
15
|
+
class SoaspecVirtualServer < Sinatra::Application
|
16
|
+
set :bind, '0.0.0.0'
|
17
|
+
set :port, (ARGV[0] || 4999).to_i
|
18
|
+
|
19
|
+
register Sinatra::DocDsl
|
20
|
+
|
21
|
+
page do
|
22
|
+
title 'Soaspec Virtual Services'
|
23
|
+
header 'Perform efficient API testing with Ruby'
|
24
|
+
introduction 'This has some simple virtual services aimed at helping you with testing your Ruby API code.'
|
25
|
+
end
|
26
|
+
|
27
|
+
documentation 'Nothing under /. Go look at /docs' do
|
28
|
+
response 'redirects to the documentation page'
|
29
|
+
status 303
|
30
|
+
end
|
31
|
+
get '/' do
|
32
|
+
redirect '/docs'
|
33
|
+
end
|
34
|
+
|
35
|
+
doc_endpoint '/docs'
|
36
|
+
|
37
|
+
documentation 'Used to test attributes' do
|
38
|
+
response 'A simple Note XML with a date attribute'
|
39
|
+
end
|
40
|
+
get '/test_attribute' do
|
41
|
+
Soaspec::TestServer::TestAttribute.note
|
42
|
+
end
|
43
|
+
|
44
|
+
documentation 'Used to test namespaces' do
|
45
|
+
response 'XML with 2 namespaces and same elements inside it'
|
46
|
+
end
|
47
|
+
get '/namespace' do
|
48
|
+
Soaspec::TestServer::TestNamespace.food
|
49
|
+
end
|
50
|
+
|
51
|
+
documentation 'Used for showing a simple difference in value depending on the id used' do
|
52
|
+
param :num, 'Number of tester'
|
53
|
+
param :id, 'Test parameter'
|
54
|
+
response 'JSON with success or true or false and the id sent
|
55
|
+
Idea is for tester to find the id that causes a failure (the fake "defect")
|
56
|
+
'
|
57
|
+
end
|
58
|
+
get '/packages/:num/:id' do |num, id|
|
59
|
+
JSON.generate(success: Soaspec::TestServer::IdManager.result_for(num, id), id: id)
|
60
|
+
end
|
61
|
+
|
62
|
+
post '/packages/developed' do
|
63
|
+
Soaspec::TestServer::IdManager.developed = request.body.include?('true')
|
64
|
+
Soaspec::TestServer::IdManager.developed.to_s
|
65
|
+
end
|
66
|
+
|
67
|
+
# Used for simple testing of posing
|
68
|
+
documentation 'Simply sends the response body back'
|
69
|
+
post '/echoer' do
|
70
|
+
request.body
|
71
|
+
end
|
72
|
+
|
73
|
+
documentation "Simulate retrieving an ouath token Passed to '/invoices'"
|
74
|
+
post '/as/token.oauth2' do
|
75
|
+
Soaspec::TestServer::Invoices.user_used = request.env['rack.request.form_hash']['username']
|
76
|
+
[200, Soaspec::TestServer::Invoices.oauth_headers, JSON.generate(Soaspec::TestServer::Invoices.oauth_body)]
|
77
|
+
end
|
78
|
+
|
79
|
+
documentation 'Replies with HTTP authorization and user set in /as/token.oauth2'
|
80
|
+
get '/invoice/:id' do |id|
|
81
|
+
JSON.generate(customer_id: id, oauth: request.env['HTTP_AUTHORIZATION'], user: Soaspec::TestServer::Invoices.user_used)
|
82
|
+
end
|
83
|
+
|
84
|
+
documentation 'This is returned when a query for the WSDL is made' do
|
85
|
+
response 'WSDL containing SCHEMA information'
|
86
|
+
end
|
87
|
+
get '/BLZService' do
|
88
|
+
[200, { 'Content-Type' => 'text/xml' }, Soaspec::TestServer::GetBank.test_wsdl]
|
89
|
+
end
|
90
|
+
|
91
|
+
authorize do |username, password|
|
92
|
+
username == 'admin' && password == 'secret'
|
93
|
+
end
|
94
|
+
|
95
|
+
protect do
|
96
|
+
documentation "Get path used to test basic auth. User is 'admin' & password is 'secret'" do
|
97
|
+
response 'Secret text'
|
98
|
+
end
|
99
|
+
get '/basic_secrets' do
|
100
|
+
'Secret data'
|
101
|
+
end
|
102
|
+
|
103
|
+
documentation 'This is the basic service being hit by SOAP actions'
|
104
|
+
post '/BLZService' do
|
105
|
+
Soaspec::TestServer::GetBank.response_for request
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
documentation 'Used for testing storage of data' do
|
110
|
+
payload 'Puppy JSON',
|
111
|
+
Name: 'Test', Failure_Type__c: 'Fail'
|
112
|
+
end
|
113
|
+
post '/test/puppy' do
|
114
|
+
request_hash = JSON.parse(request.body.string)
|
115
|
+
id = Soaspec::TestServer::PuppyService.new_id
|
116
|
+
Soaspec::TestServer::PuppyService.data[id][:Name] = request_hash['Name']
|
117
|
+
Soaspec::TestServer::PuppyService.data[id][:Failure_Type__c] = request_hash['Failure_Type__c'] if request_hash['Failure_Type__c']
|
118
|
+
response_hash = { result: { Status: 'success', Data: Soaspec::TestServer::PuppyService.data[id] } }
|
119
|
+
JSON.generate response_hash
|
120
|
+
end
|
121
|
+
|
122
|
+
documentation 'Used for testing retrieving storage of data'
|
123
|
+
get '/test/puppy/:id' do |id|
|
124
|
+
result = Soaspec::TestServer::PuppyService.data[id.to_i]
|
125
|
+
JSON.generate result
|
126
|
+
end
|
127
|
+
|
128
|
+
documentation 'Used for testing updating data'
|
129
|
+
patch '/test/puppy/:id' do |id|
|
130
|
+
request_hash = JSON.parse(request.body.string)
|
131
|
+
Soaspec::TestServer::PuppyService.data[id.to_i][:Name] = request_hash['Name']
|
132
|
+
response_hash = { result: { Status: 'updated', With: request_hash['Name'] } }
|
133
|
+
JSON.generate response_hash
|
134
|
+
end
|
135
|
+
|
136
|
+
documentation 'Used for testing the handling of JSON path' do
|
137
|
+
response 'JSON with multiple elements of the same name at different nested levels'
|
138
|
+
end
|
139
|
+
get '/test/multiple_json' do
|
140
|
+
<<-BOOKS
|
141
|
+
{"store":
|
142
|
+
{"bicycle":
|
143
|
+
{"price":19.95, "color":"red"},
|
144
|
+
"book":[
|
145
|
+
{"price":8.95, "category":"reference", "title":"Sayings of the Century", "author":"Nigel Rees"},
|
146
|
+
{"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"},
|
147
|
+
{"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville","color":"blue"},
|
148
|
+
{"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"Tolkien"}
|
149
|
+
]
|
150
|
+
}
|
151
|
+
}
|
152
|
+
BOOKS
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
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,103 +1,107 @@
|
|
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/
|
13
|
-
require 'soaspec/exchange_handlers/
|
14
|
-
require 'soaspec/exchange_handlers/
|
15
|
-
require 'soaspec/
|
16
|
-
require 'soaspec/
|
17
|
-
require 'soaspec/
|
18
|
-
require 'soaspec/
|
19
|
-
require 'soaspec/
|
20
|
-
require 'soaspec/
|
21
|
-
require 'soaspec/
|
22
|
-
require 'soaspec/exchange_handlers/
|
23
|
-
require 'soaspec/
|
24
|
-
require 'soaspec/
|
25
|
-
require 'soaspec/
|
26
|
-
require 'soaspec/test_server/
|
27
|
-
require 'soaspec/test_server/
|
28
|
-
require 'soaspec/test_server/
|
29
|
-
require 'soaspec/test_server/
|
30
|
-
require 'soaspec/test_server/
|
31
|
-
require 'soaspec/
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
#
|
42
|
-
|
43
|
-
#
|
44
|
-
attr_accessor :
|
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
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
#
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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/o_auth2'
|
13
|
+
require 'soaspec/exchange_handlers/soap_handler'
|
14
|
+
require 'soaspec/exchange_handlers/exchange_handler'
|
15
|
+
require 'soaspec/exchange_handlers/rest_methods'
|
16
|
+
require 'soaspec/exchange'
|
17
|
+
require 'soaspec/matchers'
|
18
|
+
require 'soaspec/soaspec_shared_examples'
|
19
|
+
require 'soaspec/core_ext/hash'
|
20
|
+
require 'soaspec/spec_logger'
|
21
|
+
require 'soaspec/exe_helpers'
|
22
|
+
require 'soaspec/exchange_handlers/rest_handler'
|
23
|
+
require 'soaspec/exchange_handlers/handler_accessors'
|
24
|
+
require 'soaspec/interpreter'
|
25
|
+
require 'soaspec/not_found_errors'
|
26
|
+
require 'soaspec/test_server/get_bank'
|
27
|
+
require 'soaspec/test_server/test_attribute'
|
28
|
+
require 'soaspec/test_server/puppy_service'
|
29
|
+
require 'soaspec/test_server/invoices'
|
30
|
+
require 'soaspec/test_server/test_namespace'
|
31
|
+
require 'soaspec/test_server/id_manager'
|
32
|
+
require 'soaspec/wsdl_generator'
|
33
|
+
|
34
|
+
# Gem for handling SOAP and REST api tests
|
35
|
+
module Soaspec
|
36
|
+
|
37
|
+
@template_folder = 'template'
|
38
|
+
@auto_oauth = true
|
39
|
+
|
40
|
+
class << self
|
41
|
+
# Specify whether to see params sent to and retrieved from oauth. This will put password in log file, only recommended for debugging
|
42
|
+
attr_writer :debug_oauth
|
43
|
+
# Folder used to store templates for API calls
|
44
|
+
attr_accessor :template_folder
|
45
|
+
# Stores last exchange
|
46
|
+
attr_accessor :last_exchange
|
47
|
+
# Automatically add Authorization header to RestHandler where oauth2 credentials are specified
|
48
|
+
attr_accessor :auto_oauth
|
49
|
+
|
50
|
+
# Folder used to store credentials
|
51
|
+
# Used in auth2_file command
|
52
|
+
# @param [String] folder
|
53
|
+
def credentials_folder=(folder)
|
54
|
+
@credentials_folder = folder
|
55
|
+
end
|
56
|
+
|
57
|
+
# Credentials folder used to store secret data (not in source control) E.g passwords
|
58
|
+
def credentials_folder
|
59
|
+
@credentials_folder
|
60
|
+
end
|
61
|
+
|
62
|
+
# Used so that exchange class knows what context it's in
|
63
|
+
# @param [ExchangeHandler] handler A class inheriting from Soaspec::ExchangeHandler. Exchange class uses this
|
64
|
+
def api_handler=(handler)
|
65
|
+
@api_handler = handler
|
66
|
+
end
|
67
|
+
|
68
|
+
# Exchange Handler class currently being used
|
69
|
+
def api_handler
|
70
|
+
@api_handler
|
71
|
+
end
|
72
|
+
|
73
|
+
# Set whether to transform strings to keys in request automatically
|
74
|
+
# @param [Boolean] use_keys
|
75
|
+
def always_use_keys=(use_keys)
|
76
|
+
@always_use_keys = use_keys
|
77
|
+
end
|
78
|
+
|
79
|
+
# @return [Boolean] Whether to transform strings to keys in request automatically
|
80
|
+
def always_use_keys?
|
81
|
+
@always_use_keys || true
|
82
|
+
end
|
83
|
+
|
84
|
+
# @return [Boolean] Whether to see params sent to & received from oauth URL
|
85
|
+
def debug_oauth?
|
86
|
+
@debug_oauth || false
|
87
|
+
end
|
88
|
+
|
89
|
+
# @return [String] Folder used to store templates for API calls
|
90
|
+
# def template_folder
|
91
|
+
# @template_folder || 'template'
|
92
|
+
# end
|
93
|
+
|
94
|
+
# Whether to log all API traffic
|
95
|
+
def log_api_traffic=(set)
|
96
|
+
@log_api_traffic = set
|
97
|
+
RestClient.log = nil unless set
|
98
|
+
end
|
99
|
+
|
100
|
+
# @return [Boolean] Whether to log all API traffic
|
101
|
+
def log_api_traffic?
|
102
|
+
@log_api_traffic.nil? ? true : @log_api_traffic
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
RestClient.log = Soaspec::SpecLogger.create
|