Permalink
Browse files

added rake task for complexity report and code coverage, also simplif…

…ied service method find code
  • Loading branch information...
1 parent 7ca00ba commit 62bb8f5faef25846a48324a934dac17d81edb0d3 mpclocal committed Aug 23, 2009
Showing with 38 additions and 25 deletions.
  1. +11 −1 Rakefile
  2. +11 −21 lib/soap4r2ruby.rb
  3. +9 −1 lib/soap4r2ruby_helpers.rb
  4. +0 −1 test/ts_master.rb
  5. +7 −1 test/unit/tc_mpc1_service_names.rb
View
@@ -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
View
@@ -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
@@ -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)
@@ -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
@@ -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)
@@ -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
View
@@ -27,4 +27,3 @@ def self.suite
return suite
end
end
-#Test::Unit::UI::Console::TestRunner.run(TS_Master)
@@ -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"
@@ -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

0 comments on commit 62bb8f5

Please sign in to comment.