diff --git a/plugins/mezuro/lib/kalibro/entities/error.rb b/plugins/mezuro/lib/kalibro/entities/error.rb index 8a4a879..3dcd05d 100644 --- a/plugins/mezuro/lib/kalibro/entities/error.rb +++ b/plugins/mezuro/lib/kalibro/entities/error.rb @@ -1,6 +1,6 @@ class Kalibro::Entities::Error < Kalibro::Entities::Entity - attr_accessor :message, :stack_trace_element + attr_accessor :error_class, :message, :stack_trace_element def stack_trace_element=(value) @stack_trace_element = to_entity_array(value, Kalibro::Entities::StackTraceElement) diff --git a/plugins/mezuro/lib/kalibro/entities/metric_result.rb b/plugins/mezuro/lib/kalibro/entities/metric_result.rb index 6904421..bd96d2d 100644 --- a/plugins/mezuro/lib/kalibro/entities/metric_result.rb +++ b/plugins/mezuro/lib/kalibro/entities/metric_result.rb @@ -14,12 +14,16 @@ class Kalibro::Entities::MetricResult < Kalibro::Entities::Entity end end + def value=(value) + @value = value.to_f + end + def range=(value) @range = to_entity(value, Kalibro::Entities::Range) end def descendent_result=(value) - @descendent_result = to_entity_array(value) + @descendent_result = value.collect {|element| element.to_f} end def descendent_results diff --git a/plugins/mezuro/lib/kalibro/entities/module_result.rb b/plugins/mezuro/lib/kalibro/entities/module_result.rb index 39d07dd..63f564e 100644 --- a/plugins/mezuro/lib/kalibro/entities/module_result.rb +++ b/plugins/mezuro/lib/kalibro/entities/module_result.rb @@ -6,6 +6,10 @@ class Kalibro::Entities::ModuleResult < Kalibro::Entities::Entity @module = to_entity(value, Kalibro::Entities::Module) end + def grade=(value) + @grade = value.to_f + end + def metric_result=(value) @metric_result = to_entity_array(value, Kalibro::Entities::MetricResult) end diff --git a/plugins/mezuro/lib/kalibro/entities/project_result.rb b/plugins/mezuro/lib/kalibro/entities/project_result.rb index 4cf5e3a..66c375f 100644 --- a/plugins/mezuro/lib/kalibro/entities/project_result.rb +++ b/plugins/mezuro/lib/kalibro/entities/project_result.rb @@ -6,6 +6,14 @@ class Kalibro::Entities::ProjectResult < Kalibro::Entities::Entity @project = to_entity(value, Kalibro::Entities::Project) end + def load_time=(value) + @load_time = value.to_i + end + + def analysis_time=(value) + @analysis_time = value.to_i + end + def source_tree=(value) @source_tree = to_entity(value, Kalibro::Entities::ModuleNode) end diff --git a/plugins/mezuro/lib/kalibro/entities/stack_trace_element.rb b/plugins/mezuro/lib/kalibro/entities/stack_trace_element.rb index 1b68471..5c8ae8a 100644 --- a/plugins/mezuro/lib/kalibro/entities/stack_trace_element.rb +++ b/plugins/mezuro/lib/kalibro/entities/stack_trace_element.rb @@ -2,4 +2,8 @@ class Kalibro::Entities::StackTraceElement < Kalibro::Entities::Entity attr_accessor :declaring_class, :method_name, :file_name, :line_number + def line_number=(value) + @line_number = value.to_i + end + end \ No newline at end of file diff --git a/plugins/mezuro/test/fixtures/error_fixtures.rb b/plugins/mezuro/test/fixtures/error_fixtures.rb index cf44c9c..3a84598 100644 --- a/plugins/mezuro/test/fixtures/error_fixtures.rb +++ b/plugins/mezuro/test/fixtures/error_fixtures.rb @@ -4,6 +4,7 @@ class ErrorFixtures def self.create error = Kalibro::Entities::Error.new + error.error_class = 'java.lang.Exception' error.message = 'Error message from ErrorTest' error.stack_trace = [ StackTraceElementFixtures.create('my method 1', 42), @@ -12,7 +13,8 @@ class ErrorFixtures end def self.create_hash - {:message => 'Error message from ErrorTest', :stack_trace_element => [ + {:error_class => 'java.lang.Exception', :message => 'Error message from ErrorTest', + :stack_trace_element => [ StackTraceElementFixtures.create_hash('my method 1', 42), StackTraceElementFixtures.create_hash('my method 2', 84)]} end diff --git a/plugins/mezuro/test/fixtures/module_node_fixtures.rb b/plugins/mezuro/test/fixtures/module_node_fixtures.rb index a2c9bdc..6dd0fc8 100644 --- a/plugins/mezuro/test/fixtures/module_node_fixtures.rb +++ b/plugins/mezuro/test/fixtures/module_node_fixtures.rb @@ -5,17 +5,17 @@ class ModuleNodeFixtures node.module = ModuleFixtures.qt_calculator org_node = new_node('org', 'PACKAGE') org_node.children = [new_node('org.Window', 'CLASS')] - node.children = [new_node('Dialog', 'CLASS'), new_node('main', 'CLASS'), org_node] + node.children = [org_node, new_node('Dialog', 'CLASS'), new_node('main', 'CLASS')] node end def self.qt_calculator_tree_hash {:module => ModuleFixtures.qt_calculator_hash, :child => [ - {:module => {:name => 'Dialog', :granularity => 'CLASS'}}, - {:module => {:name => 'main', :granularity => 'CLASS'}}, {:module => {:name => 'org', :granularity => 'PACKAGE'}, - :child => [{:module => {:name => 'org.Window', :granularity => 'CLASS'}}]} + :child => [{:module => {:name => 'org.Window', :granularity => 'CLASS'}}]}, + {:module => {:name => 'Dialog', :granularity => 'CLASS'}}, + {:module => {:name => 'main', :granularity => 'CLASS'}} ] } end diff --git a/plugins/mezuro/test/functional/echo_port_test.rb b/plugins/mezuro/test/functional/echo_port_test.rb index 3739250..537e682 100644 --- a/plugins/mezuro/test/functional/echo_port_test.rb +++ b/plugins/mezuro/test/functional/echo_port_test.rb @@ -2,6 +2,8 @@ require "test_helper" require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/base_tool_fixtures" require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures" +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures" class EchoPortTest < ActiveSupport::TestCase @@ -12,17 +14,76 @@ class EchoPortTest < ActiveSupport::TestCase end should 'echo base tool' do - base_tool = BaseToolFixtures.analizo - echoed = @port.request(:echo_base_tool, {:base_tool => base_tool.to_hash})[:base_tool] - base_tool.name = "echo " + base_tool.name - assert_equal base_tool, Kalibro::Entities::BaseTool.from_hash(echoed) + test BaseToolFixtures.analizo, 'BaseTool' do |base_tool| + base_tool.name = "echo " + base_tool.name + end end - + should 'echo configuration' do - configuration = ConfigurationFixtures.kalibro_configuration - echoed = @port.request(:echo_configuration, {:configuration => configuration.to_hash})[:configuration] - configuration.name = "echo " + configuration.name - assert_equal configuration, Kalibro::Entities::Configuration.from_hash(echoed) + test ConfigurationFixtures.kalibro_configuration, 'Configuration' do |configuration| + configuration.name = "echo " + configuration.name + end + end + + should 'echo metric configuration' do + test_metric_configuration(MetricConfigurationFixtures.amloc_configuration) + test_metric_configuration(MetricConfigurationFixtures.sc_configuration) + end + + should 'echo module result' do + test ModuleResultFixtures.create, 'ModuleResult' do |module_result| + module_result.module.name = "echo." + module_result.module.name + end end + + should 'echo project' do + test(ProjectFixtures.qt_calculator, 'Project') do |project| + project.name = "echo " + project.name + end + end + + should 'echo project result' do + test(ProjectResultFixtures.qt_calculator, 'ProjectResult') do |project_result| + project_result.project.name = "echo " + project_result.project.name + end + end + + should 'echo raw project' do + project = ProjectFixtures.qt_calculator + echoed = @port.request(:echo_raw_project, {:project => project.to_hash})[:project] + project.name = "echo " + project.name + project.state = nil + project.error = nil + assert_equal project, Kalibro::Entities::Project.from_hash(echoed) + end + + should 'work with enums' do + test_granularity("METHOD", "CLASS") + test_granularity("CLASS", "PACKAGE") + test_granularity("PACKAGE", "PACKAGE") + test_granularity("APPLICATION", "APPLICATION") + end + + private + def test_metric_configuration(fixture) + test fixture, 'MetricConfiguration' do |metric_configuration| + metric_configuration.code = "echo_" + metric_configuration.code + end + end + + def test(fixture, entity_name) + entity_symbol = entity_name.underscore.to_sym + request_body = {entity_symbol => fixture.to_hash} + echoed = @port.request("echo_#{entity_symbol}".to_sym, request_body)[entity_symbol] + yield fixture + entity_class = "Kalibro::Entities::#{entity_name}".constantize + assert_equal fixture, entity_class.from_hash(echoed) + end + + def test_granularity(granularity, parent) + body = {:granularity => granularity} + assert_equal parent, @port.request(:infer_parent_granularity, body)[:parent_granularity] + end + end \ No newline at end of file -- libgit2 0.21.2