Commit 66fb1ebe1c66cd4f92140c22f5b2b4d12063e873

Authored by João M. M. da Silva + Caio Salgado
Committed by Paulo Meireles
1 parent e134eeeb

[Mezuro] Refactored module result to model and refactored tests

Showing 39 changed files with 310 additions and 424 deletions   Show diff stats
plugins/mezuro/lib/kalibro/base_tool.rb
@@ -11,7 +11,7 @@ class Kalibro::BaseTool < Kalibro::Model @@ -11,7 +11,7 @@ class Kalibro::BaseTool < Kalibro::Model
11 end 11 end
12 12
13 def supported_metric=(value) 13 def supported_metric=(value)
14 - @supported_metric = to_objects_array(value, Kalibro::NativeMetric) 14 + @supported_metric = Kalibro::NativeMetric.to_objects_array value
15 end 15 end
16 16
17 def supported_metrics 17 def supported_metrics
plugins/mezuro/lib/kalibro/client/module_result_client.rb
@@ -1,19 +0,0 @@ @@ -1,19 +0,0 @@
1 -class Kalibro::Client::ModuleResultClient  
2 -  
3 - def initialize  
4 - @port = Kalibro::Client::Port.new('ModuleResult')  
5 - end  
6 -  
7 - def module_result(project_name, module_name, date)  
8 - hash = @port.request(:get_module_result,  
9 - {:project_name => project_name, :module_name => module_name,  
10 - :date => Kalibro::Entities::Entity.date_with_milliseconds(date)})[:module_result]  
11 - Kalibro::Entities::ModuleResult.from_hash(hash)  
12 - end  
13 -  
14 - def result_history(project_name, module_name)  
15 - value = @port.request(:get_result_history,  
16 - {:project_name => project_name, :module_name => module_name})[:module_result]  
17 - Kalibro::Entities::Entity.new.to_entity_array(value, Kalibro::Entities::ModuleResult)  
18 - end  
19 -end  
plugins/mezuro/lib/kalibro/compound_metric_with_error.rb 0 → 100644
@@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
  1 +class Kalibro::CompoundMetricWithError < Kalibro::Model
  2 +
  3 + attr_accessor :metric, :error
  4 +
  5 + def metric=(value)
  6 + @metric = Kalibro::CompoundMetric.to_object value
  7 + end
  8 +
  9 + def error=(value)
  10 + @error = Kalibro::Error.to_object value
  11 + end
  12 +
  13 +end
