soaspec 0.2.23 → 0.2.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +15 -15
  3. data/.gitlab-ci.yml +33 -33
  4. data/.rspec +3 -3
  5. data/.rubocop.yml +2 -2
  6. data/CODE_OF_CONDUCT.md +74 -74
  7. data/ChangeLog +577 -573
  8. data/Gemfile +6 -6
  9. data/LICENSE.txt +21 -21
  10. data/README.md +230 -230
  11. data/Rakefile +42 -42
  12. data/Todo.md +15 -15
  13. data/exe/soaspec +123 -123
  14. data/exe/xml_to_yaml_file +42 -42
  15. data/lib/soaspec.rb +101 -101
  16. data/lib/soaspec/core_ext/hash.rb +35 -35
  17. data/lib/soaspec/cucumber/generic_steps.rb +85 -85
  18. data/lib/soaspec/demo.rb +4 -4
  19. data/lib/soaspec/exchange/exchange.rb +111 -111
  20. data/lib/soaspec/exchange/exchange_extractor.rb +83 -83
  21. data/lib/soaspec/exchange/exchange_properties.rb +26 -26
  22. data/lib/soaspec/exchange/exchange_repeater.rb +19 -19
  23. data/lib/soaspec/exchange/request_builder.rb +68 -68
  24. data/lib/soaspec/exchange/variable_storer.rb +22 -22
  25. data/lib/soaspec/exchange_handlers/exchange_handler.rb +126 -126
  26. data/lib/soaspec/exchange_handlers/handler_accessors.rb +130 -130
  27. data/lib/soaspec/exchange_handlers/response_extractor.rb +82 -82
  28. data/lib/soaspec/exchange_handlers/rest_exchanger_factory.rb +109 -109
  29. data/lib/soaspec/exchange_handlers/rest_handler.rb +259 -259
  30. data/lib/soaspec/exchange_handlers/rest_methods.rb +44 -44
  31. data/lib/soaspec/exchange_handlers/rest_parameters.rb +86 -86
  32. data/lib/soaspec/exchange_handlers/rest_parameters_defaults.rb +21 -21
  33. data/lib/soaspec/exchange_handlers/soap_handler.rb +235 -235
  34. data/lib/soaspec/exe_helpers.rb +92 -92
  35. data/lib/soaspec/generate_server.rb +37 -37
  36. data/lib/soaspec/generator/.rspec.erb +5 -5
  37. data/lib/soaspec/generator/.travis.yml.erb +5 -5
  38. data/lib/soaspec/generator/Gemfile.erb +8 -8
  39. data/lib/soaspec/generator/README.md.erb +29 -29
  40. data/lib/soaspec/generator/Rakefile.erb +19 -19
  41. data/lib/soaspec/generator/config/data/default.yml.erb +2 -2
  42. data/lib/soaspec/generator/css/bootstrap.css +6833 -6833
  43. data/lib/soaspec/generator/generate_exchange.html.erb +35 -35
  44. data/lib/soaspec/generator/lib/blz_service.rb.erb +26 -26
  45. data/lib/soaspec/generator/lib/dynamic_class_content.rb.erb +12 -12
  46. data/lib/soaspec/generator/lib/new_rest_service.rb.erb +51 -51
  47. data/lib/soaspec/generator/lib/new_soap_service.rb.erb +29 -29
  48. data/lib/soaspec/generator/lib/package_service.rb.erb +2 -2
  49. data/lib/soaspec/generator/lib/shared_example.rb.erb +8 -8
  50. data/lib/soaspec/generator/spec/dynamic_soap_spec.rb.erb +12 -12
  51. data/lib/soaspec/generator/spec/rest_spec.rb.erb +9 -9
  52. data/lib/soaspec/generator/spec/soap_spec.rb.erb +51 -51
  53. data/lib/soaspec/generator/spec/spec_helper.rb.erb +23 -23
  54. data/lib/soaspec/generator/template/soap_template.xml +6 -6
  55. data/lib/soaspec/indifferent_hash.rb +7 -7
  56. data/lib/soaspec/interpreter.rb +39 -39
  57. data/lib/soaspec/matchers.rb +114 -114
  58. data/lib/soaspec/not_found_errors.rb +13 -13
  59. data/lib/soaspec/o_auth2.rb +128 -128
  60. data/lib/soaspec/soaspec_shared_examples.rb +24 -24
  61. data/lib/soaspec/spec_logger.rb +121 -121
  62. data/lib/soaspec/template_reader.rb +28 -28
  63. data/lib/soaspec/test_server/bank.wsdl +90 -90
  64. data/lib/soaspec/test_server/get_bank.rb +164 -164
  65. data/lib/soaspec/test_server/id_manager.rb +39 -39
  66. data/lib/soaspec/test_server/invoices.rb +27 -27
  67. data/lib/soaspec/test_server/namespace.xml +14 -14
  68. data/lib/soaspec/test_server/note.xml +5 -5
  69. data/lib/soaspec/test_server/puppy_service.rb +19 -19
  70. data/lib/soaspec/test_server/test_attribute.rb +12 -12
  71. data/lib/soaspec/test_server/test_namespace.rb +12 -12
  72. data/lib/soaspec/version.rb +4 -3
  73. data/lib/soaspec/virtual_server.rb +174 -174
  74. data/lib/soaspec/wait.rb +41 -41
  75. data/lib/soaspec/wsdl_generator.rb +215 -215
  76. data/soaspec.gemspec +53 -53
  77. data/test.wsdl +116 -116
  78. data/test.xml +10 -10
  79. data/test_wsdl.rb +41 -41
  80. metadata +3 -4
