Commit 77c1e68bd1b94445d2f0e1ca434bc2ad791c950a

Authored by Carlos Morais
1 parent ff07e776

[mezuro] EchoPortTest almost complete

Need to fix module result and project result
plugins/mezuro/lib/kalibro/entities/error.rb
1 1 class Kalibro::Entities::Error < Kalibro::Entities::Entity
2 2  
3   - attr_accessor :message, :stack_trace_element
  3 + attr_accessor :error_class, :message, :stack_trace_element
4 4  
5 5 def stack_trace_element=(value)
6 6 @stack_trace_element = to_entity_array(value, Kalibro::Entities::StackTraceElement)
... ...
plugins/mezuro/lib/kalibro/entities/metric_result.rb
... ... @@ -14,12 +14,16 @@ class Kalibro::Entities::MetricResult &lt; Kalibro::Entities::Entity
14 14 end
15 15 end
16 16  
  17 + def value=(value)
  18 + @value = value.to_f
  19 + end
  20 +
17 21 def range=(value)
18 22 @range = to_entity(value, Kalibro::Entities::Range)
19 23 end
20 24  
21 25 def descendent_result=(value)
22   - @descendent_result = to_entity_array(value)
  26 + @descendent_result = value.collect {|element| element.to_f}
23 27 end
24 28  
25 29 def descendent_results
... ...
plugins/mezuro/lib/kalibro/entities/module_result.rb
... ... @@ -6,6 +6,10 @@ class Kalibro::Entities::ModuleResult &lt; Kalibro::Entities::Entity
6 6 @module = to_entity(value, Kalibro::Entities::Module)
7 7 end
8 8  
  9 + def grade=(value)
  10 + @grade = value.to_f
  11 + end
  12 +
9 13 def metric_result=(value)
10 14 @metric_result = to_entity_array(value, Kalibro::Entities::MetricResult)
11 15 end
... ...
plugins/mezuro/lib/kalibro/entities/project_result.rb
... ... @@ -6,6 +6,14 @@ class Kalibro::Entities::ProjectResult &lt; Kalibro::Entities::Entity
6 6 @project = to_entity(value, Kalibro::Entities::Project)
7 7 end
8 8  
  9 + def load_time=(value)
  10 + @load_time = value.to_i
  11 + end
  12 +
  13 + def analysis_time=(value)
  14 + @analysis_time = value.to_i
  15 + end
  16 +
9 17 def source_tree=(value)
10 18 @source_tree = to_entity(value, Kalibro::Entities::ModuleNode)
11 19 end
... ...
plugins/mezuro/lib/kalibro/entities/stack_trace_element.rb
... ... @@ -2,4 +2,8 @@ class Kalibro::Entities::StackTraceElement &lt; Kalibro::Entities::Entity
2 2  
3 3 attr_accessor :declaring_class, :method_name, :file_name, :line_number
4 4  
  5 + def line_number=(value)
  6 + @line_number = value.to_i
  7 + end
  8 +
5 9 end
6 10 \ No newline at end of file
... ...
plugins/mezuro/test/fixtures/error_fixtures.rb
... ... @@ -4,6 +4,7 @@ class ErrorFixtures
4 4  
5 5 def self.create
6 6 error = Kalibro::Entities::Error.new
  7 + error.error_class = 'java.lang.Exception'