plugins/mezuro/lib/kalibro/configuration.rb
@@ -3,7 +3,7 @@ class Kalibro::Configuration &lt; Kalibro::Model @@ -3,7 +3,7 @@ class Kalibro::Configuration &lt; Kalibro::Model
3 attr_accessor :name, :description, :metric_configuration 3 attr_accessor :name, :description, :metric_configuration
4 4
5 def metric_configuration=(value) 5 def metric_configuration=(value)
6 - @metric_configuration = to_objects_array(value, Kalibro::MetricConfiguration) 6 + @metric_configuration = Kalibro::MetricConfiguration.to_objects_array value
7 end 7 end
8 8
9 def metric_configurations 9 def metric_configurations
plugins/mezuro/lib/kalibro/entities/compound_metric_with_error.rb
@@ -1,13 +0,0 @@ @@ -1,13 +0,0 @@
1 -class Kalibro::Entities::CompoundMetricWithError < Kalibro::Entities::Entity  
2 -  
3 - attr_accessor :metric, :error  
4 -  
5 - def metric=(value)  
6 - @metric = to_entity(value, Kalibro::Entities::CompoundMetric)  
7 - end  
8 -  
9 - def error=(value)  
10 - @error = to_entity(value, Kalibro::Entities::Error)  
11 - end  
12 -  
13 -end  
14 \ No newline at end of file 0 \ No newline at end of file
plugins/mezuro/lib/kalibro/entities/error.rb
@@ -1,21 +0,0 @@ @@ -1,21 +0,0 @@
1 -class Kalibro::Entities::Error < Kalibro::Entities::Entity  
2 -  
3 - attr_accessor :error_class, :message, :stack_trace_element, :cause  
4 -  
5 - def stack_trace_element=(value)  
6 - @stack_trace_element = to_entity_array(value, Kalibro::Entities::StackTraceElement)  
7 - end  
8 -  
9 - def stack_trace  
10 - @stack_trace_element  
11 - end  
12 -  
13 - def stack_trace=(stack_trace)  
14 - @stack_trace_element = stack_trace  
15 - end  
16 -  
17 - def cause=(cause_value)  
18 - @cause = to_entity(cause_value, Kalibro::Entities::Error)  
19 - end  
20 -  
21 -end  
plugins/mezuro/lib/kalibro/entities/metric_result.rb
@@ -1,38 +0,0 @@ @@ -1,38 +0,0 @@
1 -class Kalibro::Entities::MetricResult < Kalibro::Entities::Entity  
2 -  
3 - attr_accessor :metric, :value, :range, :descendent_result, :weight  
4 -  
5 - def metric=(value)  
6 - if value.kind_of?(Hash)  
7 - if value.has_key?(:script)  
8 - @metric = to_entity(value, Kalibro::CompoundMetric)  
9 - else  
10 - @metric = to_entity(value, Kalibro::NativeMetric)  
11 - end  
12 - else  
13 - @metric = value  
14 - end  
15 - end  
16 -  
17 - def value=(value)  
18 - @value = value.to_f  
19 - end  
20 -  
21 - def range=(value)  
22 - @range = to_entity(value, Kalibro::Entities::Range)  
23 - end  
24 -  
25 - def descendent_result=(value)  
26 - array = value.kind_of?(Array) ? value : [value]  
27 - @descendent_result = array.collect {|element| element.to_f}  
28 - end  
29 -  
30 - def descendent_results  
31 - @descendent_result  
32 - end  
33 -  
34 - def descendent_results=(descendent_results)  
35 - @descendent_result = descendent_results  
36 - end  
37 -  
38 -end  
plugins/mezuro/lib/kalibro/entities/module.rb
@@ -1,18 +0,0 @@ @@ -1,18 +0,0 @@
1 -class Kalibro::Entities::Module < Kalibro::Entities::Entity  
2 -  
3 - attr_accessor :name, :granularity  
4 -  
5 - def self.parent_names(name)  
6 - path = []  
7 - ancestors = []  
8 - name.split(".").each do |token|  
9 - path << token  
10 - ancestors << path.join(".")  
11 - end  
12 - ancestors  
13 - end  
14 -  
15 - def ancestor_names  
16 - Kalibro::Entities::Module.parent_names(@name)  
17 - end  
18 -end  
plugins/mezuro/lib/kalibro/entities/module_result.rb
@@ -1,42 +0,0 @@ @@ -1,42 +0,0 @@
1 -class Kalibro::Entities::ModuleResult < Kalibro::Entities::Entity  
2 -  
3 - attr_accessor :module, :date, :grade, :metric_result, :compound_metric_with_error  
4 -  
5 - def module=(value)  
6 - @module = to_entity(value, Kalibro::Entities::Module)  
7 - end  
8 -  
9 - def date=(value)  
10 - @date = value  
11 - @date = DateTime.parse(value) if value.is_a?(String)  
12 - end  
13 -  
14 - def grade=(value)  
15 - @grade = value.to_f  
16 - end  
17 -  
18 - def metric_result=(value)  
19 - @metric_result = to_entity_array(value, Kalibro::Entities::MetricResult)  
20 - end  
21 -  
22 - def metric_results  
23 - @metric_result  
24 - end  
25 -  
26 - def metric_results=(metric_results)  
27 - @metric_result = metric_results  
28 - end  
29 -  
30 - def compound_metric_with_error=(value)  
31 - @compound_metric_with_error = to_entity_array(value, Kalibro::Entities::CompoundMetricWithError)  
32 - end  
33 -  
34 - def compound_metrics_with_error  
35 - @compound_metric_with_error  
36 - end  
37 -  
38 - def compound_metrics_with_error=(compound_metrics_with_error)  
39 - @compound_metric_with_error = compound_metrics_with_error  
40 - end  
41 -  
42 -end  
43 \ No newline at end of file 0 \ No newline at end of file
plugins/mezuro/lib/kalibro/entities/stack_trace_element.rb
@@ -1,9 +0,0 @@ @@ -1,9 +0,0 @@
1 -class Kalibro::Entities::StackTraceElement < Kalibro::Entities::Entity  
2 -  
3 - attr_accessor :declaring_class, :method_name, :file_name, :line_number  
4 -  
5 - def line_number=(value)  
6 - @line_number = value.to_i  
7 - end  
8 -  
9 -end  
10 \ No newline at end of file 0 \ No newline at end of file
plugins/mezuro/lib/kalibro/error.rb 0 → 100644
@@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
  1 +class Kalibro::Error < Kalibro::Model
  2 +
  3 + attr_accessor :error_class, :message, :stack_trace_element, :cause
  4 +
  5 + def stack_trace_element=(value)
  6 + @stack_trace_element = Kalibro::StackTraceElement.to_objects_array value
  7 + end
  8 +
  9 + def stack_trace
  10 + @stack_trace_element
  11 + end
  12 +
  13 + def stack_trace=(stack_trace)
  14 + @stack_trace_element = stack_trace
  15 + end
  16 +
  17 + def cause=(cause_value)
  18 + @cause = Kalibro::Error.to_object cause_value
  19 + end
  20 +
  21 +end
plugins/mezuro/lib/kalibro/metric_configuration.rb
@@ -7,8 +7,8 @@ class Kalibro::MetricConfiguration &lt; Kalibro::Model @@ -7,8 +7,8 @@ class Kalibro::MetricConfiguration &lt; Kalibro::Model
7 7
8 def metric=(value) 8 def metric=(value)
9 if value.kind_of?(Hash) 9 if value.kind_of?(Hash)
10 - @metric = to_object(value, Kalibro::NativeMetric) if value.has_key?(:origin)  
11 - @metric = to_object(value, Kalibro::CompoundMetric) if value.has_key?(:script) 10 + @metric = Kalibro::NativeMetric.to_object(value) if value.has_key?(:origin)
  11 + @metric = Kalibro::CompoundMetric.to_object(value) if value.has_key?(:script)
