From 6ffaed106a2066b5371e6a2ee45a337221cb4fab Mon Sep 17 00:00:00 2001 From: Alessandro Palmeira + João M. M. da Silva Date: Thu, 1 Nov 2012 15:34:44 -0200 Subject: [PATCH] [Mezuro] Completed base_tool model and changed metric model and fixtures. --- plugins/mezuro/lib/kalibro/base_tool.rb | 2 +- plugins/mezuro/lib/kalibro/compound_metric.rb | 5 ----- plugins/mezuro/lib/kalibro/metric.rb | 14 +++++++++++++- plugins/mezuro/lib/kalibro/native_metric.rb | 17 ----------------- plugins/mezuro/test/fixtures/base_tool_fixtures.rb | 14 +++++++++----- plugins/mezuro/test/fixtures/compound_metric_fixtures.rb | 11 ----------- plugins/mezuro/test/fixtures/metric_fixtures.rb | 27 +++++++++++++++++++++++++++ plugins/mezuro/test/unit/kalibro/base_tool_test.rb | 16 +++++++--------- 8 files changed, 57 insertions(+), 49 deletions(-) delete mode 100644 plugins/mezuro/lib/kalibro/compound_metric.rb delete mode 100644 plugins/mezuro/lib/kalibro/native_metric.rb delete mode 100644 plugins/mezuro/test/fixtures/compound_metric_fixtures.rb create mode 100644 plugins/mezuro/test/fixtures/metric_fixtures.rb diff --git a/plugins/mezuro/lib/kalibro/base_tool.rb b/plugins/mezuro/lib/kalibro/base_tool.rb index bc10586..c665773 100644 --- a/plugins/mezuro/lib/kalibro/base_tool.rb +++ b/plugins/mezuro/lib/kalibro/base_tool.rb @@ -16,7 +16,7 @@ class Kalibro::BaseTool < Kalibro::Model end def supported_metric=(value) - @supported_metric = Kalibro::NativeMetric.to_objects_array value + @supported_metric = Kalibro::Metric.to_objects_array value end def supported_metrics diff --git a/plugins/mezuro/lib/kalibro/compound_metric.rb b/plugins/mezuro/lib/kalibro/compound_metric.rb deleted file mode 100644 index c9f4a1d..0000000 --- a/plugins/mezuro/lib/kalibro/compound_metric.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Kalibro::CompoundMetric < Kalibro::Metric - - attr_accessor :script - -end diff --git a/plugins/mezuro/lib/kalibro/metric.rb b/plugins/mezuro/lib/kalibro/metric.rb index 3390e73..5151db8 100644 --- a/plugins/mezuro/lib/kalibro/metric.rb +++ b/plugins/mezuro/lib/kalibro/metric.rb @@ -1,5 +1,17 @@ class Kalibro::Metric < Kalibro::Model - attr_accessor :name, :scope, :description + attr_accessor :name, :compound, :scope, :description, :script, :origin, :language + + def languages + @language + end + + def languages=(languages) + @language = languages + end + + def language=(value) + @language = Kalibro::Model.to_objects_array value + end end diff --git a/plugins/mezuro/lib/kalibro/native_metric.rb b/plugins/mezuro/lib/kalibro/native_metric.rb deleted file mode 100644 index 57ddc13..0000000 --- a/plugins/mezuro/lib/kalibro/native_metric.rb +++ /dev/null @@ -1,17 +0,0 @@ -class Kalibro::NativeMetric < Kalibro::Metric - - attr_accessor :origin, :language - - def languages - @language - end - - def languages=(languages) - @language = languages - end - - def language=(value) - @language = Kalibro::Model.to_objects_array value - end - -end diff --git a/plugins/mezuro/test/fixtures/base_tool_fixtures.rb b/plugins/mezuro/test/fixtures/base_tool_fixtures.rb index 05ca51a..0a38a6b 100644 --- a/plugins/mezuro/test/fixtures/base_tool_fixtures.rb +++ b/plugins/mezuro/test/fixtures/base_tool_fixtures.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/native_metric_fixtures' +require File.dirname(__FILE__) + '/metric_fixtures' class BaseToolFixtures @@ -6,10 +6,14 @@ class BaseToolFixtures Kalibro::BaseTool.new base_tool_hash end - def self.base_tool_hash - {:name => 'Analizo', :supported_metric => [ - NativeMetricFixtures.total_cof_hash, - NativeMetricFixtures.amloc_hash]} + def self.base_tool_hash + { + :name => 'Analizo', + :supported_metric => [ + MetricFixtures.total_cof_hash, + MetricFixtures.amloc_hash], + :collector_class_name => "org.analizo.AnalizoMetricCollector" + } end end diff --git a/plugins/mezuro/test/fixtures/compound_metric_fixtures.rb b/plugins/mezuro/test/fixtures/compound_metric_fixtures.rb deleted file mode 100644 index a5a87f7..0000000 --- a/plugins/mezuro/test/fixtures/compound_metric_fixtures.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CompoundMetricFixtures - - def self.compound_metric - Kalibro::CompoundMetric.new compound_metric_hash - end - - def self.compound_metric_hash - {:name => 'Structural Complexity', :scope => 'CLASS', :script => 'return 42;', :description => 'Calculate the Structural Complexity of the Code'} - end - -end diff --git a/plugins/mezuro/test/fixtures/metric_fixtures.rb b/plugins/mezuro/test/fixtures/metric_fixtures.rb new file mode 100644 index 0000000..927cfc1 --- /dev/null +++ b/plugins/mezuro/test/fixtures/metric_fixtures.rb @@ -0,0 +1,27 @@ +class MetricFixtures + + def self.compound_metric + Kalibro::Metric.new compound_metric_hash + end + + def self.compound_metric_hash + {:name => 'Structural Complexity', :compound => true, :scope => 'CLASS', :script => 'return 42;', :description => 'Calculate the Structural Complexity of the Code'} + end + + def self.total_cof + Kalibro::Metric.new total_cof_hash + end + + def self.total_cof_hash + {:name => 'Total Coupling Factor', :compound => false, :scope => 'APPLICATION', :origin => 'Analizo', :language => ['JAVA']} + end + + def self.amloc + Kalibro::Metric.new amloc_hash + end + + def self.amloc_hash + {:name => 'Average Method LOC', :compound => false, :scope => 'CLASS', :origin => 'Analizo', :language => ['JAVA']} + end + +end diff --git a/plugins/mezuro/test/unit/kalibro/base_tool_test.rb b/plugins/mezuro/test/unit/kalibro/base_tool_test.rb index f4a00f2..7cc442b 100644 --- a/plugins/mezuro/test/unit/kalibro/base_tool_test.rb +++ b/plugins/mezuro/test/unit/kalibro/base_tool_test.rb @@ -12,14 +12,16 @@ class BaseToolTest < ActiveSupport::TestCase should 'create base tool from hash' do assert_equal @base_tool.name, Kalibro::BaseTool.new(@hash).name end - - should 'convert base tool to hash' do - assert_equal @hash, @base_tool.to_hash - end + +# Mezuro will not send a base_tool hash back to Kalibro +# +# should 'convert base tool to hash' do +# assert_equal @hash, @base_tool.to_hash +# end should 'get base tool names' do names = ['Analizo', 'Checkstyle'] - Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool_names).returns({:base_tool_name => names}) + Kalibro::BaseTool.expects(:request).with("BaseTool", :all_base_tool_names).returns({:base_tool_name => names}) assert_equal names, Kalibro::BaseTool.all_names end @@ -29,8 +31,4 @@ class BaseToolTest < ActiveSupport::TestCase assert_equal @base_tool.name, Kalibro::BaseTool.find_by_name(@base_tool.name).name end - should 'get base tool metrics' do - assert_equal @base_tool.supported_metrics[0].name, @base_tool.metric('Total Coupling Factor').name - end - end -- libgit2 0.21.2