7 8 error.message = 'Error message from ErrorTest'
8 9 error.stack_trace = [
9 10 StackTraceElementFixtures.create('my method 1', 42),
... ... @@ -12,7 +13,8 @@ class ErrorFixtures
12 13 end
13 14  
14 15 def self.create_hash
15   - {:message => 'Error message from ErrorTest', :stack_trace_element => [
  16 + {:error_class => 'java.lang.Exception', :message => 'Error message from ErrorTest',
  17 + :stack_trace_element => [
16 18 StackTraceElementFixtures.create_hash('my method 1', 42),
17 19 StackTraceElementFixtures.create_hash('my method 2', 84)]}
18 20 end
... ...
plugins/mezuro/test/fixtures/module_node_fixtures.rb
... ... @@ -5,17 +5,17 @@ class ModuleNodeFixtures
5 5 node.module = ModuleFixtures.qt_calculator
6 6 org_node = new_node('org', 'PACKAGE')
7 7 org_node.children = [new_node('org.Window', 'CLASS')]
8   - node.children = [new_node('Dialog', 'CLASS'), new_node('main', 'CLASS'), org_node]
  8 + node.children = [org_node, new_node('Dialog', 'CLASS'), new_node('main', 'CLASS')]
9 9 node
10 10 end
11 11  
12 12 def self.qt_calculator_tree_hash
13 13 {:module => ModuleFixtures.qt_calculator_hash,
14 14 :child => [
15   - {:module => {:name => 'Dialog', :granularity => 'CLASS'}},
16   - {:module => {:name => 'main', :granularity => 'CLASS'}},
17 15 {:module => {:name => 'org', :granularity => 'PACKAGE'},
18   - :child => [{:module => {:name => 'org.Window', :granularity => 'CLASS'}}]}
  16 + :child => [{:module => {:name => 'org.Window', :granularity => 'CLASS'}}]},
  17 + {:module => {:name => 'Dialog', :granularity => 'CLASS'}},
  18 + {:module => {:name => 'main', :granularity => 'CLASS'}}
19 19 ]
20 20 }
21 21 end
... ...
plugins/mezuro/test/functional/echo_port_test.rb
... ... @@ -2,6 +2,8 @@ require &quot;test_helper&quot;
2 2  
3 3 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/base_tool_fixtures"
4 4 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures"
  5 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures"
  6 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures"
5 7  
6 8 class EchoPortTest < ActiveSupport::TestCase
7 9  
... ... @@ -12,17 +14,76 @@ class EchoPortTest &lt; ActiveSupport::TestCase
12 14 end
13 15  
14 16 should 'echo base tool' do
15   - base_tool = BaseToolFixtures.analizo
16   - echoed = @port.request(:echo_base_tool, {:base_tool => base_tool.to_hash})[:base_tool]
17   - base_tool.name = "echo " + base_tool.name
18   - assert_equal base_tool, Kalibro::Entities::BaseTool.from_hash(echoed)
  17 + test BaseToolFixtures.analizo, 'BaseTool' do |base_tool|
  18 + base_tool.name = "echo " + base_tool.name
  19 + end
19 20 end
20   -
  21 +
21 22 should 'echo configuration' do
22   - configuration = ConfigurationFixtures.kalibro_configuration
23   - echoed = @port.request(:echo_configuration, {:configuration => configuration.to_hash})[:configuration]
24   - configuration.name = "echo " + configuration.name
25   - assert_equal configuration, Kalibro::Entities::Configuration.from_hash(echoed)
  23 + test ConfigurationFixtures.kalibro_configuration, 'Configuration' do |configuration|
  24 + configuration.name = "echo " + configuration.name
  25 + end
  26 + end
  27 +
  28 + should 'echo metric configuration' do
  29 + test_metric_configuration(MetricConfigurationFixtures.amloc_configuration)
  30 + test_metric_configuration(MetricConfigurationFixtures.sc_configuration)
  31 + end
  32 +
  33 + should 'echo module result' do
  34 + test ModuleResultFixtures.create, 'ModuleResult' do |module_result|
  35 + module_result.module.name = "echo." + module_result.module.name
  36 + end
26 37 end
  38 +
  39 + should 'echo project' do
  40 + test(ProjectFixtures.qt_calculator, 'Project') do |project|
  41 + project.name = "echo " + project.name
  42 + end
  43 + end
  44 +
  45 + should 'echo project result' do
  46 + test(ProjectResultFixtures.qt_calculator, 'ProjectResult') do |project_result|
  47 + project_result.project.name = "echo " + project_result.project.name
  48 + end
  49 + end
  50 +
  51 + should 'echo raw project' do
  52 + project = ProjectFixtures.qt_calculator
  53 + echoed = @port.request(:echo_raw_project, {:project => project.to_hash})[:project]
  54 + project.name = "echo " + project.name
  55 + project.state = nil
  56 + project.error = nil
  57 + assert_equal project, Kalibro::Entities::Project.from_hash(echoed)
  58 + end
  59 +
  60 + should 'work with enums' do
  61 + test_granularity("METHOD", "CLASS")
  62 + test_granularity("CLASS", "PACKAGE")
  63 + test_granularity("PACKAGE", "PACKAGE")
  64 + test_granularity("APPLICATION", "APPLICATION")
  65 + end
  66 +
  67 + private
27 68  
  69 + def test_metric_configuration(fixture)
  70 + test fixture, 'MetricConfiguration' do |metric_configuration|
  71 + metric_configuration.code = "echo_" + metric_configuration.code
  72 + end
  73 + end
  74 +
  75 + def test(fixture, entity_name)
  76 + entity_symbol = entity_name.underscore.to_sym
  77 + request_body = {entity_symbol => fixture.to_hash}
  78 + echoed = @port.request("echo_#{entity_symbol}".to_sym, request_body)[entity_symbol]
  79 + yield fixture
  80 + entity_class = "Kalibro::Entities::#{entity_name}".constantize
  81 + assert_equal fixture, entity_class.from_hash(echoed)
  82 + end
  83 +
  84 + def test_granularity(granularity, parent)
  85 + body = {:granularity => granularity}
  86 + assert_equal parent, @port.request(:infer_parent_granularity, body)[:parent_granularity]
  87 + end
  88 +
28 89 end
29 90 \ No newline at end of file
... ...