soaspec 0.2.33 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +15 -15
  3. data/.gitlab-ci.yml +62 -62
  4. data/.rspec +3 -3
  5. data/.rubocop.yml +2 -2
  6. data/CODE_OF_CONDUCT.md +74 -74
  7. data/ChangeLog +643 -632
  8. data/Dockerfile +7 -7
  9. data/Gemfile +8 -8
  10. data/LICENSE.txt +21 -21
  11. data/README.md +253 -231
  12. data/Rakefile +52 -52
  13. data/Todo.md +16 -16
  14. data/exe/soaspec +140 -138
  15. data/exe/xml_to_yaml_file +43 -43
  16. data/lib/soaspec.rb +118 -106
  17. data/lib/soaspec/baseline.rb +82 -22
  18. data/lib/soaspec/core_ext/hash.rb +44 -44
  19. data/lib/soaspec/cucumber/generic_steps.rb +94 -94
  20. data/lib/soaspec/demo.rb +6 -6
  21. data/lib/soaspec/errors.rb +24 -24
  22. data/lib/soaspec/exchange/exchange.rb +131 -129
  23. data/lib/soaspec/exchange/exchange_extractor.rb +105 -90
  24. data/lib/soaspec/exchange/exchange_properties.rb +28 -28
  25. data/lib/soaspec/exchange/exchange_repeater.rb +21 -21
  26. data/lib/soaspec/exchange/request_builder.rb +108 -70
  27. data/lib/soaspec/exchange/variable_storer.rb +24 -24
  28. data/lib/soaspec/exchange_handlers/exchange_handler.rb +98 -98
  29. data/lib/soaspec/exchange_handlers/exchange_handler_defaults.rb +61 -61
  30. data/lib/soaspec/exchange_handlers/handler_accessors.rb +132 -132
  31. data/lib/soaspec/exchange_handlers/request/rest_request.rb +77 -59
  32. data/lib/soaspec/exchange_handlers/request/soap_request.rb +41 -41
  33. data/lib/soaspec/exchange_handlers/response_extractor.rb +84 -84
  34. data/lib/soaspec/exchange_handlers/rest_exchanger_factory.rb +111 -111
  35. data/lib/soaspec/exchange_handlers/rest_handler.rb +307 -307
  36. data/lib/soaspec/exchange_handlers/rest_methods.rb +65 -65
  37. data/lib/soaspec/exchange_handlers/rest_parameters.rb +112 -112
  38. data/lib/soaspec/exchange_handlers/rest_parameters_defaults.rb +42 -42
  39. data/lib/soaspec/exchange_handlers/soap_handler.rb +241 -241
  40. data/lib/soaspec/exe_helpers.rb +94 -94
  41. data/lib/soaspec/generate_server.rb +48 -48
  42. data/lib/soaspec/generator/.rspec.erb +5 -5
  43. data/lib/soaspec/generator/.travis.yml.erb +5 -5
  44. data/lib/soaspec/generator/Gemfile.erb +8 -8
  45. data/lib/soaspec/generator/README.md.erb +29 -29
  46. data/lib/soaspec/generator/Rakefile.erb +20 -19
  47. data/lib/soaspec/generator/config/data/default.yml.erb +2 -2
  48. data/lib/soaspec/generator/css/bootstrap.css +6833 -6833
  49. data/lib/soaspec/generator/features/support/env.rb.erb +3 -3
  50. data/lib/soaspec/generator/generate_exchange.html.erb +47 -47
  51. data/lib/soaspec/generator/lib/blz_service.rb.erb +26 -26
  52. data/lib/soaspec/generator/lib/dynamic_class_content.rb.erb +12 -12
  53. data/lib/soaspec/generator/lib/new_rest_service.rb.erb +56 -56
  54. data/lib/soaspec/generator/lib/new_soap_service.rb.erb +29 -29
  55. data/lib/soaspec/generator/lib/package_service.rb.erb +2 -2
  56. data/lib/soaspec/generator/lib/shared_example.rb.erb +8 -8
  57. data/lib/soaspec/generator/spec/dynamic_soap_spec.rb.erb +12 -12
  58. data/lib/soaspec/generator/spec/rest_spec.rb.erb +9 -9
  59. data/lib/soaspec/generator/spec/soap_spec.rb.erb +51 -51
  60. data/lib/soaspec/generator/spec/spec_helper.rb.erb +23 -23
  61. data/lib/soaspec/generator/template/soap_template.xml +6 -6
  62. data/lib/soaspec/indifferent_hash.rb +9 -9
  63. data/lib/soaspec/interpreter.rb +70 -70
  64. data/lib/soaspec/matchers.rb +136 -140
  65. data/lib/soaspec/o_auth2.rb +142 -142
  66. data/lib/soaspec/soaspec_shared_examples.rb +26 -26
  67. data/lib/soaspec/spec_logger.rb +143 -143
  68. data/lib/soaspec/template_reader.rb +30 -30
  69. data/lib/soaspec/test_server/bank.wsdl +90 -90
  70. data/lib/soaspec/test_server/get_bank.rb +166 -166
  71. data/lib/soaspec/test_server/id_manager.rb +41 -41
  72. data/lib/soaspec/test_server/invoices.rb +29 -29
  73. data/lib/soaspec/test_server/namespace.xml +14 -14
  74. data/lib/soaspec/test_server/note.xml +5 -5
  75. data/lib/soaspec/test_server/puppy_service.rb +21 -21
  76. data/lib/soaspec/test_server/test_attribute.rb +14 -14
  77. data/lib/soaspec/test_server/test_namespace.rb +14 -14
  78. data/lib/soaspec/version.rb +6 -6
  79. data/lib/soaspec/virtual_server.rb +193 -190
  80. data/lib/soaspec/wait.rb +43 -43
  81. data/lib/soaspec/wsdl_generator.rb +215 -215
  82. data/soaspec.gemspec +58 -58
  83. data/test.wsdl +116 -116
  84. data/test.xml +10 -10
  85. data/test_wsdl.rb +43 -43
  86. metadata +3 -3
