exe/soaspec in soaspec-0.0.77 vs exe/soaspec in soaspec-0.0.78
- old
+ new
@@ -5,42 +5,120 @@
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
require 'savon'
require 'soaspec'
module Soaspec
+
# Common executable for Soaspec
class Exe < Thor
include Soaspec::ExeHelpers
+ include Soaspec::WsdlGenerator
- desc 'soaspec [type]', 'Initialize soaspec repository'
- def init
- puts 'Creating files for soaspec'
+ long_desc <<-LONGDESC
+ `soaspec new` will generate the initial files and folders for starting a testing project using soaspec
+ \x5
- create_file(filename: 'Gemfile', content: gem_content)
- create_file(filename: 'Rakefile', content: rake_virtual_content)
- create_file(filename: 'README.md', content: readme_content)
+ `soaspec new soap` will create example files testing against a virtual SOAP service
+ \x5
+
+ `soaspec new rest` will create example files testing against a virtual REST service
+ LONGDESC
+ desc 'new [type]', 'Initialize soaspec repository'
+ option :ci, default: 'jenkins', banner: 'What Continuous Integration is used'
+ option :virtual, type: :boolean, default: true, banner: 'Whether to set things up for a virtual server'
+ def new(type = 'initial')
+ puts 'Creating files for soaspec'
+ @virtual = options[:virtual]
+ create_file(filename: 'Gemfile')
+ create_file(filename: 'Rakefile')
+ create_file(filename: '.rspec')
+ create_file(filename: '.travis.yml') if options[:ci] == 'travis'
+ create_file(filename: 'README.md')
create_folder 'lib'
- create_file(filename: 'lib/blz_service.rb', content: weather_web_service)
- create_file filename: 'lib/shared_example.rb', content: shared_examples_content
+ if type == 'soap'
+ create_file filename: 'lib/blz_service.rb'
+ create_file filename: 'lib/shared_example.rb'
+ end
create_folder 'config'
create_folder 'config/data'
- create_file(filename: 'config/data/default.yml', content: default_yaml_content)
+ create_file(filename: 'config/data/default.yml')
create_folder 'spec'
- create_folder 'spec/test_data'
- create_folder 'spec/test_data/wsdl'
- create_file(filename: 'spec/spec_helper.rb', content: spec_helper_content)
- create_file(filename: 'spec/soap_spec.rb', content: soap_spec_content)
- create_file(filename: 'spec/test_server.rb', content: test_server_content)
- create_file(filename: 'spec/test_data/wsdl/get_bank.wsdl', content: test_wsdl_content)
+ create_file(filename: 'spec/spec_helper.rb')
+ create_file(filename: 'spec/soap_spec.rb') if type == 'soap'
create_folder 'template'
- create_file(filename: 'template/soap_template.xml', content: soap_template_content)
+ create_file(filename: 'template/soap_template.xml', erb: false) if type == 'soap'
create_folder 'logs'
puts "Run 'bundle install' to install necessary gems"
puts "Run 'rake spec' to run the tests"
- puts "Note: Setup runs Sinatra for Test Service on port 4567 by default. Change Rakefile 'start_test_server' task to update this"
end
+
+ desc 'generate', 'Generate initial test code from wsdl'
+ long_desc <<-LONGDESC
+ `soaspec generate wsdl=wsdl name=ServiceName ` will generate the initial files and folders to test each operation in a wsdl
+ \x5
+ Additionally the auth parameter can be used to use basic authentication to retrieve the WSDL.
+ To do use the following `soaspec generate --auth=basic`
+
+ LONGDESC
+ option :wsdl, required: true, aliases: :w
+ option :name, default: 'Service', aliases: :n
+ option :ci, default: 'jenkins', banner: 'What Continuous Integration is used'
+ option :auth
+ option :string_default, default: 'test string'
+ def generate
+ enter_auth_details if options[:auth] == 'basic'
+ @virtual = false
+ savon_options = { wsdl: options[:wsdl] }
+ savon_options[:basic_auth] = [@auth_name, @auth_password] if options[:auth] == 'basic'
+
+ @wsdl_doc = Savon.client(**savon_options).wsdl
+ @wsdl_schemas = @wsdl_doc.parser.schemas
+
+ create_file filename: 'Rakefile', ignore_if_present: true
+ create_file filename: 'Gemfile', ignore_if_present: true
+ create_file(filename: '.rspec')
+ create_file(filename: '.travis.yml') if options[:ci] == 'travis'
+ create_file filename: 'README.md', ignore_if_present: true
+ create_folder 'spec'
+ create_file filename: 'spec/spec_helper.rb', ignore_if_present: true
+
+ create_folder 'logs'
+ create_folder 'config'
+ create_folder 'config/data'
+ create_folder 'lib'
+ create_file filename: "lib/#{options[:name].snakecase}.rb", content: class_content
+
+ # Files according to WSDL
+ @wsdl_doc.operations.each do |operation, details|
+ puts "Creating files for operation: #{operation}"
+ @content = "default:\n"
+ @use_camel_case = false
+ puts 'Message params: ' + details.to_s
+ # From namespace identifier, find namespace, and for that find schemaLocation xsd and use that to build request
+ if details[:parameters]
+ details[:parameters].each do |element, details|
+ @use_camel_case = true if /[[:upper:]]/.match(element.to_s[0]) != nil
+ @content += " #{element.to_s.snakecase}: #{fill_in_field_from_type(details[:type])} # #{details[:type]} \n"
+ # TODO: If details is a Hash need to loop again
+ end
+ end
+
+ root_type = @wsdl_schemas.at_xpath("//*[@name='#{details[:input]}']")['type'].split(':').last
+ root_elements = @wsdl_schemas.xpath("//*[@name='#{root_type}']//xsd:element")
+ wsdl_to_yaml_for root_elements
+
+ params = []
+ params << 'convert_request_keys_to: :camelcase' if @use_camel_case
+ params_string = params == [] ? '' : ', ' + params.join(', ')
+ @class_params = "'#{camel_case(operation)}'#{params_string}"
+
+ create_file(filename: "config/data/#{operation}.yml", content: @content)
+ create_file(filename: "spec/#{operation}_spec.rb", content: generated_soap_spec_for(operation))
+ end
+ end
+
end
end
Soaspec::Exe.start(ARGV)
\ No newline at end of file