soaspec 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +15 -15
  3. data/.gitlab-ci.yml +48 -48
  4. data/.rspec +3 -3
  5. data/.rubocop.yml +2 -2
  6. data/CODE_OF_CONDUCT.md +74 -74
  7. data/ChangeLog +408 -404
  8. data/Gemfile +6 -6
  9. data/LICENSE.txt +21 -21
  10. data/README.md +113 -113
  11. data/Rakefile +24 -24
  12. data/Todo.md +6 -6
  13. data/exe/soaspec +109 -109
  14. data/exe/soaspec-virtual-server +156 -156
  15. data/exe/xml_to_yaml_file +60 -60
  16. data/lib/soaspec.rb +107 -103
  17. data/lib/soaspec/core_ext/hash.rb +83 -83
  18. data/lib/soaspec/exchange.rb +235 -235
  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 +54 -92
  22. data/lib/soaspec/exchange_handlers/rest_handler.rb +318 -314
  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 +60 -60
  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/o_auth2.rb +65 -0
  43. data/lib/soaspec/soaspec_shared_examples.rb +24 -24
  44. data/lib/soaspec/spec_logger.rb +34 -27
  45. data/lib/soaspec/test_server/bank.wsdl +90 -90
  46. data/lib/soaspec/test_server/get_bank.rb +160 -160
  47. data/lib/soaspec/test_server/id_manager.rb +31 -31
  48. data/lib/soaspec/test_server/invoices.rb +27 -27
  49. data/lib/soaspec/test_server/namespace.xml +14 -14
  50. data/lib/soaspec/test_server/note.xml +5 -5
  51. data/lib/soaspec/test_server/puppy_service.rb +20 -20
  52. data/lib/soaspec/test_server/test_attribute.rb +13 -13
  53. data/lib/soaspec/test_server/test_namespace.rb +12 -12
  54. data/lib/soaspec/version.rb +2 -2
  55. data/lib/soaspec/wsdl_generator.rb +144 -144
  56. data/soaspec.gemspec +46 -46
  57. data/test.wsdl +116 -116
  58. data/test.xml +10 -10
  59. data/test_wsdl.rb +43 -43
  60. metadata +4 -3
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:gitlab) { |repo_name| "https://gitlab.com/samuel-garratt/soaspec" }
4
-
5
- # Specify your gem's dependencies in soaspec.gemspec
6
- gemspec
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:gitlab) { |repo_name| "https://gitlab.com/samuel-garratt/soaspec" }
4
+
5
+ # Specify your gem's dependencies in soaspec.gemspec
6
+ gemspec
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2018 Samuel Garratt
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Samuel Garratt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,113 +1,113 @@
1
- # Soaspec
2
-
3
- This gem helps to represent multiple API tests against a backend briefly, concisely and clearly. It is essentially a wrapper around the Savon and RestClient gems. Note it is still in early stages of development.
4
-
5
- [![Build Status](https://gitlab.com/samuel-garratt/soaspec/badges/master/build.svg)](https://gitlab.com/samuel-garratt/soaspec/pipelines)
6
- [![Coverage](https://gitlab.com/samuel-garratt/soaspec/badges/master/coverage.svg)](https://samuel-garratt.gitlab.io/soaspec)
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'soaspec'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install soaspec
22
-
23
- [Things to be done](Todo.md)
24
-
25
- ## Getting Started
26
-
27
- To create a new test suite using this you can use the 'soaspec' binary.
28
-
29
- Example:
30
-
31
- ```
32
- mkdir 'api_test'
33
- cd 'api_test'
34
- soaspec new
35
- bundle install
36
- ```
37
-
38
- Then you can run the tests with:
39
-
40
- ```
41
- rake spec
42
- ```
43
-
44
- You can also use `soaspec generate` to generate a set of tests from a WSDL. This is still in trial period and will be finished probably after Savon 3 is more stable.
45
-
46
- ## Usage
47
-
48
- * SOAP - this uses Savon behind the scenes. Some defaults are overridden. Please see 'soap_handler.rb'-'default_options' method
49
- for such defaults. When describing an API override this in 'savon_options' method
50
- * REST - this uses the resource class from the Rest-Client gem behind the scenes.
51
-
52
- See specs for example of usage. This will be added to later.
53
-
54
- Basically you create a class inheriting from a ‘Handler’ class for each web service that’s tested.
55
- In this class you define the common parameters used for testing this class.
56
-
57
- For example:
58
-
59
- ```ruby
60
- class PuppyService < Soaspec::RestHandler
61
-
62
- headers accept: 'application/json', content_type: 'application/json'
63
-
64
- base_url 'http://petstore.swagger.io/v2/pet'
65
-
66
- element :id, :id
67
- element :category_id, '$..category.id'
68
- end
69
- ```
70
-
71
- Then you reference this class in creating `Exchange`’s (representing a request / response pair).
72
- Upon initialization of the Exchange object or later on through setters, parameters specific to this request are set
73
- All getters of the Exchange are on the response & will implicitly trigger the API request to be made.
74
-
75
- For example:
76
-
77
- ```ruby
78
- context PuppyService.new('Order Puppies') do
79
- describe post(:create_pet, body: { status: 'sold' }) do # Post with status as sold in request
80
- its(['status']) { is_expected.to eq 'sold' } # Check responses status is sold
81
- end
82
- end
83
- ```
84
-
85
- ### Recommended
86
-
87
- If you find having a large backtrace on errors or RSpec shared examples such as 'success scenarios' this can shorten the
88
- backtrace.
89
-
90
- RSpec.configure do |config|
91
-
92
- config.backtrace_exclusion_patterns = [
93
- /rspec/
94
- ]
95
- end
96
-
97
- ## Development
98
-
99
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
100
-
101
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
102
-
103
- ## Contributing
104
-
105
- Bug reports and pull requests are welcome on GitLab at https://gitlab.com/samuel-garratt/soaspec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
106
-
107
- ## License
108
-
109
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
110
-
111
- ## Code of Conduct
112
-
113
- Everyone interacting in the Soaspec project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/samuel-garratt/soaspec/blob/master/CODE_OF_CONDUCT.md).
1
+ # Soaspec
2
+
3
+ This gem helps to represent multiple API tests against a backend briefly, concisely and clearly. It is essentially a wrapper around the Savon and RestClient gems. Note it is still in early stages of development.
4
+
5
+ [![Build Status](https://gitlab.com/samuel-garratt/soaspec/badges/master/build.svg)](https://gitlab.com/samuel-garratt/soaspec/pipelines)
6
+ [![Coverage](https://gitlab.com/samuel-garratt/soaspec/badges/master/coverage.svg)](https://samuel-garratt.gitlab.io/soaspec)
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'soaspec'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install soaspec
22
+
23
+ [Things to be done](Todo.md)
24
+
25
+ ## Getting Started
26
+
27
+ To create a new test suite using this you can use the 'soaspec' binary.
28
+
29
+ Example:
30
+
31
+ ```
32
+ mkdir 'api_test'
33
+ cd 'api_test'
34
+ soaspec new
35
+ bundle install
36
+ ```
37
+
38
+ Then you can run the tests with:
39
+
40
+ ```
41
+ rake spec
42
+ ```
43
+
44
+ You can also use `soaspec generate` to generate a set of tests from a WSDL. This is still in trial period and will be finished probably after Savon 3 is more stable.
45
+
46
+ ## Usage
47
+
48
+ * SOAP - this uses Savon behind the scenes. Some defaults are overridden. Please see 'soap_handler.rb'-'default_options' method
49
+ for such defaults. When describing an API override this in 'savon_options' method
50
+ * REST - this uses the resource class from the Rest-Client gem behind the scenes.
51
+
52
+ See specs for example of usage. This will be added to later.
53
+
54
+ Basically you create a class inheriting from a ‘Handler’ class for each web service that’s tested.
55
+ In this class you define the common parameters used for testing this class.
56
+
57
+ For example:
58
+
59
+ ```ruby
60
+ class PuppyService < Soaspec::RestHandler
61
+
62
+ headers accept: 'application/json', content_type: 'application/json'
63
+
64
+ base_url 'http://petstore.swagger.io/v2/pet'
65
+
66
+ element :id, :id
67
+ element :category_id, '$..category.id'
68
+ end
69
+ ```
70
+
71
+ Then you reference this class in creating `Exchange`’s (representing a request / response pair).
72
+ Upon initialization of the Exchange object or later on through setters, parameters specific to this request are set
73
+ All getters of the Exchange are on the response & will implicitly trigger the API request to be made.
74
+
75
+ For example:
76
+
77
+ ```ruby
78
+ context PuppyService.new('Order Puppies') do
79
+ describe post(:create_pet, body: { status: 'sold' }) do # Post with status as sold in request
80
+ its(['status']) { is_expected.to eq 'sold' } # Check responses status is sold
81
+ end
82
+ end
83
+ ```
84
+
85
+ ### Recommended
86
+
87
+ If you find having a large backtrace on errors or RSpec shared examples such as 'success scenarios' this can shorten the
88
+ backtrace.
89
+
90
+ RSpec.configure do |config|
91
+
92
+ config.backtrace_exclusion_patterns = [
93
+ /rspec/
94
+ ]
95
+ end
96
+
97
+ ## Development
98
+
99
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
100
+
101
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
102
+
103
+ ## Contributing
104
+
105
+ Bug reports and pull requests are welcome on GitLab at https://gitlab.com/samuel-garratt/soaspec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
106
+
107
+ ## License
108
+
109
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
110
+
111
+ ## Code of Conduct
112
+
113
+ Everyone interacting in the Soaspec project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/samuel-garratt/soaspec/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,24 +1,24 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
- require 'rake/clean'
4
-
5
- ENV['folder'] ||= ''
6
- ENV['test'] ||= ''
7
-
8
- desc 'Run tests'
9
- RSpec::Core::RakeTask.new(spec: %i[clean clobber start_test_server]) do |t|
10
- t.pattern = "spec/**/#{ENV['folder']}*/#{ENV['test']}*_spec.rb"
11
- end
12
-
13
- task default: :spec
14
-
15
- CLEAN.include 'tmp/*'
16
- CLOBBER.include 'logs/*'
17
-
18
- desc 'Start virtual web service'
19
- task :start_test_server do
20
- mkdir_p 'logs'
21
- ENV['test_server_pid'] = Process.spawn('ruby', 'exe/soaspec-virtual-server', err: %w[logs/test_server.log w]).to_s
22
- sleep 2 # Wait a little for virtual server to start up
23
- puts 'Running test server at pid ' + ENV['test_server_pid']
24
- end
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rake/clean'
4
+
5
+ ENV['folder'] ||= ''
6
+ ENV['test'] ||= ''
7
+
8
+ desc 'Run tests'
9
+ RSpec::Core::RakeTask.new(spec: %i[clean clobber start_test_server]) do |t|
10
+ t.pattern = "spec/**/#{ENV['folder']}*/#{ENV['test']}*_spec.rb"
11
+ end
12
+
13
+ task default: :spec
14
+
15
+ CLEAN.include 'tmp/*'
16
+ CLOBBER.include 'logs/*'
17
+
18
+ desc 'Start virtual web service'
19
+ task :start_test_server do
20
+ mkdir_p 'logs'
21
+ ENV['test_server_pid'] = Process.spawn('ruby', 'exe/soaspec-virtual-server', err: %w[logs/test_server.log w]).to_s
22
+ sleep 2 # Wait a little for virtual server to start up
23
+ puts 'Running test server at pid ' + ENV['test_server_pid']
24
+ end
data/Todo.md CHANGED
@@ -1,6 +1,6 @@
1
- * Give examples and convenience methods for building classes for each SOAP or REST operation
2
- * For SOAP give example of basic_auth
3
- * Potentially have in built use of 'vcr' and 'http_stub' gems
4
- * Handle proxies to record traffic for MiddleWare testing
5
- * Get wsdl generator working for non complex gems (Put on hold til new Savon version)
6
- * Much more - please raise an issue for suggestion
1
+ * Give examples and convenience methods for building classes for each SOAP or REST operation
2
+ * For SOAP give example of basic_auth
3
+ * Potentially have in built use of 'vcr' and 'http_stub' gems
4
+ * Handle proxies to record traffic for MiddleWare testing
5
+ * Get wsdl generator working for non complex gems (Put on hold til new Savon version)
6
+ * Much more - please raise an issue for suggestion
@@ -1,110 +1,110 @@
1
- #!/usr/bin/env ruby
2
-
3
-
4
- require 'thor'
5
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
6
- require 'savon'
7
- require 'soaspec'
8
-
9
- module Soaspec
10
-
11
- # Common executable for Soaspec
12
- class Exe < Thor
13
-
14
- include Soaspec::ExeHelpers
15
- include Soaspec::WsdlGenerator
16
-
17
- long_desc <<-LONGDESC
18
- `soaspec new` will generate the initial files and folders for starting a testing project using soaspec
19
- \x5
20
-
21
- `soaspec new soap` will create example files testing against a virtual SOAP service
22
- \x5
23
-
24
- `soaspec new rest` will create example files testing against a virtual REST service
25
- LONGDESC
26
- desc 'new [type]', 'Initialize soaspec repository'
27
- option :ci, default: 'jenkins', banner: 'What Continuous Integration is used'
28
- option :virtual, type: :boolean, default: true, banner: 'Whether to set things up for a virtual server'
29
- def new(type = 'initial')
30
- @virtual = options[:virtual]
31
- puts "Creating files for soaspec. options are #{options}"
32
- create_file(filename: 'Gemfile')
33
- create_file(filename: 'Rakefile')
34
- create_file(filename: '.rspec')
35
- create_file(filename: '.travis.yml') if options[:ci] == 'travis'
36
- create_file(filename: 'README.md')
37
- if type == 'soap'
38
- create_file filename: 'lib/blz_service.rb'
39
- create_file filename: 'lib/shared_example.rb'
40
- end
41
- create_file(filename: 'config/data/default.yml')
42
- create_file(filename: 'spec/spec_helper.rb')
43
- create_file(filename: 'spec/soap_spec.rb') if type == 'soap'
44
- create_file(filename: 'template/soap_template.xml', erb: false) if type == 'soap'
45
- create_folder 'logs'
46
-
47
- puts "Run 'bundle install' to install necessary gems"
48
- puts "Run 'rake spec' to run the tests"
49
- end
50
-
51
- desc 'generate', 'Generate initial test code from wsdl'
52
- long_desc <<-LONGDESC
53
- `soaspec generate wsdl=wsdl name=ServiceName ` will generate the initial files and folders to test each operation in a wsdl
54
- \x5
55
- Additionally the auth parameter can be used to use basic authentication to retrieve the WSDL.
56
- To do use the following `soaspec generate --auth=basic`
57
-
58
- LONGDESC
59
- option :wsdl, required: true, aliases: :w
60
- option :name, default: 'Service', aliases: :n
61
- option :ci, default: 'jenkins', banner: 'What Continuous Integration is used'
62
- option :auth
63
- option :string_default, default: 'test string'
64
- def generate
65
- enter_auth_details if options[:auth] == 'basic'
66
- @virtual = false
67
- savon_options = { wsdl: options[:wsdl] }
68
- savon_options[:basic_auth] = [@auth_name, @auth_password] if options[:auth] == 'basic'
69
-
70
- @wsdl_doc = Savon.client(**savon_options).wsdl
71
- @wsdl_schemas = @wsdl_doc.parser.schemas
72
-
73
- create_file filename: 'Rakefile', ignore_if_present: true
74
- create_file filename: 'Gemfile', ignore_if_present: true
75
- create_file(filename: '.rspec')
76
- create_file(filename: '.travis.yml') if options[:ci] == 'travis'
77
- create_file filename: 'README.md', ignore_if_present: true
78
- create_file filename: 'spec/spec_helper.rb', ignore_if_present: true
79
- create_folder 'logs'
80
- create_file filename: "lib/#{options[:name].snakecase}.rb", content: class_content
81
-
82
- # Files according to WSDL
83
- @wsdl_doc.operations.each do |operation, details|
84
- puts "Creating files for operation: #{operation}"
85
- @content = "default:\n"
86
- @use_camel_case = false
87
- puts 'Message params: ' + details.to_s
88
- # From namespace identifier, find namespace, and for that find schemaLocation xsd and use that to build request
89
- if details[:parameters]
90
- details[:parameters].each do |element, details|
91
- @use_camel_case = true if /[[:upper:]]/.match(element.to_s[0]) != nil
92
- @content += " #{element.to_s.snakecase}: #{fill_in_field_from_type(details[:type])} # #{details[:type]} \n"
93
- # TODO: If details is a Hash need to loop again
94
- end
95
- end
96
- wsdl_to_yaml_for root_elements_for(details)
97
- params = []
98
- params << 'convert_request_keys_to: :camelcase' if @use_camel_case
99
- params_string = params == [] ? '' : ', ' + params.join(', ')
100
- @class_params = "'#{camel_case(operation)}'#{params_string}"
101
-
102
- create_file(filename: "config/data/#{operation}.yml", content: @content)
103
- create_file(filename: "spec/#{operation}_spec.rb", content: generated_soap_spec_for(operation))
104
- end
105
- end
106
-
107
- end
108
- end
109
-
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ require 'thor'
5
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
6
+ require 'savon'
7
+ require 'soaspec'
8
+
9
+ module Soaspec
10
+
11
+ # Common executable for Soaspec
12
+ class Exe < Thor
13
+
14
+ include Soaspec::ExeHelpers
15
+ include Soaspec::WsdlGenerator
16
+
17
+ long_desc <<-LONGDESC
18
+ `soaspec new` will generate the initial files and folders for starting a testing project using soaspec
19
+ \x5
20
+
21
+ `soaspec new soap` will create example files testing against a virtual SOAP service
22
+ \x5
23
+
24
+ `soaspec new rest` will create example files testing against a virtual REST service
25
+ LONGDESC
26
+ desc 'new [type]', 'Initialize soaspec repository'
27
+ option :ci, default: 'jenkins', banner: 'What Continuous Integration is used'
28
+ option :virtual, type: :boolean, default: true, banner: 'Whether to set things up for a virtual server'
29
+ def new(type = 'initial')
30
+ @virtual = options[:virtual]
31
+ puts "Creating files for soaspec. options are #{options}"
32
+ create_file(filename: 'Gemfile')
33
+ create_file(filename: 'Rakefile')
34
+ create_file(filename: '.rspec')
35
+ create_file(filename: '.travis.yml') if options[:ci] == 'travis'
36
+ create_file(filename: 'README.md')
37
+ if type == 'soap'
38
+ create_file filename: 'lib/blz_service.rb'
39
+ create_file filename: 'lib/shared_example.rb'
40
+ end
41
+ create_file(filename: 'config/data/default.yml')
42
+ create_file(filename: 'spec/spec_helper.rb')
43
+ create_file(filename: 'spec/soap_spec.rb') if type == 'soap'
44
+ create_file(filename: 'template/soap_template.xml', erb: false) if type == 'soap'
45
+ create_folder 'logs'
46
+
47
+ puts "Run 'bundle install' to install necessary gems"
48
+ puts "Run 'rake spec' to run the tests"
49
+ end
50
+
51
+ desc 'generate', 'Generate initial test code from wsdl'
52
+ long_desc <<-LONGDESC
53
+ `soaspec generate wsdl=wsdl name=ServiceName ` will generate the initial files and folders to test each operation in a wsdl
54
+ \x5
55
+ Additionally the auth parameter can be used to use basic authentication to retrieve the WSDL.
56
+ To do use the following `soaspec generate --auth=basic`
57
+
58
+ LONGDESC
59
+ option :wsdl, required: true, aliases: :w
60
+ option :name, default: 'Service', aliases: :n
61
+ option :ci, default: 'jenkins', banner: 'What Continuous Integration is used'
62
+ option :auth
63
+ option :string_default, default: 'test string'
64
+ def generate
65
+ enter_auth_details if options[:auth] == 'basic'
66
+ @virtual = false
67
+ savon_options = { wsdl: options[:wsdl] }
68
+ savon_options[:basic_auth] = [@auth_name, @auth_password] if options[:auth] == 'basic'
69
+
70
+ @wsdl_doc = Savon.client(**savon_options).wsdl
71
+ @wsdl_schemas = @wsdl_doc.parser.schemas
72
+
73
+ create_file filename: 'Rakefile', ignore_if_present: true
74
+ create_file filename: 'Gemfile', ignore_if_present: true
75
+ create_file(filename: '.rspec')
76
+ create_file(filename: '.travis.yml') if options[:ci] == 'travis'
77
+ create_file filename: 'README.md', ignore_if_present: true
78
+ create_file filename: 'spec/spec_helper.rb', ignore_if_present: true
79
+ create_folder 'logs'
80
+ create_file filename: "lib/#{options[:name].snakecase}.rb", content: class_content
81
+
82
+ # Files according to WSDL
83
+ @wsdl_doc.operations.each do |operation, details|
84
+ puts "Creating files for operation: #{operation}"
85
+ @content = "default:\n"
86
+ @use_camel_case = false
87
+ puts 'Message params: ' + details.to_s
88
+ # From namespace identifier, find namespace, and for that find schemaLocation xsd and use that to build request
89
+ if details[:parameters]
90
+ details[:parameters].each do |element, details|
91
+ @use_camel_case = true if /[[:upper:]]/.match(element.to_s[0]) != nil
92
+ @content += " #{element.to_s.snakecase}: #{fill_in_field_from_type(details[:type])} # #{details[:type]} \n"
93
+ # TODO: If details is a Hash need to loop again
94
+ end
95
+ end
96
+ wsdl_to_yaml_for root_elements_for(details)
97
+ params = []
98
+ params << 'convert_request_keys_to: :camelcase' if @use_camel_case
99
+ params_string = params == [] ? '' : ', ' + params.join(', ')
100
+ @class_params = "'#{camel_case(operation)}'#{params_string}"
101
+
102
+ create_file(filename: "config/data/#{operation}.yml", content: @content)
103
+ create_file(filename: "spec/#{operation}_spec.rb", content: generated_soap_spec_for(operation))
104
+ end
105
+ end
106
+
107
+ end
108
+ end
109
+
110
110
  Soaspec::Exe.start(ARGV)