@@ -1,41 +1,41 @@
1
- # frozen_string_literal: true
2
-
3
- module Soaspec
4
- module TestServer
5
- # Handles returning ids dependent on a number of factors
6
- # Made to demonstrate creating testing a list of ids where a few return false
7
- # when not developed and checking each value in the list can find the false value
8
- class IdManager
9
- # @return [Boolean] Whether to simulate a fully developed state where everything is done
10
- @developed = false
11
- class << self
12
- attr_accessor :developed
13
-
14
- # Once developed is set, everything will return true. A 'false' value represents something
15
- # not developed
16
- # @param [String] num Number representing tester or test number
17
- # @param [String] id Id used in test
18
- # @return Result depending on num, id and whether '@developed' is set
19
- def result_for(num, id)
20
- result = undeveloped_id(num, id) unless @developed
21
- result || 'true'
22
- end
23
-
24
- # Idea is that this will return false for a particular id for different test numbers
25
- # @param [String] num Number representing tester or test number
26
- # @param [String] id Id used in test
27
- # @return [String] true of false depending on num and id
28
- def undeveloped_id(num, id)
29
- case num
30
- when '1', '4', '10' then 'false' if id == '40'
31
- when '3', '11', '9' then 'false' if id == '74'
32
- when '2', '6', '8' then 'false' if id == '80'
33
- when '7', '5', '12' then 'false' if id == '64'
34
- else
35
- 'true'
36
- end
37
- end
38
- end
39
- end
40
- end
41
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Soaspec
4
+ module TestServer
5
+ # Handles returning ids dependent on a number of factors
6
+ # Made to demonstrate creating testing a list of ids where a few return false
7
+ # when not developed and checking each value in the list can find the false value
8
+ class IdManager
9
+ # @return [Boolean] Whether to simulate a fully developed state where everything is done
10
+ @developed = false
11
+ class << self
12
+ attr_accessor :developed
13
+
14
+ # Once developed is set, everything will return true. A 'false' value represents something
15
+ # not developed
16
+ # @param [String] num Number representing tester or test number
17
+ # @param [String] id Id used in test
18
+ # @return Result depending on num, id and whether '@developed' is set
19
+ def result_for(num, id)
20
+ result = undeveloped_id(num, id) unless @developed
21
+ result || 'true'
22
+ end
23
+
24
+ # Idea is that this will return false for a particular id for different test numbers
25
+ # @param [String] num Number representing tester or test number
26
+ # @param [String] id Id used in test
27
+ # @return [String] true of false depending on num and id
28
+ def undeveloped_id(num, id)
29
+ case num
30
+ when '1', '4', '10' then 'false' if id == '40'
31
+ when '3', '11', '9' then 'false' if id == '74'
32
+ when '2', '6', '8' then 'false' if id == '80'
33
+ when '7', '5', '12' then 'false' if id == '64'
34
+ else
35
+ 'true'
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,29 +1,29 @@
1
- # frozen_string_literal: true
2
-
3
- module Soaspec
4
- module TestServer
5
- # Used to simulate requests requiring oauth authentication
6
- class Invoices
7
- @user_used = nil
8
-
9
- class << self
10
- attr_accessor :user_used
11
-
12
- def oauth_headers
13
- {
14
- 'Content-Type' => 'application/json;charset=UTF-8'
15
- }
16
- end
17
-
18
- def oauth_body
19
- {
20
- access_token: 'TEST_TOKENiIsImtpZCI6IlRFU1QifQ.AAAABBBBRfaWQiOiJhYWQ5MjY3SIMULATE_LARGE_TOKEN3MmM5OGQ5NGE2YTU5YSIsImV4cCI6MTUyNzU3MTY4Mywic2NvcGUiOltdfQ.3OmCdW7fLZMUST_BE_ABLE_TO_HANDLEgAGaJB0lFYyhaw',
21
- token_type: 'Bearer',
22
- expires_in: '86399',
23
- instance_url: %w[http://this_is_my_instance http://this_is_second_instance].sample
24
- }
25
- end
26
- end
27
- end
28
- end
29
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Soaspec
4
+ module TestServer
5
+ # Used to simulate requests requiring oauth authentication
6
+ class Invoices
7
+ @user_used = nil
8
+
9
+ class << self
10
+ attr_accessor :user_used
11
+
12
+ def oauth_headers
13
+ {
14
+ 'Content-Type' => 'application/json;charset=UTF-8'
15
+ }
16
+ end
17
+
18
+ def oauth_body
19
+ {
20
+ access_token: 'TEST_TOKENiIsImtpZCI6IlRFU1QifQ.AAAABBBBRfaWQiOiJhYWQ5MjY3SIMULATE_LARGE_TOKEN3MmM5OGQ5NGE2YTU5YSIsImV4cCI6MTUyNzU3MTY4Mywic2NvcGUiOltdfQ.3OmCdW7fLZMUST_BE_ABLE_TO_HANDLEgAGaJB0lFYyhaw',
21
+ token_type: 'Bearer',
22
+ expires_in: '86399',
23
+ instance_url: %w[http://this_is_my_instance http://this_is_second_instance].sample
24
+ }
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -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,21 +1,21 @@
1
- # frozen_string_literal: true
2
-
3
- module Soaspec
4
- module TestServer
5
- # Simulates ordering a new puppy. Used for testing REST storing, retrieving and updating data
6
- class PuppyService
7
- @data = {}
8
- @current_id = 1
9
- class << self
10
- attr_accessor :data
11
-
12
- def new_id
13
- @data[@current_id] = {}
14
- @data[@current_id][:Id] = @current_id
15
- @current_id += 1
16
- @current_id - 1
17
- end
18
- end
19
- end
20
- end
21
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Soaspec
4
+ module TestServer
5
+ # Simulates ordering a new puppy. Used for testing REST storing, retrieving and updating data
6
+ class PuppyService
7
+ @data = {}
8
+ @current_id = 1
9
+ class << self
10
+ attr_accessor :data
11
+
12
+ def new_id
13
+ @data[@current_id] = {}
14
+ @data[@current_id][:Id] = @current_id
15
+ @current_id += 1
16
+ @current_id - 1
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,14 +1,14 @@
1
- # frozen_string_literal: true
2
-
3
- module Soaspec
4
- module TestServer
5
- # Helps tests attribute methods
6
- class TestAttribute
7
- class << self
8
- def note
9
- File.read(File.join(File.dirname(__FILE__), 'note.xml'))
10
- end
11
- end
12
- end
13
- end
14
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Soaspec
4
+ module TestServer
5
+ # Helps tests attribute methods
6
+ class TestAttribute
7
+ class << self
8
+ def note
9
+ File.read(File.join(File.dirname(__FILE__), 'note.xml'))
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,14 +1,14 @@
1
- # frozen_string_literal: true
2
-
3
- module Soaspec
4
- module TestServer
5
- # Helps tests attribute methods
6
- class TestNamespace
7
- class << self
8
- def food
9
- File.read(File.join(File.dirname(__FILE__), 'namespace.xml'))
10
- end
11
- end
12
- end
13
- end
14
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Soaspec
4
+ module TestServer
5
+ # Helps tests attribute methods
6
+ class TestNamespace
7
+ class << self
8
+ def food
9
+ File.read(File.join(File.dirname(__FILE__), 'namespace.xml'))
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,6 +1,6 @@
1
- # frozen_string_literal: true
2
-
3
- module Soaspec
4
- # @return [String] Version of the gem
5
- VERSION = '0.2.33'
6
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Soaspec
4
+ # @return [String] Version of the gem
5
+ VERSION = '0.3.1'
6
+ end
@@ -1,190 +1,193 @@
1
- # frozen_string_literal: true
2
-
3
- require 'soaspec'
4
- require 'sinatra'
5
- require 'sinatra/basic_auth'
6
- require 'docdsl'
7
- require 'nokogiri'
8
- require 'erb'
9
- require 'json'
10
- require 'faker'
11
- require 'soaspec/test_server/get_bank'
12
- require 'soaspec/test_server/test_attribute'
13
- require 'soaspec/test_server/puppy_service'
14
- require 'soaspec/test_server/invoices'
15
- require 'soaspec/test_server/test_namespace'
16
- require 'soaspec/test_server/id_manager'
17
-
18
- module Soaspec
19
- # Used to run virtual web service on localhost. This makes tests more reliable and faster
20
- # First argument overrides the default port
21
- class VirtualServer < Sinatra::Application
22
- set :bind, '0.0.0.0'
23
- set :port, (ENV['port'] || 4999).to_i
24
-
25
- register Sinatra::DocDsl
26
-
27
- page do
28
- title 'Soaspec Virtual Services'
29
- header 'Perform efficient API testing with Ruby'
30
- introduction 'This has some simple virtual services aimed at helping you with testing your Ruby API code.'
31
- end
32
-
33
- documentation 'Nothing under /. Go look at /docs' do
34
- response 'redirects to the documentation page'
35
- status 302
36
- end
37
- get '/' do
38
- redirect '/docs'
39
- end
40
-
41
- doc_endpoint '/docs'
42
-
43
- documentation 'Simulate server error' do
44
- status 500
45
- end
46
- get '/server_error' do
47
- [500, {}, 'Internal Server Error']
48
- end
49
-
50
- documentation 'Used to verify extract from text response' do
51
- response 'Plain text with a pattern to match in it'
52
- end
53
- get '/text_response' do
54
- 'This is some text. In here it says ID=12345 to indicate value to obtain'
55
- end
56
-
57
- documentation 'Used to demonstrate a multi layered path' do
58
- response 'Simple xml'
59
- end
60
- get '/this/is/a/long/path' do
61
- '<long><path>Text from drilling down to a long path</path></long>'
62
- end
63
-
64
- documentation 'Used to demonstrate response that could be baselined' do
65
- response 'JSON varying according to request params'
66
- end
67
- get '/baseline/:sub1/:sub2' do
68
- JSON.generate(success: true, params: params)
69
- end
70
-
71
- documentation 'Used to test attributes' do
72
- response 'A simple Note XML with a date attribute'
73
- end
74
- get '/test_attribute' do
75
- Soaspec::TestServer::TestAttribute.note
76
- end
77
-
78
- documentation 'Used to test namespaces' do
79
- response 'XML with 2 namespaces and same elements inside it'
80
- end
81
- get '/namespace' do
82
- Soaspec::TestServer::TestNamespace.food
83
- end
84
-
85
- documentation 'Used for showing a simple difference in value depending on the id used' do
86
- param :num, 'Number of tester'
87
- param :id, 'Test parameter'
88
- response 'JSON with success or true or false and the id sent
89
- Idea is for tester to find the id that causes a failure (the fake "defect")
90
- '
91
- end
92
- get '/packages/:num/:id' do |num, id|
93
- JSON.generate(success: Soaspec::TestServer::IdManager.result_for(num, id), id: id)
94
- end
95
-
96
- documentation 'Sets status as developed'
97
- post '/packages/developed' do
98
- Soaspec::TestServer::IdManager.developed = request.body.include?('true')
99
- Soaspec::TestServer::IdManager.developed.to_s
100
- end
101
-
102
- # Used for simple testing of posing
103
- documentation 'Simply sends the response body back'
104
- post '/echoer' do
105
- request.body
106
- end
107
-
108
- documentation "Simulate retrieving an ouath token Passed to '/invoices'"
109
- post '/as/token.oauth2' do
110
- Soaspec::TestServer::Invoices.user_used = request.env['rack.request.form_hash']['username']
111
- [200, Soaspec::TestServer::Invoices.oauth_headers, JSON.generate(Soaspec::TestServer::Invoices.oauth_body)]
112
- end
113
-
114
- documentation 'Replies with HTTP authorization and user set in /as/token.oauth2'
115
- get '/invoice/:id' do |id|
116
- JSON.generate(customer_id: id, oauth: request.env['HTTP_AUTHORIZATION'], user: Soaspec::TestServer::Invoices.user_used)
117
- end
118
-
119
- documentation 'This is returned when a query for the WSDL is made' do
120
- response 'WSDL containing SCHEMA information'
121
- end
122
- get '/BLZService' do
123
- [200, { 'Content-Type' => 'text/xml' }, Soaspec::TestServer::GetBank.test_wsdl]
124
- end
125
-
126
- authorize do |username, password|
127
- username == 'admin' && password == 'secret'
128
- end
129
-
130
- protect do
131
- documentation "Get path used to test basic auth. User is 'admin' & password is 'secret'" do
132
- response 'Secret text'
133
- end
134
- get '/basic_secrets' do
135
- 'Secret data'
136
- end
137
-
138
- documentation 'This is the basic service being hit by SOAP actions'
139
- post '/BLZService' do
140
- Soaspec::TestServer::GetBank.response_for request
141
- end
142
- end
143
-
144
- documentation 'Used for testing storage of data' do
145
- payload 'Puppy JSON',
146
- Name: 'Test', Failure_Type__c: 'Fail'
147
- end
148
- post '/test/puppy' do
149
- request_hash = JSON.parse(request.body.string)
150
- id = Soaspec::TestServer::PuppyService.new_id
151
- Soaspec::TestServer::PuppyService.data[id][:Name] = request_hash['Name']
152
- Soaspec::TestServer::PuppyService.data[id][:Failure_Type__c] = request_hash['Failure_Type__c'] if request_hash['Failure_Type__c']
153
- response_hash = { result: { Status: 'success', Data: Soaspec::TestServer::PuppyService.data[id] } }
154
- JSON.generate response_hash
155
- end
156
-
157
- documentation 'Used for testing retrieving storage of data'
158
- get '/test/puppy/:id' do |id|
159
- result = Soaspec::TestServer::PuppyService.data[id.to_i]
160
- JSON.generate result
161
- end
162
-
163
- documentation 'Used for testing updating data'
164
- patch '/test/puppy/:id' do |id|
165
- request_hash = JSON.parse(request.body.string)
166
- Soaspec::TestServer::PuppyService.data[id.to_i][:Name] = request_hash['Name']
167
- response_hash = { result: { Status: 'updated', With: request_hash['Name'] } }
168
- JSON.generate response_hash
169
- end
170
-
171
- documentation 'Used for testing the handling of JSON path' do
172
- response 'JSON with multiple elements of the same name at different nested levels'
173
- end
174
- get '/test/multiple_json' do
175
- <<-BOOKS
176
- {"store":
177
- {"bicycle":
178
- {"price":19.95, "color":"red"},
179
- "book":[
180
- {"price":8.95, "category":"reference", "title":"Sayings of the Century", "author":"Nigel Rees"},
181
- {"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"},
182
- {"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville","color":"blue"},
183
- {"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"Tolkien"}
184
- ]
185
- }
186
- }
187
- BOOKS
188
- end
189
- end
190
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'soaspec'
4
+ require 'sinatra'
5
+ require 'sinatra/basic_auth'
6
+ require 'docdsl'
7
+ require 'nokogiri'
8
+ require 'erb'
9
+ require 'json'
10
+ require 'faker'
11
+ require 'soaspec/test_server/get_bank'
12
+ require 'soaspec/test_server/test_attribute'
13
+ require 'soaspec/test_server/puppy_service'
14
+ require 'soaspec/test_server/invoices'
15
+ require 'soaspec/test_server/test_namespace'
16
+ require 'soaspec/test_server/id_manager'
17
+
18
+ module Soaspec
19
+ # Used to run virtual web service on localhost. This makes tests more reliable and faster
20
+ # First argument overrides the default port
21
+ class VirtualServer < Sinatra::Application
22
+ set :bind, '0.0.0.0'
23
+ set :port, (ENV['port'] || 4999).to_i
24
+
25
+ register Sinatra::DocDsl
26
+
27
+ page do
28
+ title 'Soaspec Virtual Services'
29
+ header 'Perform efficient API testing with Ruby'
30
+ introduction 'This has some simple virtual services aimed at helping you with testing your Ruby API code.'
31
+ end
32
+
33
+ documentation 'Nothing under /. Go look at /docs' do
34
+ response 'redirects to the documentation page'
35
+ status 302
36
+ end
37
+ get '/' do
38
+ redirect '/docs'
39
+ end
40
+
41
+ doc_endpoint '/docs'
42
+
43
+ documentation 'Simulate server error' do
44
+ status 500
45
+ end
46
+ get '/server_error' do
47
+ [500, {}, 'Internal Server Error']
48
+ end
49
+
50
+ documentation 'Used to verify extract from text response' do
51
+ response 'Plain text with a pattern to match in it'
52
+ end
53
+ get '/text_response' do
54
+ 'This is some text. In here it says ID=12345 to indicate value to obtain'
55
+ end
56
+
57
+ documentation 'Used to demonstrate a multi layered path' do
58
+ response 'Simple xml'
59
+ end
60
+ get '/this/is/a/long/path' do
61
+ '<long><path>Text from drilling down to a long path</path></long>'
62
+ end
63
+
64
+ documentation 'Used to demonstrate response that could be baselined' do
65
+ response 'JSON varying according to request params'
66
+ end
67
+ get '/baseline' do
68
+ JSON.pretty_generate(success: true, params: 'Empty')
69
+ end
70
+ get '/baseline/:sub1/:sub2' do
71
+ JSON.generate(success: true, params: params)
72
+ end
73
+
74
+ documentation 'Used to test attributes' do
75
+ response 'A simple Note XML with a date attribute'
76
+ end
77
+ get '/test_attribute' do
78
+ Soaspec::TestServer::TestAttribute.note
79
+ end
80
+
81
+ documentation 'Used to test namespaces' do
82
+ response 'XML with 2 namespaces and same elements inside it'
83
+ end
84
+ get '/namespace' do
85
+ Soaspec::TestServer::TestNamespace.food
86
+ end
87
+
88
+ documentation 'Used for showing a simple difference in value depending on the id used' do
89
+ param :num, 'Number of tester'
90
+ param :id, 'Test parameter'
91
+ response 'JSON with success or true or false and the id sent
92
+ Idea is for tester to find the id that causes a failure (the fake "defect")
93
+ '
94
+ end
95
+ get '/packages/:num/:id' do |num, id|
96
+ JSON.generate(success: Soaspec::TestServer::IdManager.result_for(num, id), id: id)
97
+ end
98
+
99
+ documentation 'Sets status as developed'
100
+ post '/packages/developed' do
101
+ Soaspec::TestServer::IdManager.developed = request.body.include?('true')
102
+ Soaspec::TestServer::IdManager.developed.to_s
103
+ end
104
+
105
+ # Used for simple testing of posing
106
+ documentation 'Simply sends the response body back'
107
+ post '/echoer' do
108
+ request.body
109
+ end
110
+
111
+ documentation "Simulate retrieving an ouath token Passed to '/invoices'"
112
+ post '/as/token.oauth2' do
113
+ Soaspec::TestServer::Invoices.user_used = request.env['rack.request.form_hash']['username']
114
+ [200, Soaspec::TestServer::Invoices.oauth_headers, JSON.generate(Soaspec::TestServer::Invoices.oauth_body)]
115
+ end
116
+
117
+ documentation 'Replies with HTTP authorization and user set in /as/token.oauth2'
118
+ get '/invoice/:id' do |id|
119
+ JSON.generate(customer_id: id, oauth: request.env['HTTP_AUTHORIZATION'], user: Soaspec::TestServer::Invoices.user_used)
120
+ end
121
+
122
+ documentation 'This is returned when a query for the WSDL is made' do
123
+ response 'WSDL containing SCHEMA information'
124
+ end
125
+ get '/BLZService' do
126
+ [200, { 'Content-Type' => 'text/xml' }, Soaspec::TestServer::GetBank.test_wsdl]
127
+ end
128
+
129
+ authorize do |username, password|
130
+ username == 'admin' && password == 'secret'
131
+ end
132
+
133
+ protect do
134
+ documentation "Get path used to test basic auth. User is 'admin' & password is 'secret'" do
135
+ response 'Secret text'
136
+ end
137
+ get '/basic_secrets' do
138
+ 'Secret data'
139
+ end
140
+
141
+ documentation 'This is the basic service being hit by SOAP actions'
142
+ post '/BLZService' do
143
+ Soaspec::TestServer::GetBank.response_for request
144
+ end
145
+ end
146
+
147
+ documentation 'Used for testing storage of data' do
148
+ payload 'Puppy JSON',
149
+ Name: 'Test', Failure_Type__c: 'Fail'
150
+ end
151
+ post '/test/puppy' do
152
+ request_hash = JSON.parse(request.body.string)
153
+ id = Soaspec::TestServer::PuppyService.new_id
154
+ Soaspec::TestServer::PuppyService.data[id][:Name] = request_hash['Name']
155
+ Soaspec::TestServer::PuppyService.data[id][:Failure_Type__c] = request_hash['Failure_Type__c'] if request_hash['Failure_Type__c']
156
+ response_hash = { result: { Status: 'success', Data: Soaspec::TestServer::PuppyService.data[id] } }
157
+ JSON.generate response_hash
158
+ end
159
+
160
+ documentation 'Used for testing retrieving storage of data'
161
+ get '/test/puppy/:id' do |id|
162
+ result = Soaspec::TestServer::PuppyService.data[id.to_i]
163
+ JSON.generate result
164
+ end
165
+
166
+ documentation 'Used for testing updating data'
167
+ patch '/test/puppy/:id' do |id|
168
+ request_hash = JSON.parse(request.body.string)
169
+ Soaspec::TestServer::PuppyService.data[id.to_i][:Name] = request_hash['Name']
170
+ response_hash = { result: { Status: 'updated', With: request_hash['Name'] } }
171
+ JSON.generate response_hash
172
+ end
173
+
174
+ documentation 'Used for testing the handling of JSON path' do
175
+ response 'JSON with multiple elements of the same name at different nested levels'
176
+ end
177
+ get '/test/multiple_json' do
178
+ <<-BOOKS
179
+ {"store":
180
+ {"bicycle":
181
+ {"price":19.95, "color":"red"},
182
+ "book":[
183
+ {"price":8.95, "category":"reference", "title":"Sayings of the Century", "author":"Nigel Rees"},
184
+ {"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"},
185
+ {"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville","color":"blue"},
186
+ {"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"Tolkien"}
187
+ ]
188
+ }
189
+ }
190
+ BOOKS
191
+ end
192
+ end
193
+ end