@@ -1,15 +1,15 @@
1
- <root>
2
- <h:table xmlns:h="http://www.w3.org/TR/html4/">
3
- <h:tr>
4
- <h:td>Apples</h:td>
5
- <h:td>Bananas</h:td>
6
- </h:tr>
7
- </h:table>
8
-
9
- <f:table xmlns:f="https://www.w3schools.com/furniture">
10
- <f:td>Wood</f:td>
11
- <f:name>African Coffee Table</f:name>
12
- <f:width>80</f:width>
13
- <f:length>120</f:length>
14
- </f:table>
1
+ <root>
2
+ <h:table xmlns:h="http://www.w3.org/TR/html4/">
3
+ <h:tr>
4
+ <h:td>Apples</h:td>
5
+ <h:td>Bananas</h:td>
6
+ </h:tr>
7
+ </h:table>
8
+
9
+ <f:table xmlns:f="https://www.w3schools.com/furniture">
10
+ <f:td>Wood</f:td>
11
+ <f:name>African Coffee Table</f:name>
12
+ <f:width>80</f:width>
13
+ <f:length>120</f:length>
14
+ </f:table>
15
15
  </root>
@@ -1,6 +1,6 @@
1
- <note date="2008-01-10">
2
- <to>Tove</to>
3
- <from>Jani</from>
4
- <comment_line>First comment</comment_line>
5
- <comment_line>Second comment</comment_line>
1
+ <note date="2008-01-10">
2
+ <to>Tove</to>
3
+ <from>Jani</from>
4
+ <comment_line>First comment</comment_line>
5
+ <comment_line>Second comment</comment_line>
6
6
  </note>