12 else 12 else
13 @metric = value 13 @metric = value
14 end 14 end
@@ -19,7 +19,7 @@ class Kalibro::MetricConfiguration &lt; Kalibro::Model @@ -19,7 +19,7 @@ class Kalibro::MetricConfiguration &lt; Kalibro::Model
19 end 19 end
20 20
21 def range=(value) 21 def range=(value)
22 - @range = to_objects_array(value, Kalibro::Range) 22 + @range = Kalibro::Range.to_objects_array value
23 end 23 end
24 24
25 def add_range(new_range) 25 def add_range(new_range)
plugins/mezuro/lib/kalibro/metric_result.rb
@@ -4,12 +4,12 @@ class Kalibro::MetricResult &lt; Kalibro::Model @@ -4,12 +4,12 @@ class Kalibro::MetricResult &lt; Kalibro::Model
4 4
5 def metric=(value) 5 def metric=(value)
6 if value.kind_of?(Hash) 6 if value.kind_of?(Hash)
7 - compound?(value) ? @metric = to_object(value, Kalibro::CompoundMetric) : @metric = to_object(value, Kalibro::NativeMetric) 7 + compound?(value) ? @metric = Kalibro::CompoundMetric.to_object(value) : @metric = Kalibro::NativeMetric.to_object(value)
8 else 8 else
9 @metric = value 9 @metric = value
10 end 10 end
11 end 11 end
12 - 12 +
13 def compound?(metric) 13 def compound?(metric)
14 metric.has_key?(:script) 14 metric.has_key?(:script)
15 end 15 end
@@ -19,7 +19,7 @@ class Kalibro::MetricResult &lt; Kalibro::Model @@ -19,7 +19,7 @@ class Kalibro::MetricResult &lt; Kalibro::Model
19 end 19 end
20 20
21 def range=(value) 21 def range=(value)
22 - @range = to_object(value, Kalibro::Range) 22 + @range = Kalibro::Range.to_object value
23 end 23 end
24 24
25 def descendent_result=(value) 25 def descendent_result=(value)
plugins/mezuro/lib/kalibro/model.rb
@@ -4,11 +4,11 @@ class Kalibro::Model @@ -4,11 +4,11 @@ class Kalibro::Model
4 attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) } 4 attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) }
5 end 5 end
6 6
7 - def to_hash # Convert an object into a hash 7 + def to_hash
8 hash = Hash.new 8 hash = Hash.new
9 fields.each do |field| 9 fields.each do |field|
10 field_value = send(field) 10 field_value = send(field)
11 - hash[field] = convert_to_hash(field_value) 11 + hash[field] = convert_to_hash(field_value) if ! field_value.nil?
12 if field_value.is_a?(Kalibro::Model) 12 if field_value.is_a?(Kalibro::Model)
13 hash = {:attributes! => {}}.merge(hash) 13 hash = {:attributes! => {}}.merge(hash)
14 hash[:attributes!][field.to_sym] = { 14 hash[:attributes!][field.to_sym] = {
@@ -18,7 +18,21 @@ class Kalibro::Model @@ -18,7 +18,21 @@ class Kalibro::Model
18 end 18 end
19 hash 19 hash
20 end 20 end
21 - 21 +
  22 + def self.request(endpoint, action, request_body = nil)
  23 + response = client(endpoint).request(:kalibro, action) { soap.body = request_body }
  24 + response.to_hash["#{action}_response".to_sym] # response is a Savon::SOAP::Response, and to_hash is a Savon::SOAP::Response method
  25 + end
  26 +
  27 + def self.to_objects_array value
  28 + array = value.kind_of?(Array) ? value : [value]
  29 + array.each.collect { |element| to_object(element) }
  30 + end
  31 +
  32 + def self.to_object value
  33 + value.kind_of?(Hash) ? new(value) : value
  34 + end
  35 +
22 protected 36 protected
23 37
24 def fields 38 def fields
@@ -29,13 +43,14 @@ class Kalibro::Model @@ -29,13 +43,14 @@ class Kalibro::Model
29 return value if value.nil? 43 return value if value.nil?
30 return value.collect { |element| convert_to_hash(element) } if value.is_a?(Array) 44 return value.collect { |element| convert_to_hash(element) } if value.is_a?(Array)
31 return value.to_hash if value.is_a?(Kalibro::Model) 45 return value.to_hash if value.is_a?(Kalibro::Model)
  46 + return self.class.date_with_milliseconds(value) if value.is_a?(DateTime)
32 return 'INF' if value.is_a?(Float) and value.infinite? == 1 47 return 'INF' if value.is_a?(Float) and value.infinite? == 1
33 return '-INF' if value.is_a?(Float) and value.infinite? == -1 48 return '-INF' if value.is_a?(Float) and value.infinite? == -1
34 value 49 value
35 end 50 end
36 51
37 - def xml_class_name(entity)  
38 - xml_name = entity.class.name 52 + def xml_class_name(object)
  53 + xml_name = object.class.name
39 xml_name["Kalibro::"] = "" 54 xml_name["Kalibro::"] = ""
40 xml_name[0..0] = xml_name[0..0].downcase 55 xml_name[0..0] = xml_name[0..0].downcase
41 xml_name + "Xml" 56 xml_name + "Xml"
@@ -46,24 +61,8 @@ class Kalibro::Model @@ -46,24 +61,8 @@ class Kalibro::Model
46 Savon::Client.new("#{service_address}#{endpoint}Endpoint/?wsdl") 61 Savon::Client.new("#{service_address}#{endpoint}Endpoint/?wsdl")
47 end 62 end
48 63
49 -  
50 def self.is_valid?(field) 64 def self.is_valid?(field)
51 field.to_s[0] != '@' and field != :attributes! and (field.to_s =~ /xsi/).nil? 65 field.to_s[0] != '@' and field != :attributes! and (field.to_s =~ /xsi/).nil?
52 end 66 end
53 67
54 - def self.request(endpoint, action, request_body = nil)  
55 - response = client(endpoint).request(:kalibro, action) { soap.body = request_body }  
56 - response.to_hash["#{action}_response".to_sym] # response is a Savon::SOAP::Response, and to_hash is a Savon::SOAP::Response method  
57 - end  
58 -  
59 - def to_objects_array(value, model_class = nil)  
60 - array = value.kind_of?(Array) ? value : [value]  
61 - array.each.collect { |element| to_object(element, model_class) }  
62 - end  
63 -  
64 - def to_object(value, model_class)  
65 - value.kind_of?(Hash) ? model_class.new(value) : value  
66 - end  
67 -  
68 end 68 end
69 -  
plugins/mezuro/lib/kalibro/module.rb 0 → 100644
@@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
  1 +class Kalibro::Module < Kalibro::Model
  2 +
  3 + attr_accessor :name, :granularity
  4 +
  5 + def self.parent_names(name)
  6 + path = []
  7 + ancestors = []
  8 + name.split(".").each do |token|
  9 + path << token
  10 + ancestors << path.join(".")
  11 + end
  12 + ancestors
  13 + end
  14 +
  15 + def ancestor_names
  16 + self.class.parent_names(@name)
  17 + end
  18 +end
plugins/mezuro/lib/kalibro/module_result.rb
@@ -22,11 +22,11 @@ class Kalibro::ModuleResult &lt; Kalibro::Model @@ -22,11 +22,11 @@ class Kalibro::ModuleResult &lt; Kalibro::Model
22 :project_name => project_name, 22 :project_name => project_name,
23 :module_name => module_name, 23 :module_name => module_name,
24 })[:module_result] 24 })[:module_result]
25 - to_objects_array(response) 25 + Kalibro::ModuleResult.to_objects_array(response)
26 end 26 end
27 27
28 def module=(value) 28 def module=(value)
29 - @module = to_object(value, Kalibro::Module) 29 + @module = Kalibro::Module.to_object value
30 end 30 end
31 31
32 def date=(value) 32 def date=(value)
@@ -38,9 +38,29 @@ class Kalibro::ModuleResult &lt; Kalibro::Model @@ -38,9 +38,29 @@ class Kalibro::ModuleResult &lt; Kalibro::Model
38 end 38 end
39 39
40 def metric_result=(value) 40 def metric_result=(value)
41 - @metric_result = to_objects_array(value, Kalibro::MetricResult) 41 + @metric_result = Kalibro::MetricResult.to_objects_array value
42 end 42 end
43 43
  44 + def metric_results
  45 + @metric_result
  46 + end
  47 +
  48 + def metric_results=(metric_results)
  49 + @metric_result = metric_results
  50 + end
  51 +
  52 + def compound_metric_with_error=(value)
  53 + @compound_metric_with_error = Kalibro::CompoundMetricWithError.to_objects_array value
  54 + end
  55 +
  56 + def compound_metrics_with_error
  57 + @compound_metric_with_error
  58 + end
  59 +
  60 + def compound_metrics_with_error=(compound_metrics_with_error)
  61 + @compound_metric_with_error = compound_metrics_with_error
  62 + end
  63 +
