soaspec 0.1.1 → 0.1.2

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 (57) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +15 -15
  3. data/.gitlab-ci.yml +31 -31
  4. data/.rspec +3 -3
  5. data/.rubocop.yml +2 -2
  6. data/CODE_OF_CONDUCT.md +74 -74
  7. data/ChangeLog +384 -384
  8. data/Gemfile +6 -6
  9. data/LICENSE.txt +21 -21
  10. data/README.md +85 -85
  11. data/Rakefile +24 -24
  12. data/Todo.md +6 -6
  13. data/exe/soaspec +119 -119
  14. data/exe/soaspec-virtual-server +103 -103
  15. data/exe/xml_to_yaml_file +60 -60
  16. data/lib/soaspec.rb +91 -91
  17. data/lib/soaspec/core_ext/hash.rb +83 -83
  18. data/lib/soaspec/exchange.rb +234 -234
  19. data/lib/soaspec/exchange_handlers/exchange_handler.rb +103 -103
  20. data/lib/soaspec/exchange_handlers/handler_accessors.rb +106 -106
  21. data/lib/soaspec/exchange_handlers/rest_accessors.rb +92 -92
  22. data/lib/soaspec/exchange_handlers/rest_handler.rb +311 -311
  23. data/lib/soaspec/exchange_handlers/rest_methods.rb +44 -44
  24. data/lib/soaspec/exchange_handlers/soap_handler.rb +236 -236
  25. data/lib/soaspec/exe_helpers.rb +56 -56
  26. data/lib/soaspec/generator/.rspec.erb +5 -5
  27. data/lib/soaspec/generator/.travis.yml.erb +5 -5
  28. data/lib/soaspec/generator/Gemfile.erb +8 -8
  29. data/lib/soaspec/generator/README.md.erb +29 -29
  30. data/lib/soaspec/generator/Rakefile.erb +19 -19
  31. data/lib/soaspec/generator/config/data/default.yml.erb +1 -1
  32. data/lib/soaspec/generator/lib/blz_service.rb.erb +26 -26
  33. data/lib/soaspec/generator/lib/dynamic_class_content.rb.erb +12 -12
  34. data/lib/soaspec/generator/lib/shared_example.rb.erb +8 -8
  35. data/lib/soaspec/generator/spec/dynamic_soap_spec.rb.erb +12 -12
  36. data/lib/soaspec/generator/spec/soap_spec.rb.erb +51 -51
  37. data/lib/soaspec/generator/spec/spec_helper.rb.erb +20 -20
  38. data/lib/soaspec/generator/template/soap_template.xml +6 -6
  39. data/lib/soaspec/interpreter.rb +40 -40
  40. data/lib/soaspec/matchers.rb +65 -65
  41. data/lib/soaspec/not_found_errors.rb +13 -13
  42. data/lib/soaspec/soaspec_shared_examples.rb +24 -24
  43. data/lib/soaspec/spec_logger.rb +27 -27
  44. data/lib/soaspec/test_server/bank.wsdl +90 -90
  45. data/lib/soaspec/test_server/get_bank.rb +160 -160
  46. data/lib/soaspec/test_server/invoices.rb +27 -27
  47. data/lib/soaspec/test_server/namespace.xml +14 -14
  48. data/lib/soaspec/test_server/note.xml +5 -5
  49. data/lib/soaspec/test_server/puppy_service.rb +20 -20
  50. data/lib/soaspec/test_server/test_attribute.rb +13 -13
  51. data/lib/soaspec/version.rb +2 -2
  52. data/lib/soaspec/wsdl_generator.rb +144 -144
  53. data/soaspec.gemspec +46 -45
  54. data/test.wsdl +116 -116
  55. data/test.xml +10 -10
  56. data/test_wsdl.rb +43 -43
  57. metadata +17 -3