@@ -1,19 +1,19 @@
1
- module Soaspec
2
- module TestServer
3
- # Simulates ordering a new puppy. Used for testing REST storing, retrieving and updating data
4
- class PuppyService
5
- @data = {}
6
- @current_id = 1
7
- class << self
8
- attr_accessor :data
9
-
10
- def new_id
11
- @data[@current_id] = {}
12
- @data[@current_id][:Id] = @current_id
13
- @current_id += 1
14
- @current_id - 1
15
- end
16
- end
17
- end
18
- end
19
- end
1
+ module Soaspec
2
+ module TestServer
3
+ # Simulates ordering a new puppy. Used for testing REST storing, retrieving and updating data
4
+ class PuppyService
5
+ @data = {}
6
+ @current_id = 1
7
+ class << self
8
+ attr_accessor :data
9
+
10
+ def new_id
11
+ @data[@current_id] = {}
12
+ @data[@current_id][:Id] = @current_id
13
+ @current_id += 1
14
+ @current_id - 1
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,12 +1,12 @@
1
- module Soaspec
2
- module TestServer
3
- # Helps tests attribute methods
4
- class TestAttribute
5
- class << self
6
- def note
7
- File.read(File.join(File.dirname(__FILE__), 'note.xml'))
8
- end
9
- end
10
- end
11
- end
12
- end
1
+ module Soaspec
2
+ module TestServer
3
+ # Helps tests attribute methods
4
+ class TestAttribute
5
+ class << self
6
+ def note
7
+ File.read(File.join(File.dirname(__FILE__), 'note.xml'))
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,12 +1,12 @@
1
- module Soaspec
2
- module TestServer
3
- # Helps tests attribute methods
4
- class TestNamespace
5
- class << self
6
- def food
7
- File.read(File.join(File.dirname(__FILE__), 'namespace.xml'))
8
- end
9
- end
10
- end
11
- end
12
- end
1
+ module Soaspec
2
+ module TestServer
3
+ # Helps tests attribute methods
4
+ class TestNamespace
5
+ class << self
6
+ def food
7
+ File.read(File.join(File.dirname(__FILE__), 'namespace.xml'))
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,4 @@
1
- module Soaspec
2
- VERSION = '0.2.23'.freeze
3
- end
1
+ module Soaspec
2
+ # @return [String] Version of the gem
3
+ VERSION = '0.2.24'.freeze
4
+ end
@@ -1,174 +1,174 @@
1
- require 'soaspec'
2
- require 'sinatra'
3
- require 'sinatra/basic_auth'
4
- require 'docdsl'
5
- require 'nokogiri'
6
- require 'erb'
7
- require 'json'
8
- require 'faker'
9
- require 'soaspec/test_server/get_bank'
10
- require 'soaspec/test_server/test_attribute'
11
- require 'soaspec/test_server/puppy_service'
12
- require 'soaspec/test_server/invoices'
13
- require 'soaspec/test_server/test_namespace'
14
- require 'soaspec/test_server/id_manager'
15
-
16
- module Soaspec
17
- # Used to run virtual web service on localhost. This makes tests more reliable and faster
18
- # First argument overrides the default port
19
- class VirtualServer < Sinatra::Application
20
- set :bind, '0.0.0.0'
21
- set :port, (ENV['port'] || 4999).to_i
22
-
23
- register Sinatra::DocDsl
24
-
25
- page do
26
- title 'Soaspec Virtual Services'
27
- header 'Perform efficient API testing with Ruby'
28
- introduction 'This has some simple virtual services aimed at helping you with testing your Ruby API code.'
29
- end
30
-
31
- documentation 'Nothing under /. Go look at /docs' do
32
- response 'redirects to the documentation page'
33
- status 302
34
- end
35
- get '/' do
36
- redirect '/docs'
37
- end
38
-
39
- doc_endpoint '/docs'
40
-
41
- documentation 'Simulate server error' do
42
- status 500
43
- end
44
- get '/server_error' do
45
- [500, {}, 'Internal Server Error']
46
- end
47
-
48
- documentation 'Used to verify extract from text response' do
49
- response 'Plain text with a pattern to match in it'
50
- end
51
- get '/text_response' do
52
- 'This is some text. In here it says ID=12345 to indicate value to obtain'
53
- end
54
-
55
- documentation 'Used to test attributes' do
56
- response 'A simple Note XML with a date attribute'
57
- end
58
- get '/test_attribute' do
59
- Soaspec::TestServer::TestAttribute.note
60
- end
61
-
62
- documentation 'Used to test namespaces' do
63
- response 'XML with 2 namespaces and same elements inside it'
64
- end
65
- get '/namespace' do
66
- Soaspec::TestServer::TestNamespace.food
67
- end
68
-
69
- documentation 'Used for showing a simple difference in value depending on the id used' do
70
- param :num, 'Number of tester'
71
- param :id, 'Test parameter'
72
- response 'JSON with success or true or false and the id sent
73
- Idea is for tester to find the id that causes a failure (the fake "defect")
74
- '
75
- end
76
- get '/packages/:num/:id' do |num, id|
77
- JSON.generate(success: Soaspec::TestServer::IdManager.result_for(num, id), id: id)
78
- end
79
-
80
- documentation 'Sets status as developed'
81
- post '/packages/developed' do
82
- Soaspec::TestServer::IdManager.developed = request.body.include?('true')
83
- Soaspec::TestServer::IdManager.developed.to_s
84
- end
85
-
86
- # Used for simple testing of posing
87
- documentation 'Simply sends the response body back'
88
- post '/echoer' do
89
- request.body
90
- end
91
-
92
- documentation "Simulate retrieving an ouath token Passed to '/invoices'"
93
- post '/as/token.oauth2' do
94
- Soaspec::TestServer::Invoices.user_used = request.env['rack.request.form_hash']['username']
95
- [200, Soaspec::TestServer::Invoices.oauth_headers, JSON.generate(Soaspec::TestServer::Invoices.oauth_body)]
96
- end
97
-
98
- documentation 'Replies with HTTP authorization and user set in /as/token.oauth2'
99
- get '/invoice/:id' do |id|
100
- JSON.generate(customer_id: id, oauth: request.env['HTTP_AUTHORIZATION'], user: Soaspec::TestServer::Invoices.user_used)
101
- end
102
-
103
- documentation 'This is returned when a query for the WSDL is made' do
104
- response 'WSDL containing SCHEMA information'
105
- end
106
- get '/BLZService' do
107
- [200, { 'Content-Type' => 'text/xml' }, Soaspec::TestServer::GetBank.test_wsdl]
108
- end
109
-
110
- authorize do |username, password|
111
- username == 'admin' && password == 'secret'
112
- end
113
-
114
- protect do
115
- documentation "Get path used to test basic auth. User is 'admin' & password is 'secret'" do
116
- response 'Secret text'
117
- end
118
- get '/basic_secrets' do
119
- 'Secret data'
120
- end
121
-
122
- documentation 'This is the basic service being hit by SOAP actions'
123
- post '/BLZService' do
124
- Soaspec::TestServer::GetBank.response_for request
125
- end
126
- end
127
-
128
- documentation 'Used for testing storage of data' do
129
- payload 'Puppy JSON',
130
- Name: 'Test', Failure_Type__c: 'Fail'
131
- end
132
- post '/test/puppy' do
133
- request_hash = JSON.parse(request.body.string)
134
- id = Soaspec::TestServer::PuppyService.new_id
135
- Soaspec::TestServer::PuppyService.data[id][:Name] = request_hash['Name']
136
- Soaspec::TestServer::PuppyService.data[id][:Failure_Type__c] = request_hash['Failure_Type__c'] if request_hash['Failure_Type__c']
137
- response_hash = { result: { Status: 'success', Data: Soaspec::TestServer::PuppyService.data[id] } }
138
- JSON.generate response_hash
139
- end
140
-
141
- documentation 'Used for testing retrieving storage of data'
142
- get '/test/puppy/:id' do |id|
143
- result = Soaspec::TestServer::PuppyService.data[id.to_i]
144
- JSON.generate result
145
- end
146
-
147
- documentation 'Used for testing updating data'
148
- patch '/test/puppy/:id' do |id|
149
- request_hash = JSON.parse(request.body.string)
150
- Soaspec::TestServer::PuppyService.data[id.to_i][:Name] = request_hash['Name']
151
- response_hash = { result: { Status: 'updated', With: request_hash['Name'] } }
152
- JSON.generate response_hash
153
- end
154
-
155
- documentation 'Used for testing the handling of JSON path' do
156
- response 'JSON with multiple elements of the same name at different nested levels'
157
- end
158
- get '/test/multiple_json' do
159
- <<-BOOKS
160
- {"store":
161
- {"bicycle":
162
- {"price":19.95, "color":"red"},
163
- "book":[
164
- {"price":8.95, "category":"reference", "title":"Sayings of the Century", "author":"Nigel Rees"},
165
- {"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"},
166
- {"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville","color":"blue"},
167
- {"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"Tolkien"}
168
- ]
169
- }
170
- }
171
- BOOKS
172
- end
173
- end
174
- end
1
+ require 'soaspec'
2
+ require 'sinatra'
3
+ require 'sinatra/basic_auth'
4
+ require 'docdsl'
5
+ require 'nokogiri'
6
+ require 'erb'
7
+ require 'json'
8
+ require 'faker'
9
+ require 'soaspec/test_server/get_bank'
10
+ require 'soaspec/test_server/test_attribute'
11
+ require 'soaspec/test_server/puppy_service'
12
+ require 'soaspec/test_server/invoices'
13
+ require 'soaspec/test_server/test_namespace'
14
+ require 'soaspec/test_server/id_manager'
15
+
16
+ module Soaspec
17
+ # Used to run virtual web service on localhost. This makes tests more reliable and faster
18
+ # First argument overrides the default port
19
+ class VirtualServer < Sinatra::Application
20
+ set :bind, '0.0.0.0'
21
+ set :port, (ENV['port'] || 4999).to_i
22
+
23
+ register Sinatra::DocDsl
24
+
25
+ page do
26
+ title 'Soaspec Virtual Services'
27
+ header 'Perform efficient API testing with Ruby'
28
+ introduction 'This has some simple virtual services aimed at helping you with testing your Ruby API code.'
29
+ end
30
+
31
+ documentation 'Nothing under /. Go look at /docs' do
32
+ response 'redirects to the documentation page'
33
+ status 302
34
+ end
35
+ get '/' do
36
+ redirect '/docs'
37
+ end
38
+
39
+ doc_endpoint '/docs'
40
+
41
+ documentation 'Simulate server error' do
42
+ status 500
43
+ end
44
+ get '/server_error' do
45
+ [500, {}, 'Internal Server Error']
46
+ end
47
+
48
+ documentation 'Used to verify extract from text response' do
49
+ response 'Plain text with a pattern to match in it'
50
+ end
51
+ get '/text_response' do
52
+ 'This is some text. In here it says ID=12345 to indicate value to obtain'
53
+ end
54
+
55
+ documentation 'Used to test attributes' do
56
+ response 'A simple Note XML with a date attribute'
57
+ end
58
+ get '/test_attribute' do
59
+ Soaspec::TestServer::TestAttribute.note
60
+ end
61
+
62
+ documentation 'Used to test namespaces' do
63
+ response 'XML with 2 namespaces and same elements inside it'
64
+ end
65
+ get '/namespace' do
66
+ Soaspec::TestServer::TestNamespace.food
67
+ end
68
+
69
+ documentation 'Used for showing a simple difference in value depending on the id used' do
70
+ param :num, 'Number of tester'
71
+ param :id, 'Test parameter'
72
+ response 'JSON with success or true or false and the id sent
73
+ Idea is for tester to find the id that causes a failure (the fake "defect")
74
+ '
75
+ end
76
+ get '/packages/:num/:id' do |num, id|
77
+ JSON.generate(success: Soaspec::TestServer::IdManager.result_for(num, id), id: id)
78
+ end
79
+
80
+ documentation 'Sets status as developed'
81
+ post '/packages/developed' do
82
+ Soaspec::TestServer::IdManager.developed = request.body.include?('true')
83
+ Soaspec::TestServer::IdManager.developed.to_s
84
+ end
85
+
86
+ # Used for simple testing of posing
87
+ documentation 'Simply sends the response body back'
88
+ post '/echoer' do
89
+ request.body
90
+ end
91
+
92
+ documentation "Simulate retrieving an ouath token Passed to '/invoices'"
93
+ post '/as/token.oauth2' do
94
+ Soaspec::TestServer::Invoices.user_used = request.env['rack.request.form_hash']['username']
95
+ [200, Soaspec::TestServer::Invoices.oauth_headers, JSON.generate(Soaspec::TestServer::Invoices.oauth_body)]
96
+ end
97
+
98
+ documentation 'Replies with HTTP authorization and user set in /as/token.oauth2'
99
+ get '/invoice/:id' do |id|
100
+ JSON.generate(customer_id: id, oauth: request.env['HTTP_AUTHORIZATION'], user: Soaspec::TestServer::Invoices.user_used)
101
+ end
102
+
103
+ documentation 'This is returned when a query for the WSDL is made' do
104
+ response 'WSDL containing SCHEMA information'
105
+ end
106
+ get '/BLZService' do
107
+ [200, { 'Content-Type' => 'text/xml' }, Soaspec::TestServer::GetBank.test_wsdl]
108
+ end
109
+
110
+ authorize do |username, password|
111
+ username == 'admin' && password == 'secret'
112
+ end
113
+
114
+ protect do
115
+ documentation "Get path used to test basic auth. User is 'admin' & password is 'secret'" do
116
+ response 'Secret text'
117
+ end
118
+ get '/basic_secrets' do
119
+ 'Secret data'
120
+ end
121
+
122
+ documentation 'This is the basic service being hit by SOAP actions'
123
+ post '/BLZService' do
124
+ Soaspec::TestServer::GetBank.response_for request
125
+ end
126
+ end
127
+
128
+ documentation 'Used for testing storage of data' do
129
+ payload 'Puppy JSON',
130
+ Name: 'Test', Failure_Type__c: 'Fail'
131
+ end
132
+ post '/test/puppy' do
133
+ request_hash = JSON.parse(request.body.string)
134
+ id = Soaspec::TestServer::PuppyService.new_id
135
+ Soaspec::TestServer::PuppyService.data[id][:Name] = request_hash['Name']
136
+ Soaspec::TestServer::PuppyService.data[id][:Failure_Type__c] = request_hash['Failure_Type__c'] if request_hash['Failure_Type__c']
137
+ response_hash = { result: { Status: 'success', Data: Soaspec::TestServer::PuppyService.data[id] } }
138
+ JSON.generate response_hash
139
+ end
140
+
141
+ documentation 'Used for testing retrieving storage of data'
142
+ get '/test/puppy/:id' do |id|
143
+ result = Soaspec::TestServer::PuppyService.data[id.to_i]
144
+ JSON.generate result
145
+ end
146
+
147
+ documentation 'Used for testing updating data'
148
+ patch '/test/puppy/:id' do |id|
149
+ request_hash = JSON.parse(request.body.string)
150
+ Soaspec::TestServer::PuppyService.data[id.to_i][:Name] = request_hash['Name']
151
+ response_hash = { result: { Status: 'updated', With: request_hash['Name'] } }
152
+ JSON.generate response_hash
153
+ end
154
+
155
+ documentation 'Used for testing the handling of JSON path' do
156
+ response 'JSON with multiple elements of the same name at different nested levels'
157
+ end
158
+ get '/test/multiple_json' do
159
+ <<-BOOKS
160
+ {"store":
161
+ {"bicycle":
162
+ {"price":19.95, "color":"red"},
163
+ "book":[
164
+ {"price":8.95, "category":"reference", "title":"Sayings of the Century", "author":"Nigel Rees"},
165
+ {"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"},
166
+ {"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville","color":"blue"},
167
+ {"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"Tolkien"}
168
+ ]
169
+ }
170
+ }
171
+ BOOKS
172
+ end
173
+ end
174
+ end