44 private 64 private
45 65
46 def self.date_with_milliseconds(date) 66 def self.date_with_milliseconds(date)
@@ -48,5 +68,4 @@ class Kalibro::ModuleResult &lt; Kalibro::Model @@ -48,5 +68,4 @@ class Kalibro::ModuleResult &lt; Kalibro::Model
48 date.to_s[0..18] + milliseconds + date.to_s[19..-1] 68 date.to_s[0..18] + milliseconds + date.to_s[19..-1]
49 end 69 end
50 70
51 -  
52 end 71 end
plugins/mezuro/lib/kalibro/native_metric.rb
@@ -11,7 +11,7 @@ class Kalibro::NativeMetric &lt; Kalibro::Metric @@ -11,7 +11,7 @@ class Kalibro::NativeMetric &lt; Kalibro::Metric
11 end 11 end
12 12
13 def language=(value) 13 def language=(value)
14 - @language = to_objects_array(value) 14 + @language = Kalibro::Model.to_objects_array value
15 end 15 end
16 16
17 end 17 end
plugins/mezuro/lib/kalibro/project.rb
@@ -37,7 +37,7 @@ class Kalibro::Project &lt; Kalibro::Model @@ -37,7 +37,7 @@ class Kalibro::Project &lt; Kalibro::Model
37 end 37 end
38 38
39 def repository=(value) 39 def repository=(value)
40 - @repository = to_object(value, Kalibro::Repository) 40 + @repository = Kalibro::Repository.to_object value
41 end 41 end
42 42
43 end 43 end
plugins/mezuro/lib/kalibro/stack_trace_element.rb 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +class Kalibro::StackTraceElement < Kalibro::Model
  2 +
  3 + attr_accessor :declaring_class, :method_name, :file_name, :line_number
  4 +
  5 + def line_number=(value)
  6 + @line_number = value.to_i
  7 + end
  8 +
  9 +end
plugins/mezuro/test/fixtures/compound_metric_with_error_fixtures.rb
1 require File.dirname(__FILE__) + '/error_fixtures' 1 require File.dirname(__FILE__) + '/error_fixtures'
  2 +require File.dirname(__FILE__) + '/compound_metric_fixtures'
2 3
3 class CompoundMetricWithErrorFixtures 4 class CompoundMetricWithErrorFixtures
4 5
5 - def self.create  
6 - fixture = Kalibro::Entities::CompoundMetricWithError.new  
7 - fixture.metric = CompoundMetricFixtures.compound_metric  
8 - fixture.error = ErrorFixtures.create  
9 - fixture 6 + def self.compound_metric_with_error
  7 + Kalibro::CompoundMetricWithError.new compound_metric_with_error_hash
10 end 8 end
11 9
12 - def self.create_hash  
13 - {:metric => CompoundMetricFixtures.compound_metric_hash, :error => ErrorFixtures.create_hash, 10 + def self.compound_metric_with_error_hash
  11 + {:metric => CompoundMetricFixtures.compound_metric_hash, :error => ErrorFixtures.error_hash,
14 :attributes! => {:metric => { 12 :attributes! => {:metric => {
15 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', 13 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
16 - 'xsi:type' => 'kalibro:compoundMetricXml' }}} 14 + 'xsi:type' => 'kalibro:compoundMetricXml' },
  15 + :error => {
  16 + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
  17 + 'xsi:type' => 'kalibro:errorXml' }}}
