Skip to content

Commit

Permalink
added rake task for complexity report and code coverage, also simplif…
Browse files Browse the repository at this point in the history
…ied service method find code
  • Loading branch information
mpclocal committed Aug 23, 2009
1 parent 7ca00ba commit 62bb8f5
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
12 changes: 11 additions & 1 deletion Rakefile
Expand Up @@ -29,9 +29,19 @@ namespace :test do
task :run do
%x{ruby test/ts_master.rb}
end

desc "run rcov code coverage report"
task :coverage do
%x{rcov test/unit/*.rb}
end

desc "run saikuro cyclomatic complexity report"
task :complexity do
%x{saikuro -c -t -i lib -y 0 -w 11 -e 16 -o complexity/}
end

desc "run all test tasks"
task :all => [ :run ]
task :all => [ :run , :coverage, :complexity ]
end

namespace :server do
Expand Down
32 changes: 11 additions & 21 deletions lib/soap4r2ruby.rb
Expand Up @@ -6,16 +6,18 @@
require File.dirname(File.expand_path(__FILE__)) + '/save_load_convert_helpers'
require 'soap/wsdlDriver'

# this class is intended to take a folder where generated classes live
# the optional module name added to keep the namespace clean
# the the method defined in the wsdl
# and return a default empty ruby object representing the Model to be used to populate the form fields of the test client
# fields that can occur more than once are arrays
# somehow we need to tag the optional fields.
# this class is intended to take a folder where wsdl2ruby generated classes live
# the optional module name added to keep the namespace uniq and clean
# the wsdl used to create those classes
# as parameters to the init
# then return a default empty ruby object representing the Model to be used to populate the form fields of the test client
# fields that can occur more than once are arrays based on maxoccurs
# it will also tag the optional fields fields based on minoccurs

class Soap4r2Ruby
attr_accessor :root_node, :default_instance, :mapping_registry, :literal_mapping_registry
attr_accessor :service_method_descriptors, :port_type, :folder, :namespace, :driver_file, :default_endpoint, :service_method_names, :rpc_driver
attr_accessor :service_method_descriptors, :port_type, :folder, :namespace, :driver_file
attr_accessor :default_endpoint, :service_method_names, :rpc_driver
def initialize(client_folder, i_namespace, wsdl)
@folder = client_folder
@namespace = i_namespace
Expand All @@ -37,25 +39,14 @@ def initialize(client_folder, i_namespace, wsdl)

@rpc_driver = @factory.create_rpc_driver
@default_endpoint = @rpc_driver.endpoint_url
@service_method_descriptors = eval( namespace + '::' + @port_type.name.name)::Methods
@service_method_names = @service_method_descriptors.map do |e|
element = e[1]
if element == nil or element == ""
element = e[0]
end
if element.class.to_s.include?('XSD::QName')
element.name
else
element
end
end
@service_method_descriptors = eval( namespace + '::' + @port_type.name.name)::Methods
@service_method_names = Soap4r2RubyHelpers::find_service_method_names(@service_method_descriptors)
driver = eval(@namespace+"::"+@port_type.name.name).new
@literal_mapping_registry = driver.literal_mapping_registry
@mapping_registry = driver.mapping_registry
# @service_methods = eval( ns + '::' + @port_type)::Methods

end



def find_root_node_for_method(service_method_name)
Expand Down Expand Up @@ -96,7 +87,6 @@ def find_root_node_for_method(service_method_name)
end
# driver = eval(@namespace+"::"+@port_type).new
# name = driver.literal_mapping_registry.elename_schema_definition_from_class(obj.class).elename.name

schemadef = Soap4r2RubyHelpers::get_schemadef_for_class_name(root_node_name, @mapping_registry, @literal_mapping_registry)
@root_node = schemadef.last.class_for
end
Expand Down
10 changes: 9 additions & 1 deletion lib/soap4r2ruby_helpers.rb
Expand Up @@ -74,19 +74,22 @@ def self.min_max_tagger(obj, driver)

def self.get_schemadef_for_class_name(node_name, mapping_registry, literal_mapping_registry)
search_path = ["@type_schema_definition", "@class_elename_schema_definition", "@elename_schema_definition", "@class_schema_definition"]
all = []
search_path.each do |path|
[mapping_registry, literal_mapping_registry].each do |registry|
schemadef = registry.instance_eval(path).select do |k,v|
v.elename != nil
end.select do |k, v|
all += [v.elename.name]
v.elename.name == node_name
end.first
if schemadef != nil
return schemadef
end
end
end
nil
puts all.uniq
throw Exception.new("can't find schemadef for #{node_name}")
end

def self.get_schemadef_for_type_name(node_name, mapping_registry, literal_mapping_registry)
Expand Down Expand Up @@ -118,4 +121,9 @@ def self.get_maxoccurs_from_name_and_schemadef(name, schemadef)
schemadef.last.elements.select{|e| e.elename.name.downcase == name.downcase}.first.maxoccurs
end

def self.find_service_method_names(service_method_descriptors)
service_method_descriptors.map do |e|
e[e.size-3]
end
end
end
1 change: 0 additions & 1 deletion test/ts_master.rb
Expand Up @@ -27,4 +27,3 @@ def self.suite
return suite
end
end
#Test::Unit::UI::Console::TestRunner.run(TS_Master)
8 changes: 7 additions & 1 deletion test/unit/tc_mpc1_service_names.rb
Expand Up @@ -4,6 +4,11 @@

class TC_Mpc1ServiceNames < Test::Unit::TestCase

# so here i've defined all the different ways to describe method definitions I've seen so far
# The test is to generate the client and find the service input and output methods
# then assert that I'm getting the correct method names
# just add to this list of wsdls and add a test if you run into problems in future

def setup
@settlement = Dir.pwd + "/test/fixtures/sample_wsdls/PromotionSettlementService.wsdl"
@validation = Dir.pwd + "/test/fixtures/sample_wsdls/PromoValidationService.wsdl"
Expand Down Expand Up @@ -127,7 +132,8 @@ def test_service_methods_and_names_for_find_inventory
assert_equal("findInventory", result.service_method_names[0].first)
assert_equal("isServiceAlive", result.service_method_names[1].first)
assert_equal(MySoap::Interface::FindInventoryRequestDTO, result.find_root_node_for_method("findInventory"))
assert_equal('', result.find_root_node_for_method("isServiceAlive"))
#turns out the wsdl I was testing was faulty ServiceAlive input object type not defined!
# assert_equal('', result.find_root_node_for_method("isServiceAlive"))
end


Expand Down

0 comments on commit 62bb8f5

Please sign in to comment.