@@ -1,104 +1,104 @@
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
- # Used for simple testing of posing
30
- post '/echoer' do
31
- request.body
32
- end
33
-
34
- # Simulate retrieving an ouath token. Passed to '/invoices'
35
- post '/as/token.oauth2' do
36
- Soaspec::TestServer::Invoices.user_used = request.env['rack.request.form_hash']['username']
37
- [200, Soaspec::TestServer::Invoices.oauth_headers, JSON.generate(Soaspec::TestServer::Invoices.oauth_body)]
38
- end
39
-
40
- get '/invoice/:id' do |id|
41
- JSON.generate(customer_id: id, oauth: request.env['HTTP_AUTHORIZATION'], user: Soaspec::TestServer::Invoices.user_used)
42
- end
43
-
44
- # This is returned when a query for the WSDL is made
45
- get '/BLZService' do
46
- [200, { 'Content-Type' => 'text/xml' }, Soaspec::TestServer::GetBank.test_wsdl]
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
-
58
- # This is the one being hit by SOAP actions
59
- post '/BLZService' do
60
- Soaspec::TestServer::GetBank.response_for request
61
- end
62
- end
63
-
64
- # Used for testing storage of data
65
- post '/test/puppy' do
66
- request_hash = JSON.parse(request.body.string)
67
- id = Soaspec::TestServer::PuppyService.new_id
68
- Soaspec::TestServer::PuppyService.data[id][:Name] = request_hash['Name']
69
- Soaspec::TestServer::PuppyService.data[id][:Failure_Type__c] = request_hash['Failure_Type__c'] if request_hash['Failure_Type__c']
70
- response_hash = { result: { Status: 'success', Data: Soaspec::TestServer::PuppyService.data[id] } }
71
- JSON.generate response_hash
72
- end
73
-
74
- # Used for testing retrieving storage of data
75
- get '/test/puppy/:id' do |id|
76
- result = Soaspec::TestServer::PuppyService.data[id.to_i]
77
- JSON.generate result
78
- end
79
-
80
- get '/test/multiple_json' do
81
- <<-BOOKS
82
- {"store":
83
- {"bicycle":
84
- {"price":19.95, "color":"red"},
85
- "book":[
86
- {"price":8.95, "category":"reference", "title":"Sayings of the Century", "author":"Nigel Rees"},
87
- {"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"},
88
- {"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville","color":"blue"},
89
- {"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"Tolkien"}
90
- ]
91
- }
92
- }
93
- BOOKS
94
- end
95
-
96
- patch '/test/puppy/:id' do |id|
97
- request_hash = JSON.parse(request.body.string)
98
- Soaspec::TestServer::PuppyService.data[id.to_i][:Name] = request_hash['Name']
99
- response_hash = { result: { Status: 'updated', With: request_hash['Name'] } }
100
- JSON.generate response_hash
101
- end
102
- end
103
-
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
+ # Used for simple testing of posing
30
+ post '/echoer' do
31
+ request.body
32
+ end
33
+
34
+ # Simulate retrieving an ouath token. Passed to '/invoices'
35
+ post '/as/token.oauth2' do
36
+ Soaspec::TestServer::Invoices.user_used = request.env['rack.request.form_hash']['username']
37
+ [200, Soaspec::TestServer::Invoices.oauth_headers, JSON.generate(Soaspec::TestServer::Invoices.oauth_body)]
38
+ end
39
+
40
+ get '/invoice/:id' do |id|
41
+ JSON.generate(customer_id: id, oauth: request.env['HTTP_AUTHORIZATION'], user: Soaspec::TestServer::Invoices.user_used)
42
+ end
43
+
44
+ # This is returned when a query for the WSDL is made
45
+ get '/BLZService' do
46
+ [200, { 'Content-Type' => 'text/xml' }, Soaspec::TestServer::GetBank.test_wsdl]
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
+
58
+ # This is the one being hit by SOAP actions
59
+ post '/BLZService' do
60
+ Soaspec::TestServer::GetBank.response_for request
61
+ end
62
+ end
63
+
64
+ # Used for testing storage of data
65
+ post '/test/puppy' do
66
+ request_hash = JSON.parse(request.body.string)
67
+ id = Soaspec::TestServer::PuppyService.new_id
68
+ Soaspec::TestServer::PuppyService.data[id][:Name] = request_hash['Name']
69
+ Soaspec::TestServer::PuppyService.data[id][:Failure_Type__c] = request_hash['Failure_Type__c'] if request_hash['Failure_Type__c']
70
+ response_hash = { result: { Status: 'success', Data: Soaspec::TestServer::PuppyService.data[id] } }
71
+ JSON.generate response_hash
72
+ end
73
+
74
+ # Used for testing retrieving storage of data
75
+ get '/test/puppy/:id' do |id|
76
+ result = Soaspec::TestServer::PuppyService.data[id.to_i]
77
+ JSON.generate result
78
+ end
79
+
80
+ get '/test/multiple_json' do
81
+ <<-BOOKS
82
+ {"store":
83
+ {"bicycle":
84
+ {"price":19.95, "color":"red"},
85
+ "book":[
86
+ {"price":8.95, "category":"reference", "title":"Sayings of the Century", "author":"Nigel Rees"},
87
+ {"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"},
88
+ {"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville","color":"blue"},
89
+ {"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"Tolkien"}
90
+ ]
91
+ }
92
+ }
93
+ BOOKS
94
+ end
95
+
96
+ patch '/test/puppy/:id' do |id|
97
+ request_hash = JSON.parse(request.body.string)
98
+ Soaspec::TestServer::PuppyService.data[id.to_i][:Name] = request_hash['Name']
99
+ response_hash = { result: { Status: 'updated', With: request_hash['Name'] } }
100
+ JSON.generate response_hash
101
+ end
102
+ end
103
+
104
104
  SoaspecVirtualServer.run!
@@ -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
@@ -1,91 +1,91 @@
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
- # Specify whether to see params sent to and retrieved from oauth. This will put password in log file, only recommended for debugging
37
- attr_writer :debug_oauth
38
-
39
- # Folder used to store credentials
40
- # Used in auth2_file command
41
- # @param [String] folder
42
- def credentials_folder=(folder)
43
- @credentials_folder = folder
44
- end
45
-
46
- # Credentials folder used to store secret data (not in source control) E.g passwords
47
- def credentials_folder
48
- @credentials_folder
49
- end
50
-
51
- # Used so that exchange class knows what context it's in
52
- # @param [ExchangeHandler] handler A class inheriting from Soaspec::ExchangeHandler. Exchange class uses this
53
- def api_handler=(handler)
54
- @api_handler = handler
55
- end
56
-
57
- # Exchange Handler class currently being used
58
- def api_handler
59
- @api_handler
60
- end
61
-
62
- # Set whether to transform strings to keys in request automatically
63
- # @param [Boolean] use_keys
64
- def always_use_keys=(use_keys)
65
- @always_use_keys = use_keys
66
- end
67
-
68
- # @return [Boolean] Whether to transform strings to keys in request automatically
69
- def always_use_keys?
70
- @always_use_keys || true
71
- end
72
-
73
- # @return [Boolean] Whether to see params sent to & received from oauth URL
74
- def debug_oauth?
75
- @debug_oauth || false
76
- end
77
-
78
- # Whether to log all API traffic
79
- def log_api_traffic=(set)
80
- @log_api_traffic = set
81
- RestClient.log = nil unless set
82
- end
83
-
84
- # @return [Boolean] Whether to log all API traffic
85
- def log_api_traffic?
86
- @log_api_traffic.nil? ? true : @log_api_traffic
87
- end
88
- end
89
- end
90
-
91
- RestClient.log = Soaspec::SpecLogger.create
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
+ # Specify whether to see params sent to and retrieved from oauth. This will put password in log file, only recommended for debugging
37
+ attr_writer :debug_oauth
38
+
39
+ # Folder used to store credentials
40
+ # Used in auth2_file command
41
+ # @param [String] folder
42
+ def credentials_folder=(folder)
43
+ @credentials_folder = folder
44
+ end
45
+
46
+ # Credentials folder used to store secret data (not in source control) E.g passwords
47
+ def credentials_folder
48
+ @credentials_folder
49
+ end
50
+
51
+ # Used so that exchange class knows what context it's in
52
+ # @param [ExchangeHandler] handler A class inheriting from Soaspec::ExchangeHandler. Exchange class uses this
53
+ def api_handler=(handler)
54
+ @api_handler = handler
55
+ end
56
+
57
+ # Exchange Handler class currently being used
58
+ def api_handler
59
+ @api_handler
60
+ end
61
+
62
+ # Set whether to transform strings to keys in request automatically
63
+ # @param [Boolean] use_keys
64
+ def always_use_keys=(use_keys)
65
+ @always_use_keys = use_keys
66
+ end
67
+
68
+ # @return [Boolean] Whether to transform strings to keys in request automatically
69
+ def always_use_keys?
70
+ @always_use_keys || true
71
+ end
72
+
73
+ # @return [Boolean] Whether to see params sent to & received from oauth URL
74
+ def debug_oauth?
75
+ @debug_oauth || false
76
+ end
77
+
78
+ # Whether to log all API traffic
79
+ def log_api_traffic=(set)
80
+ @log_api_traffic = set
81
+ RestClient.log = nil unless set
82
+ end
83
+
84
+ # @return [Boolean] Whether to log all API traffic
85
+ def log_api_traffic?
86
+ @log_api_traffic.nil? ? true : @log_api_traffic
87
+ end
88
+ end
89
+ end
90
+
91
+ RestClient.log = Soaspec::SpecLogger.create