17 end 18 end
18 19
19 end 20 end
plugins/mezuro/test/fixtures/error_fixtures.rb
@@ -2,21 +2,19 @@ require File.dirname(__FILE__) + &#39;/stack_trace_element_fixtures&#39; @@ -2,21 +2,19 @@ require File.dirname(__FILE__) + &#39;/stack_trace_element_fixtures&#39;
2 2
3 class ErrorFixtures 3 class ErrorFixtures
4 4
5 - def self.create  
6 - error = Kalibro::Entities::Error.new  
7 - error.error_class = 'java.lang.Exception'  
8 - error.message = 'Error message from ErrorTest'  
9 - error.stack_trace = [  
10 - StackTraceElementFixtures.create('my method 1', 42),  
11 - StackTraceElementFixtures.create('my method 2', 84)]  
12 - error 5 + def self.error
  6 + Kalibro::Error.new error_hash
13 end 7 end
14 8
15 - def self.create_hash  
16 - {:error_class => 'java.lang.Exception', :message => 'Error message from ErrorTest', 9 + def self.error_hash
  10 + {
  11 + :error_class => 'java.lang.Exception',
  12 + :message => 'Error message from ErrorTest',
17 :stack_trace_element => [ 13 :stack_trace_element => [
18 - StackTraceElementFixtures.create_hash('my method 1', 42),  
19 - StackTraceElementFixtures.create_hash('my method 2', 84)]} 14 + StackTraceElementFixtures.stack_trace_element_hash('my method 1', 42),
  15 + StackTraceElementFixtures.stack_trace_element_hash('my method 2', 84)
  16 + ]
  17 + }
20 end 18 end
21 19
22 end 20 end
plugins/mezuro/test/fixtures/metric_result_fixtures.rb
@@ -4,27 +4,42 @@ require File.dirname(__FILE__) + &#39;/range_fixtures&#39; @@ -4,27 +4,42 @@ require File.dirname(__FILE__) + &#39;/range_fixtures&#39;
4 4
5 class MetricResultFixtures 5 class MetricResultFixtures
6 6
7 - def self.native_metric  
8 - Kalibro::MetricResult.new( native_metric_hash ) 7 + def self.native_metric_result
  8 + Kalibro::MetricResult.new native_metric_result_hash
9 end 9 end
10 10
11 - def self.compound_metric  
12 - Kalibro::MetricResult.new( compound_metric_hash ) 11 + def self.compound_metric_result
  12 + Kalibro::MetricResult.new compound_metric_result_hash
13 end 13 end
14 14
15 - def self.native_metric_hash  
16 - {:metric => NativeMetricFixtures.amloc_hash, :value => 0.0, :descendent_result => [40.0, 42.0], 15 + def self.native_metric_result_hash
  16 + {
  17 + :metric => NativeMetricFixtures.amloc_hash,
  18 + :value => 0.0,
  19 + :descendent_result => [40.0, 42.0],
17 :range => RangeFixtures.range_excellent_hash, 20 :range => RangeFixtures.range_excellent_hash,
18 - :attributes! => {:metric => { 21 + :attributes! => {
  22 + :metric => {
19 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', 23 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
20 - 'xsi:type' => 'kalibro:nativeMetricXml' }}} 24 + 'xsi:type' => 'kalibro:nativeMetricXml' },
  25 + :range => {
  26 + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
  27 + 'xsi:type' => 'kalibro:rangeXml' }
  28 + }
  29 + }
21 end 30 end
22 31
23 - def self.compound_metric_hash  
24 - {:metric => CompoundMetricFixtures.compound_metric_hash, :value => 1.0, :descendent_result => [2.0, 42.0],  
25 - :attributes! => {:metric => { 32 + def self.compound_metric_result_hash
  33 + {
  34 + :metric => CompoundMetricFixtures.compound_metric_hash,
  35 + :value => 1.0,
  36 + :descendent_result => [2.0, 42.0],
  37 + :attributes! => {
  38 + :metric => {
26 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', 39 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
27 - 'xsi:type' => 'kalibro:compoundMetricXml' }}} 40 + 'xsi:type' => 'kalibro:compoundMetricXml' }
  41 + }
  42 + }
28 end 43 end
29 44
30 end 45 end
plugins/mezuro/test/fixtures/module_fixtures.rb
1 class ModuleFixtures 1 class ModuleFixtures
2 2
3 - def self.qt_calculator  
4 - entity = Kalibro::Entities::Module.new  
5 - entity.name = 'Qt-Calculator'  
6 - entity.granularity = 'APPLICATION'  
7 - entity 3 + def self.module
  4 + entity = Kalibro::Module.new module_hash
