diff --git a/plugins/mezuro/lib/kalibro/client/module_result_client.rb b/plugins/mezuro/lib/kalibro/client/module_result_client.rb index a67419f..81b42af 100644 --- a/plugins/mezuro/lib/kalibro/client/module_result_client.rb +++ b/plugins/mezuro/lib/kalibro/client/module_result_client.rb @@ -13,7 +13,7 @@ class Kalibro::Client::ModuleResultClient def module_result(project_name, module_name, date) hash = @port.request(:get_module_result, {:project_name => project_name, :module_name => module_name, - :date => Kalibro::Entitites::Entity.date_with_milliseconds(date)})[:module_result] + :date => Kalibro::Entities::Entity.date_with_milliseconds(date)})[:module_result] Kalibro::Entities::ModuleResult.from_hash(hash) end diff --git a/plugins/mezuro/lib/kalibro/entities/entity.rb b/plugins/mezuro/lib/kalibro/entities/entity.rb index 1e0e03d..e486519 100644 --- a/plugins/mezuro/lib/kalibro/entities/entity.rb +++ b/plugins/mezuro/lib/kalibro/entities/entity.rb @@ -2,10 +2,14 @@ class Kalibro::Entities::Entity def self.from_hash(hash) entity = self.new - hash.each { |field, value| entity.set(field, value) if field.to_s[0] != '@'} + hash.each { |field, value| entity.set(field, value) if is_valid?(field) } entity end + def self.is_valid?(field) + field.to_s[0] != '@' and field != :attributes! + end + def self.date_with_milliseconds(date) milliseconds = "." + (date.sec_fraction * 60 * 60 * 24 * 1000).to_s date.to_s[0..18] + milliseconds + date.to_s[19..-1] @@ -60,7 +64,7 @@ class Kalibro::Entities::Entity def convert_to_hash(value) return value.collect { |element| convert_to_hash(element) } if value.is_a?(Array) return value.to_hash if value.is_a?(Kalibro::Entities::Entity) - return date_with_milliseconds(value) if value.is_a?(DateTime) + return self.class.date_with_milliseconds(value) if value.is_a?(DateTime) return 'INF' if value.is_a?(Float) and value.infinite? == 1 return '-INF' if value.is_a?(Float) and value.infinite? == -1 value diff --git a/plugins/mezuro/lib/kalibro/entities/metric_result.rb b/plugins/mezuro/lib/kalibro/entities/metric_result.rb index bd96d2d..0853d6d 100644 --- a/plugins/mezuro/lib/kalibro/entities/metric_result.rb +++ b/plugins/mezuro/lib/kalibro/entities/metric_result.rb @@ -23,7 +23,8 @@ class Kalibro::Entities::MetricResult < Kalibro::Entities::Entity end def descendent_result=(value) - @descendent_result = value.collect {|element| element.to_f} + array = value.kind_of?(Array) ? value : [value] + @descendent_result = array.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 63f564e..948c22e 100644 --- a/plugins/mezuro/lib/kalibro/entities/module_result.rb +++ b/plugins/mezuro/lib/kalibro/entities/module_result.rb @@ -6,6 +6,11 @@ class Kalibro::Entities::ModuleResult < Kalibro::Entities::Entity @module = to_entity(value, Kalibro::Entities::Module) end + def date=(value) + @date = value + @date = DateTime.parse(value) if value.is_a?(String) + end + def grade=(value) @grade = value.to_f end diff --git a/plugins/mezuro/lib/kalibro/entities/project_result.rb b/plugins/mezuro/lib/kalibro/entities/project_result.rb index 66c375f..cc7848f 100644 --- a/plugins/mezuro/lib/kalibro/entities/project_result.rb +++ b/plugins/mezuro/lib/kalibro/entities/project_result.rb @@ -6,6 +6,11 @@ class Kalibro::Entities::ProjectResult < Kalibro::Entities::Entity @project = to_entity(value, Kalibro::Entities::Project) end + def date=(value) + @date = value + @date = DateTime.parse(value) if value.is_a?(String) + end + def load_time=(value) @load_time = value.to_i end diff --git a/plugins/mezuro/test/fixtures/module_result_fixtures.rb b/plugins/mezuro/test/fixtures/module_result_fixtures.rb index eb15f89..3130123 100644 --- a/plugins/mezuro/test/fixtures/module_result_fixtures.rb +++ b/plugins/mezuro/test/fixtures/module_result_fixtures.rb @@ -18,7 +18,7 @@ class ModuleResultFixtures def self.create_hash {:module => ModuleFixtures.qt_calculator_hash, - :date => DateTime.parse('Thu, 20 Oct 2011 18:26:43.151 +0000'), :grade => 10.0, :metric_result => [ + :date => '2011-10-20T18:26:43.151+00:00', :grade => 10.0, :metric_result => [ MetricResultFixtures.amloc_result_hash, MetricResultFixtures.sc_result_hash], :compound_metric_with_error => [CompoundMetricWithErrorFixtures.create_hash]} diff --git a/plugins/mezuro/test/fixtures/project_result_fixtures.rb b/plugins/mezuro/test/fixtures/project_result_fixtures.rb index df484aa..402daae 100644 --- a/plugins/mezuro/test/fixtures/project_result_fixtures.rb +++ b/plugins/mezuro/test/fixtures/project_result_fixtures.rb @@ -15,7 +15,7 @@ class ProjectResultFixtures end def self.qt_calculator_hash - {:project => ProjectFixtures.qt_calculator_hash, :date => ModuleResultFixtures.create.date, + {:project => ProjectFixtures.qt_calculator_hash, :date => ModuleResultFixtures.create_hash[:date], :load_time => 14878, :analysis_time => 1022, :source_tree => ModuleNodeFixtures.qt_calculator_tree_hash} end diff --git a/plugins/mezuro/test/fixtures/range_fixtures.rb b/plugins/mezuro/test/fixtures/range_fixtures.rb index 0b61583..0abbe41 100644 --- a/plugins/mezuro/test/fixtures/range_fixtures.rb +++ b/plugins/mezuro/test/fixtures/range_fixtures.rb @@ -27,7 +27,7 @@ class RangeFixtures end def self.amloc_bad_hash - {:beginning => 19.5, :end => Infinity, :label => 'Bad',:grade => 0.0, :color => 'ffff0000'} + {:beginning => 19.5, :end => "INF", :label => 'Bad',:grade => 0.0, :color => 'ffff0000'} end end diff --git a/plugins/mezuro/test/functional/echo_port_test.rb b/plugins/mezuro/test/functional/echo_port_test.rb index 537e682..2d8a6d0 100644 --- a/plugins/mezuro/test/functional/echo_port_test.rb +++ b/plugins/mezuro/test/functional/echo_port_test.rb @@ -9,8 +9,7 @@ class EchoPortTest < ActiveSupport::TestCase def setup @port = Kalibro::Client::Port.new('Echo') -# @port.service_address=('http://valinhos.ime.usp.br:50688/KalibroFake/'); - @port.service_address=('http://localhost:8080/KalibroFake/'); + @port.service_address=('http://valinhos.ime.usp.br:50688/KalibroFake/'); end should 'echo base tool' do diff --git a/plugins/mezuro/test/unit/kalibro/entities/project_result_test.rb b/plugins/mezuro/test/unit/kalibro/entities/project_result_test.rb index 1957f31..db35bec 100644 --- a/plugins/mezuro/test/unit/kalibro/entities/project_result_test.rb +++ b/plugins/mezuro/test/unit/kalibro/entities/project_result_test.rb @@ -27,12 +27,12 @@ class ProjectResultTest < ActiveSupport::TestCase should 'retrieve module node' do node = @result.get_node("main") - assert_equal @hash[:source_tree][:child][1], node.to_hash + assert_equal @hash[:source_tree][:child][2], node.to_hash end should 'retrive complex module' do node = @result.get_node("org.Window") - assert_equal @hash[:source_tree][:child][2][:child].first, node.to_hash + assert_equal @hash[:source_tree][:child][0][:child].first, node.to_hash end should 'return source tree node when nil is given' do @@ -44,6 +44,6 @@ class ProjectResultTest < ActiveSupport::TestCase end should 'return correct node when module name is given' do - assert_equal @hash[:source_tree][:child][1], @result.node_of("main").to_hash + assert_equal @hash[:source_tree][:child][2], @result.node_of("main").to_hash end end diff --git a/plugins/mezuro/views/content_viewer/_module_result.rhtml b/plugins/mezuro/views/content_viewer/_module_result.rhtml index b8ac675..782e879 100644 --- a/plugins/mezuro/views/content_viewer/_module_result.rhtml +++ b/plugins/mezuro/views/content_viewer/_module_result.rhtml @@ -19,7 +19,7 @@ <% range = metric_result.range %>