8 end 5 end
9 6
10 - def self.qt_calculator_hash 7 + def self.module_hash
11 {:name => 'Qt-Calculator', :granularity => 'APPLICATION'} 8 {:name => 'Qt-Calculator', :granularity => 'APPLICATION'}
12 end 9 end
13 10
plugins/mezuro/test/fixtures/module_result_fixtures.rb
@@ -5,18 +5,23 @@ require File.dirname(__FILE__) + &#39;/compound_metric_with_error_fixtures&#39; @@ -5,18 +5,23 @@ require File.dirname(__FILE__) + &#39;/compound_metric_with_error_fixtures&#39;
5 class ModuleResultFixtures 5 class ModuleResultFixtures
6 6
7 def self.module_result 7 def self.module_result
8 - Kalibro::ModuleResult.new( module_result_hash ) 8 + Kalibro::ModuleResult.new module_result_hash
9 end 9 end
10 10
11 def self.module_result_hash 11 def self.module_result_hash
12 { 12 {
13 - :module => ModuleFixtures.qt_calculator_hash, 13 + :module => ModuleFixtures.module_hash,
14 :date => '2011-10-20T18:26:43.151+00:00', 14 :date => '2011-10-20T18:26:43.151+00:00',
15 :grade => 10.0, 15 :grade => 10.0,
16 :metric_result => [ 16 :metric_result => [
17 - MetricResultFixtures.native_metric_hash,  
18 - MetricResultFixtures.compound_metric_hash],  
19 - :compound_metric_with_error => [CompoundMetricWithErrorFixtures.create_hash] 17 + MetricResultFixtures.native_metric_result_hash,
  18 + MetricResultFixtures.compound_metric_result_hash],
  19 + :compound_metric_with_error => [CompoundMetricWithErrorFixtures.compound_metric_with_error_hash],
  20 + :attributes! => {
  21 + :module => {
  22 + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
  23 + 'xsi:type' => 'kalibro:moduleXml' }
  24 + }
20 } 25 }
21 end 26 end
22 27
plugins/mezuro/test/fixtures/stack_trace_element_fixtures.rb
1 class StackTraceElementFixtures 1 class StackTraceElementFixtures
2 2
3 - def self.create(method_name = 'my method name', line_number = 42)  
4 - element = Kalibro::Entities::StackTraceElement.new  
5 - element.declaring_class = 'my.declaring.Class'  
6 - element.method_name = method_name  
7 - element.file_name = 'MyFile.java'  
8 - element.line_number = line_number  
9 - element 3 + def self.stack_trace_element(method_name = 'my method name', line_number = 42)
  4 + Kalibro::StackTraceElement.new stack_trace_element_hash(method_name, line_number)
10 end 5 end
11 6
12 - def self.create_hash(method_name = 'my method name', line_number = 42)  
13 - {:declaring_class => 'my.declaring.Class', :method_name => method_name, :file_name => 'MyFile.java',  
14 - :line_number => line_number} 7 + def self.stack_trace_element_hash(method_name = 'my method name', line_number = 42)
  8 + {
  9 + :declaring_class => 'my.declaring.Class',
  10 + :method_name => method_name,
  11 + :file_name => 'MyFile.java',
  12 + :line_number => line_number
  13 + }
15 end 14 end
16 15
17 end 16 end
plugins/mezuro/test/unit/kalibro/client/module_result_client_test.rb
@@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
1 -require "test_helper"  
2 -  
3 -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures"  
4 -  
5 -class ModuleResultClientTest < ActiveSupport::TestCase  
6 -  
7 - def setup  
8 - @port = mock  
9 - Kalibro::Client::Port.expects(:new).with('ModuleResult').returns(@port)  
10 - @client = Kalibro::Client::ModuleResultClient.new  
11 - @result = ModuleResultFixtures.create  
12 - end  
13 -  
14 - should 'get module result' do  
15 - date_string = '2012-01-10T16:07:15.442-02:00'  
16 - date = DateTime.parse(date_string)  
17 - request_body = {:project_name => 'Qt-Calculator', :module_name => 'main', :date => date_string}  
18 - response = {:module_result => @result.to_hash}  
19 - @port.expects(:request).with(:get_module_result, request_body).returns(response)  
20 - assert_equal @result, @client.module_result('Qt-Calculator', 'main', date)  
21 - end  
22 -  
23 - should 'get result history' do  
24 - request_body = {:project_name => 'Qt-Calculator', :module_name => 'main'}  
25 - response = {:module_result => @result.to_hash}  
26 - @port.expects(:request).with(:get_result_history, request_body).returns(response)  
27 - assert_equal [@result], @client.result_history('Qt-Calculator', 'main')  
28 - end  
29 -end  
plugins/mezuro/test/unit/kalibro/compound_metric_with_error_test.rb 0 → 100644
@@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
  1 +require "test_helper"
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/compound_metric_with_error_fixtures"
  4 +
  5 +class CompoundMetricWithErrorTest < ActiveSupport::TestCase
  6 +
  7 + def setup
  8 + @hash = CompoundMetricWithErrorFixtures.compound_metric_with_error_hash
  9 + @compound_metric_with_error = CompoundMetricWithErrorFixtures.compound_metric_with_error
  10 + end
  11 +
  12 + should 'create error from hash' do
  13 + assert_equal @hash[:error][:message], Kalibro::CompoundMetricWithError.new(@hash).error.message
  14 + end
  15 +
  16 + should 'convert error to hash' do
  17 + assert_equal @hash, @compound_metric_with_error.to_hash
  18 + end
  19 +
  20 +end
plugins/mezuro/test/unit/kalibro/entities/compound_metric_with_error_test.rb
@@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
1 -require "test_helper"  
2 -  
3 -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/compound_metric_with_error_fixtures"  
4 -  
5 -class CompoundMetricWithErrorTest < ActiveSupport::TestCase  
6 -  
7 - def setup  
8 - @hash = CompoundMetricWithErrorFixtures.create_hash  
9 - @entity = CompoundMetricWithErrorFixtures.create  
10 - end  
11 -  
12 - should 'create error from hash' do  
13 - assert_equal @entity, Kalibro::Entities::CompoundMetricWithError.from_hash(@hash)  
14 - end  
15 -  
16 - should 'convert error to hash' do  
17 - assert_equal @hash, @entity.to_hash  
18 - end  
19 -  
20 -end  
plugins/mezuro/test/unit/kalibro/entities/error_test.rb
@@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
1 -require "test_helper"  
2 -  
3 -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/error_fixtures"  
4 -  
5 -class ErrorTest < ActiveSupport::TestCase  
6 -  
7 - def setup  
8 - @hash = ErrorFixtures.create_hash  
9 - @error = ErrorFixtures.create  
10 - end  
11 -  
12 - should 'create error from hash' do  
13 - assert_equal @error, Kalibro::Entities::Error.from_hash(@hash)  
14 - end  
15 -  
16 - should 'convert error to hash' do  
17 - assert_equal @hash, @error.to_hash  
18 - end  
19 -  
20 -end  
21 \ No newline at end of file 0 \ No newline at end of file
plugins/mezuro/test/unit/kalibro/entities/metric_result_test.rb
@@ -1,30 +0,0 @@ @@ -1,30 +0,0 @@
1 -require "test_helper"  
2 -  
3 -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_result_fixtures"  
4 -  
5 -class MetricResultTest < ActiveSupport::TestCase  
6 -  
7 - def setup  
8 - @hash = MetricResultFixtures.amloc_result_hash  
9 - @result = MetricResultFixtures.amloc_result  
10 - end  
11 -  
12 - should 'create metric result from hash' do  
13 - assert_equal @result, Kalibro::Entities::MetricResult.from_hash(@hash)  
14 - end  
15 -  
16 - should 'convert metric result to hash' do  
17 - assert_equal @hash, @result.to_hash  
18 - end  
19 -  
20 - should 'create appropriate metric type' do  
21 - assert MetricResultFixtures.amloc_result.metric.instance_of?(Kalibro::Entities::NativeMetric)  
22 - assert MetricResultFixtures.sc_result.metric.instance_of?(Kalibro::Entities::CompoundMetric)  
23 - end  
24 -  
25 - should 'convert single descendent result to array' do  
26 - @result.descendent_result = 1  
27 - assert_equal [1], @result.descendent_results  
28 - end  
29 -  
30 -end  
31 \ No newline at end of file 0 \ No newline at end of file
plugins/mezuro/test/unit/kalibro/entities/module_result_test.rb
@@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
1 -require "test_helper"  
2 -  
3 -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures"  
4 -  
5 -class ModuleResultTest < ActiveSupport::TestCase  
6 -  
7 - def setup  
8 - @hash = ModuleResultFixtures.module_result_hash  
9 - @result = ModuleResultFixtures.module_result  
10 - end  
11 -  
12 - should 'create module result from hash' do  
13 - assert_equal @result, Kalibro::Entities::ModuleResult.from_hash(@hash)  
14 - end  
15 -  
16 - should 'convert module result to hash' do  
17 - assert_equal @hash, Kalibro::Entities::ModuleResult.to_hash(@result)  
18 - end  
19 -  
20 -end  
plugins/mezuro/test/unit/kalibro/entities/module_test.rb
@@ -1,30 +0,0 @@ @@ -1,30 +0,0 @@
1 -require "test_helper"  
2 -  
3 -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_fixtures"  
4 -  
5 -class ModuleTest < ActiveSupport::TestCase  
6 -  
7 - def setup  
8 - @hash = ModuleFixtures.qt_calculator_hash  
9 - @module = ModuleFixtures.qt_calculator  
10 - end  
11 -  
12 - should 'create module from hash' do  
13 - assert_equal @module, Kalibro::Entities::Module.from_hash(@hash)  
14 - end  
15 -  
16 - should 'convert module to hash' do  
17 - assert_equal @hash, @module.to_hash  
18 - end  
19 -  
20 - should 'list ancestor names' do  
21 - @module.name = "org.kalibro.core"  
22 - assert_equal ["org", "org.kalibro", "org.kalibro.core"], @module.ancestor_names  
23 - end  
24 -  
25 - should 'list ancestor with one name' do  
26 - @module.name = "org"  
27 - assert_equal ["org"], @module.ancestor_names  
28 - end  
29 -  
30 -end  
plugins/mezuro/test/unit/kalibro/entities/stack_trace_element_test.rb
@@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
1 -require "test_helper"  
2 -  
3 -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/stack_trace_element_fixtures"  
4 -  
5 -class StackTraceElementTest < ActiveSupport::TestCase  
6 -  
7 - def setup  
8 - @hash = StackTraceElementFixtures.create_hash  
9 - @stack_trace_element = StackTraceElementFixtures.create  
10 - end  
11 -  
12 - should 'create stack trace element from hash' do  
13 - assert_equal @stack_trace_element, Kalibro::Entities::StackTraceElement.from_hash(@hash)  
14 - end  
15 -  
16 - should 'convert stack trace element to hash' do  
17 - assert_equal @hash, @stack_trace_element.to_hash  
18 - end  
19 -  
20 -end  
plugins/mezuro/test/unit/kalibro/error_test.rb 0 → 100644
@@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
  1 +require "test_helper"
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/error_fixtures"
  4 +
  5 +class ErrorTest < ActiveSupport::TestCase
  6 +
  7 + def setup
  8 + @hash = ErrorFixtures.error_hash
  9 + @error = ErrorFixtures.error
  10 + end
  11 +
  12 + should 'create error from hash' do
  13 + assert_equal @hash[:message], Kalibro::Error.new(@hash).message
  14 + end
  15 +
  16 + should 'convert error to hash' do
  17 + assert_equal @hash, @error.to_hash
  18 + end
  19 +
  20 +end
plugins/mezuro/test/unit/kalibro/metric_result_test.rb 0 → 100644
@@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
  1 +require "test_helper"
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_result_fixtures"
  4 +
  5 +class MetricResultTest < ActiveSupport::TestCase
  6 +
  7 + def setup
  8 + @hash = MetricResultFixtures.native_metric_result_hash
  9 + @result = MetricResultFixtures.native_metric_result
  10 + end
  11 +
  12 + should 'create metric result from hash' do
  13 + assert_equal @hash[:metric][:name], Kalibro::MetricResult.new(@hash).metric.name
  14 + end
  15 +
  16 + should 'convert metric result to hash' do
  17 + assert_equal @hash, @result.to_hash
  18 + end
  19 +
  20 + should 'create appropriate metric type' do
  21 + assert MetricResultFixtures.native_metric_result.metric.instance_of?(Kalibro::NativeMetric)
  22 + assert MetricResultFixtures.compound_metric_result.metric.instance_of?(Kalibro::CompoundMetric)
  23 + end
  24 +
  25 + should 'convert single descendent result to array' do
  26 + @result.descendent_result = 1
  27 + assert_equal [1], @result.descendent_results
  28 + end
  29 +
  30 +end
plugins/mezuro/test/unit/kalibro/module_result_test.rb
@@ -17,19 +17,20 @@ class ModuleResultTest &lt; ActiveSupport::TestCase @@ -17,19 +17,20 @@ class ModuleResultTest &lt; ActiveSupport::TestCase
17 end 17 end
18 18
19 should 'find module result' do 19 should 'find module result' do
20 - date_string = '2012-01-10T16:07:15.442-02:00'  
21 - date = DateTime.parse(date_string)  
22 - request_body = {:project_name => 'Qt-Calculator', :module_name => 'main', :date => date_string} 20 + date = DateTime.parse(@module_result.date.to_s)
  21 + name = @module_result.module.name
  22 + request_body = {:project_name => name, :module_name => name, :date => '2011-10-20T18:26:43.0+00:00'}
23 response = {:module_result => @hash} 23 response = {:module_result => @hash}
24 Kalibro::ModuleResult.expects(:request).with('ModuleResult',:get_module_result, request_body).returns(response) 24 Kalibro::ModuleResult.expects(:request).with('ModuleResult',:get_module_result, request_body).returns(response)
25 - assert_equal @module_result.grade, Kalibro::ModuleResult.find_by_project_name_and_module_name_and_date('Qt-Calculator', 'main', date).grade 25 + assert_equal @module_result.grade, Kalibro::ModuleResult.find_by_project_name_and_module_name_and_date(name, name, date).grade
26 end 26 end
27 27
28 should 'find all module results' do 28 should 'find all module results' do
29 - request_body = {:project_name => 'Qt-Calculator', :module_name => 'main'} 29 + name = @module_result.module.name
  30 + request_body = {:project_name => name, :module_name => name}
30 response = {:module_result => @hash} 31 response = {:module_result => @hash}
31 Kalibro::ModuleResult.expects(:request).with('ModuleResult',:get_result_history, request_body).returns(response) 32 Kalibro::ModuleResult.expects(:request).with('ModuleResult',:get_result_history, request_body).returns(response)
32 - response_array = Kalibro::ModuleResult.all_by_project_name_and_module_name('Qt-Calculator', 'main') 33 + response_array = Kalibro::ModuleResult.all_by_project_name_and_module_name(name, name)
33 assert_equal [@module_result].class, response_array.class 34 assert_equal [@module_result].class, response_array.class
34 assert_equal @module_result.grade, response_array[0].grade 35 assert_equal @module_result.grade, response_array[0].grade
35 end 36 end
plugins/mezuro/test/unit/kalibro/module_test.rb 0 → 100644
@@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
  1 +require "test_helper"
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_fixtures"
  4 +
  5 +class ModuleTest < ActiveSupport::TestCase
  6 +
  7 + def setup
  8 + @hash = ModuleFixtures.module_hash
  9 + @module = ModuleFixtures.module
  10 + end
  11 +
  12 + should 'create module from hash' do
  13 + assert_equal @hash[:name], Kalibro::Module.new(@hash).name
  14 + end
  15 +
  16 + should 'convert module to hash' do
  17 + assert_equal @hash, @module.to_hash
  18 + end
  19 +
  20 + should 'list ancestor names' do
  21 + @module.name = "org.kalibro.core"
  22 + assert_equal ["org", "org.kalibro", "org.kalibro.core"], @module.ancestor_names
  23 + end
  24 +
  25 + should 'list ancestor with one name' do
  26 + @module.name = "org"
  27 + assert_equal ["org"], @module.ancestor_names
  28 + end
  29 +
  30 +end
plugins/mezuro/test/unit/kalibro/stack_trace_element_test.rb 0 → 100644
@@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
  1 +require "test_helper"
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/stack_trace_element_fixtures"
  4 +
  5 +class StackTraceElementTest < ActiveSupport::TestCase
  6 +
  7 + def setup
  8 + @hash = StackTraceElementFixtures.stack_trace_element_hash
  9 + @stack_trace_element = StackTraceElementFixtures.stack_trace_element
  10 + end
  11 +
  12 + should 'create stack trace element from hash' do
  13 + assert_equal @hash[:method_name], Kalibro::StackTraceElement.new(@hash).method_name
  14 + end
  15 +
  16 + should 'convert stack trace element to hash' do
  17 + assert_equal @hash, @stack_trace_element.to_hash
  18 + end
  19 +
  20 +end
plugins/mezuro/test/unit/mezuro_plugin/helpers/content_viewer_helper_test.rb
@@ -14,7 +14,7 @@ class ContentViewerHelperTest &lt; ActiveSupport::TestCase @@ -14,7 +14,7 @@ class ContentViewerHelperTest &lt; ActiveSupport::TestCase
14 end 14 end
15 15
16 should 'format metric name for module result' do 16 should 'format metric name for module result' do
17 - metric_result = MetricResultFixtures.amloc_result 17 + metric_result = MetricResultFixtures.native_metric_result
18 assert_equal 'AverageMethodLOC', MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) 18 assert_equal 'AverageMethodLOC', MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result)
19 end 19 end
20 end 20 end