Commit 0d44cd8b217da7ba0f7720b2e0607839e2cc6090
Committed by
Paulo Meireles
1 parent
140932c0
Exists in
master
and in
29 other branches
[Mezuro] fixed fixtures and moved files
Showing
15 changed files
with
207 additions
and
340 deletions
Show diff stats
plugins/mezuro/lib/kalibro/client/project_result_client.rb
@@ -1,46 +0,0 @@ | @@ -1,46 +0,0 @@ | ||
1 | -class Kalibro::Client::ProjectResultClient | ||
2 | - | ||
3 | - # TODO test this | ||
4 | - def self.last_result(project_name) | ||
5 | - new.last_result(project_name) | ||
6 | - end | ||
7 | - | ||
8 | - def initialize | ||
9 | - @port = Kalibro::Client::Port.new('ProjectResult') | ||
10 | - end | ||
11 | - | ||
12 | - def has_results_for(project_name) | ||
13 | - @port.request(:has_results_for, {:project_name => project_name})[:has_results] | ||
14 | - end | ||
15 | - | ||
16 | - def has_results_before(project_name, date) | ||
17 | - @port.request(:has_results_before, {:project_name => project_name, :date => date})[:has_results] | ||
18 | - end | ||
19 | - | ||
20 | - def has_results_after(project_name, date) | ||
21 | - @port.request(:has_results_after, {:project_name => project_name, :date => date})[:has_results] | ||
22 | - end | ||
23 | - | ||
24 | - def first_result(project_name) | ||
25 | - hash = @port.request(:get_first_result_of, {:project_name => project_name})[:project_result] | ||
26 | - Kalibro::Entities::ProjectResult.from_hash(hash) | ||
27 | - end | ||
28 | - | ||
29 | - def last_result(project_name) | ||
30 | - hash = @port.request(:get_last_result_of, {:project_name => project_name})[:project_result] | ||
31 | - Kalibro::Entities::ProjectResult.from_hash(hash) | ||
32 | - end | ||
33 | - | ||
34 | - def first_result_after(project_name, date) | ||
35 | - request_body = {:project_name => project_name, :date => date} | ||
36 | - hash = @port.request(:get_first_result_after, request_body)[:project_result] | ||
37 | - Kalibro::Entities::ProjectResult.from_hash(hash) | ||
38 | - end | ||
39 | - | ||
40 | - def last_result_before(project_name, date) | ||
41 | - request_body = {:project_name => project_name, :date => date} | ||
42 | - hash = @port.request(:get_last_result_before, request_body)[:project_result] | ||
43 | - Kalibro::Entities::ProjectResult.from_hash(hash) | ||
44 | - end | ||
45 | - | ||
46 | -end | ||
47 | \ No newline at end of file | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/module_node.rb
@@ -1,21 +0,0 @@ | @@ -1,21 +0,0 @@ | ||
1 | -class Kalibro::Entities::ModuleNode < Kalibro::Entities::Entity | ||
2 | - | ||
3 | - attr_accessor :module, :child | ||
4 | - | ||
5 | - def module=(value) | ||
6 | - @module = to_entity(value, Kalibro::Entities::Module) | ||
7 | - end | ||
8 | - | ||
9 | - def child=(value) | ||
10 | - @child = to_entity_array(value, Kalibro::Entities::ModuleNode) | ||
11 | - end | ||
12 | - | ||
13 | - def children | ||
14 | - @child | ||
15 | - end | ||
16 | - | ||
17 | - def children=(children) | ||
18 | - @child = children | ||
19 | - end | ||
20 | - | ||
21 | -end |
plugins/mezuro/lib/kalibro/entities/project_result.rb
@@ -1,76 +0,0 @@ | @@ -1,76 +0,0 @@ | ||
1 | -class Kalibro::Entities::ProjectResult < Kalibro::Entities::Entity | ||
2 | - | ||
3 | - attr_accessor :project, :date, :load_time, :analysis_time, :source_tree, :collect_time | ||
4 | - | ||
5 | - def project=(value) | ||
6 | - @project = to_entity(value, Kalibro::Entities::Project) | ||
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 load_time=(value) | ||
15 | - @load_time = value.to_i | ||
16 | - end | ||
17 | - | ||
18 | - def collect_time=(value) | ||
19 | - @collect_time = value.to_i | ||
20 | - end | ||
21 | - | ||
22 | - def analysis_time=(value) | ||
23 | - @analysis_time = value.to_i | ||
24 | - end | ||
25 | - | ||
26 | - def source_tree=(value) | ||
27 | - @source_tree = to_entity(value, Kalibro::Entities::ModuleNode) | ||
28 | - end | ||
29 | - | ||
30 | - def formatted_load_time | ||
31 | - format_milliseconds(@load_time) | ||
32 | - end | ||
33 | - | ||
34 | - def formatted_analysis_time | ||
35 | - format_milliseconds(@analysis_time) | ||
36 | - end | ||
37 | - | ||
38 | - def format_milliseconds(value) | ||
39 | - seconds = value.to_i/1000 | ||
40 | - hours = seconds/3600 | ||
41 | - seconds -= hours * 3600 | ||
42 | - minutes = seconds/60 | ||
43 | - seconds -= minutes * 60 | ||
44 | - "#{format(hours)}:#{format(minutes)}:#{format(seconds)}" | ||
45 | - end | ||
46 | - | ||
47 | - def format(amount) | ||
48 | - ('%2d' % amount).sub(/\s/, '0') | ||
49 | - end | ||
50 | - | ||
51 | - def node_of(module_name) | ||
52 | - if module_name.nil? or module_name == project.name | ||
53 | - node = source_tree | ||
54 | - else | ||
55 | - node = get_node(module_name) | ||
56 | - end | ||
57 | - end | ||
58 | - | ||
59 | - def get_node(module_name) | ||
60 | - path = Kalibro::Entities::Module.parent_names(module_name) | ||
61 | - parent = @source_tree | ||
62 | - path.each do |node_name| | ||
63 | - parent = get_leaf_from(parent, node_name) | ||
64 | - end | ||
65 | - return parent | ||
66 | - end | ||
67 | - | ||
68 | - private | ||
69 | - def get_leaf_from(node, module_name) | ||
70 | - node.children.each do |child_node| | ||
71 | - return child_node if child_node.module.name == module_name | ||
72 | - end | ||
73 | - nil | ||
74 | - end | ||
75 | - | ||
76 | -end |
plugins/mezuro/lib/kalibro/model.rb
@@ -64,5 +64,10 @@ class Kalibro::Model | @@ -64,5 +64,10 @@ class Kalibro::Model | ||
64 | def self.is_valid?(field) | 64 | def self.is_valid?(field) |
65 | 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? |
66 | end | 66 | end |
67 | + | ||
68 | + def self.date_with_milliseconds(date) | ||
69 | + milliseconds = "." + (date.sec_fraction * 60 * 60 * 24 * 1000).to_s | ||
70 | + date.to_s[0..18] + milliseconds + date.to_s[19..-1] | ||
71 | + end | ||
67 | 72 | ||
68 | end | 73 | end |
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +class Kalibro::ModuleNode < Kalibro::Model | ||
2 | + | ||
3 | + attr_accessor :module, :child | ||
4 | + | ||
5 | + def module=(value) | ||
6 | + @module = Kalibro::Module.to_object value | ||
7 | + end | ||
8 | + | ||
9 | + def child=(value) | ||
10 | + @child = Kalibro::ModuleNode.to_objects_array value | ||
11 | + end | ||
12 | + | ||
13 | + def children | ||
14 | + @child | ||
15 | + end | ||
16 | + | ||
17 | + def children=(children) | ||
18 | + @child = children | ||
19 | + end | ||
20 | + | ||
21 | +end |
plugins/mezuro/lib/kalibro/module_result.rb
@@ -61,11 +61,4 @@ class Kalibro::ModuleResult < Kalibro::Model | @@ -61,11 +61,4 @@ class Kalibro::ModuleResult < Kalibro::Model | ||
61 | @compound_metric_with_error = compound_metrics_with_error | 61 | @compound_metric_with_error = compound_metrics_with_error |
62 | end | 62 | end |
63 | 63 | ||
64 | - private | ||
65 | - | ||
66 | - def self.date_with_milliseconds(date) | ||
67 | - milliseconds = "." + (date.sec_fraction * 60 * 60 * 24 * 1000).to_s | ||
68 | - date.to_s[0..18] + milliseconds + date.to_s[19..-1] | ||
69 | - end | ||
70 | - | ||
71 | end | 64 | end |
plugins/mezuro/lib/kalibro/project_result.rb
@@ -3,35 +3,35 @@ class Kalibro::ProjectResult < Kalibro::Model | @@ -3,35 +3,35 @@ class Kalibro::ProjectResult < Kalibro::Model | ||
3 | attr_accessor :project, :date, :load_time, :analysis_time, :source_tree, :collect_time | 3 | attr_accessor :project, :date, :load_time, :analysis_time, :source_tree, :collect_time |
4 | 4 | ||
5 | def self.last_result(project_name) | 5 | def self.last_result(project_name) |
6 | - last_result = request(:get_last_result_of, {:project_name => project_name})[:project_result] | 6 | + last_result = request('ProjectResult', :get_last_result_of, {:project_name => project_name})[:project_result] |
7 | new last_result | 7 | new last_result |
8 | end | 8 | end |
9 | 9 | ||
10 | def self.first_result(project_name) | 10 | def self.first_result(project_name) |
11 | - first_result = request(:get_first_result_of, {:project_name => project_name})[:project_result] | 11 | + first_result = request('ProjectResult',:get_first_result_of, {:project_name => project_name})[:project_result] |
12 | new first_result | 12 | new first_result |
13 | end | 13 | end |
14 | 14 | ||
15 | def self.first_result_after(project_name, date) | 15 | def self.first_result_after(project_name, date) |
16 | - first_result_after = request(:get_first_result_after, {:project_name => project_name, :date => date})[:project_result] | 16 | + first_result_after = request('ProjectResult',:get_first_result_after, {:project_name => project_name, :date => date})[:project_result] |
17 | new first_result_after | 17 | new first_result_after |
18 | end | 18 | end |
19 | 19 | ||
20 | def self.last_result_before(project_name, date) | 20 | def self.last_result_before(project_name, date) |
21 | - last_result_before = request(:get_last_result_before, {:project_name => project_name, :date => date})[:project_result] | 21 | + last_result_before = request('ProjectResult',:get_last_result_before, {:project_name => project_name, :date => date})[:project_result] |
22 | new last_result_before | 22 | new last_result_before |
23 | end | 23 | end |
24 | 24 | ||
25 | def self.has_results?(project_name) | 25 | def self.has_results?(project_name) |
26 | - request(:has_results_for, {:project_name => project_name})[:has_results] | 26 | + request('ProjectResult',:has_results_for, {:project_name => project_name})[:has_results] |
27 | end | 27 | end |
28 | 28 | ||
29 | def self.has_results_before?(project_name, date) | 29 | def self.has_results_before?(project_name, date) |
30 | - request(:has_results_before, {:project_name => project_name, :date => date})[:has_results] | 30 | + request('ProjectResult',:has_results_before, {:project_name => project_name, :date => date})[:has_results] |
31 | end | 31 | end |
32 | 32 | ||
33 | def self.has_results_after?(project_name, date) | 33 | def self.has_results_after?(project_name, date) |
34 | - request(:has_results_after, {:project_name => project_name, :date => date})[:has_results] | 34 | + request('ProjectResult',:has_results_after, {:project_name => project_name, :date => date})[:has_results] |
35 | end | 35 | end |
36 | 36 | ||
37 | def project=(value) | 37 | def project=(value) |
@@ -54,9 +54,8 @@ class Kalibro::ProjectResult < Kalibro::Model | @@ -54,9 +54,8 @@ class Kalibro::ProjectResult < Kalibro::Model | ||
54 | @analysis_time = value.to_i | 54 | @analysis_time = value.to_i |
55 | end | 55 | end |
56 | 56 | ||
57 | - #FIXME mudar a atribuição depois que refatorarmos o module_result client | ||
58 | def source_tree=(value) | 57 | def source_tree=(value) |
59 | - @source_tree = value.kind_of?(Hash) ? Kalibro::Entities::ModuleNode.from_hash(value) : value | 58 | + @source_tree = value.kind_of?(Hash) ? Kalibro::ModuleNode.new(value) : value |
60 | end | 59 | end |
61 | 60 | ||
62 | def formatted_load_time | 61 | def formatted_load_time |
@@ -88,9 +87,8 @@ class Kalibro::ProjectResult < Kalibro::Model | @@ -88,9 +87,8 @@ class Kalibro::ProjectResult < Kalibro::Model | ||
88 | end | 87 | end |
89 | end | 88 | end |
90 | 89 | ||
91 | -#FIXME mudar a atribuição depois que refatorarmos o module_result client | ||
92 | def get_node(module_name) | 90 | def get_node(module_name) |
93 | - path = Kalibro::Entities::Module.parent_names(module_name) | 91 | + path = Kalibro::Module.parent_names(module_name) |
94 | parent = @source_tree | 92 | parent = @source_tree |
95 | path.each do |node_name| | 93 | path.each do |node_name| |
96 | parent = get_leaf_from(parent, node_name) | 94 | parent = get_leaf_from(parent, node_name) |
@@ -100,17 +98,6 @@ class Kalibro::ProjectResult < Kalibro::Model | @@ -100,17 +98,6 @@ class Kalibro::ProjectResult < Kalibro::Model | ||
100 | 98 | ||
101 | private | 99 | private |
102 | 100 | ||
103 | - def self.project_result | ||
104 | - endpoint = "ProjectResult" | ||
105 | - service_address = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/service.yaml") | ||
106 | - Savon::Client.new("#{service_address}#{endpoint}Endpoint/?wsdl") | ||
107 | - end | ||
108 | - | ||
109 | - def self.request(action, request_body = nil) | ||
110 | - response = project_result.request(:kalibro, action) { soap.body = request_body } | ||
111 | - response.to_hash["#{action}_response".to_sym] | ||
112 | - end | ||
113 | - | ||
114 | def get_leaf_from(node, module_name) | 101 | def get_leaf_from(node, module_name) |
115 | node.children.each do |child_node| | 102 | node.children.each do |child_node| |
116 | return child_node if child_node.module.name == module_name | 103 | return child_node if child_node.module.name == module_name |
plugins/mezuro/test/fixtures/module_fixtures.rb
1 | class ModuleFixtures | 1 | class ModuleFixtures |
2 | 2 | ||
3 | def self.module | 3 | def self.module |
4 | - entity = Kalibro::Module.new module_hash | 4 | + Kalibro::Module.new module_hash |
5 | end | 5 | end |
6 | 6 | ||
7 | def self.module_hash | 7 | def self.module_hash |
8 | - {:name => 'Qt-Calculator', :granularity => 'APPLICATION'} | 8 | + { |
9 | + :name => 'Qt-Calculator', | ||
10 | + :granularity => 'APPLICATION' | ||
11 | + } | ||
9 | end | 12 | end |
10 | 13 | ||
11 | end | 14 | end |
plugins/mezuro/test/fixtures/module_node_fixtures.rb
1 | +require File.dirname(__FILE__) + '/module_fixtures' | ||
2 | + | ||
1 | class ModuleNodeFixtures | 3 | class ModuleNodeFixtures |
2 | 4 | ||
3 | - def self.qt_calculator_tree | ||
4 | - node = Kalibro::Entities::ModuleNode.new | ||
5 | - node.module = ModuleFixtures.qt_calculator | ||
6 | - org_node = new_node('org', 'PACKAGE') | ||
7 | - org_node.children = [new_node('org.Window', 'CLASS')] | ||
8 | - node.children = [org_node, new_node('Dialog', 'CLASS'), new_node('main', 'CLASS')] | ||
9 | - node | 5 | + def self.module_node |
6 | + Kalibro::ModuleNode.new module_node_hash | ||
10 | end | 7 | end |
11 | 8 | ||
12 | - def self.qt_calculator_tree_hash | ||
13 | - {:module => ModuleFixtures.qt_calculator_hash, | ||
14 | - :child => [ | ||
15 | - {:module => {:name => 'org', :granularity => 'PACKAGE'}, | ||
16 | - :child => [{:module => {:name => 'org.Window', :granularity => 'CLASS'}}]}, | ||
17 | - {:module => {:name => 'Dialog', :granularity => 'CLASS'}}, | ||
18 | - {:module => {:name => 'main', :granularity => 'CLASS'}} | ||
19 | - ] | 9 | + def self.module_node_hash |
10 | + { | ||
11 | + :module => ModuleFixtures.module_hash,:attributes! => {:module => { | ||
12 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | ||
13 | + 'xsi:type' => 'kalibro:moduleXml' }}, | ||
14 | + :child => [{ | ||
15 | + :module => { | ||
16 | + :name => 'org', | ||
17 | + :granularity => 'PACKAGE' | ||
18 | + },:attributes! => {:module => { | ||
19 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | ||
20 | + 'xsi:type' => 'kalibro:moduleXml' }}, | ||
21 | + :child => [{ | ||
22 | + :module => { | ||
23 | + :name => 'org.Window', | ||
24 | + :granularity => 'CLASS' | ||
25 | + },:attributes! => {:module => { | ||
26 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | ||
27 | + 'xsi:type' => 'kalibro:moduleXml' }} | ||
28 | + }] | ||
29 | + },{ | ||
30 | + :module => { | ||
31 | + :name => 'Dialog', | ||
32 | + :granularity => 'CLASS' | ||
33 | + },:attributes! => {:module => { | ||
34 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | ||
35 | + 'xsi:type' => 'kalibro:moduleXml' }} | ||
36 | + },{ | ||
37 | + :module => { | ||
38 | + :name => 'main', | ||
39 | + :granularity => 'CLASS' | ||
40 | + },:attributes! => {:module => { | ||
41 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | ||
42 | + 'xsi:type' => 'kalibro:moduleXml' }} | ||
43 | + }] | ||
20 | } | 44 | } |
21 | end | 45 | end |
22 | 46 | ||
23 | - private | ||
24 | - | ||
25 | - def self.new_node(name, granularity) | ||
26 | - the_module = Kalibro::Entities::Module.new | ||
27 | - the_module.name = name | ||
28 | - the_module.granularity = granularity | ||
29 | - node = Kalibro::Entities::ModuleNode.new | ||
30 | - node.module = the_module | ||
31 | - node | ||
32 | - end | ||
33 | - | ||
34 | end | 47 | end |
plugins/mezuro/test/fixtures/project_result_fixtures.rb
@@ -4,21 +4,19 @@ require File.dirname(__FILE__) + '/module_result_fixtures' | @@ -4,21 +4,19 @@ require File.dirname(__FILE__) + '/module_result_fixtures' | ||
4 | 4 | ||
5 | class ProjectResultFixtures | 5 | class ProjectResultFixtures |
6 | 6 | ||
7 | - def self.qt_calculator | ||
8 | - result = Kalibro::Entities::ProjectResult.new | ||
9 | - result.project = ProjectFixtures.project | ||
10 | - result.date = ModuleResultFixtures.create.date | ||
11 | - result.load_time = 14878 | ||
12 | - result.analysis_time = 1022 | ||
13 | - result.source_tree = ModuleNodeFixtures.qt_calculator_tree | ||
14 | - result.collect_time = 14878 | ||
15 | - result | 7 | + def self.project_result |
8 | + Kalibro::ProjectResult.new project_result_hash | ||
16 | end | 9 | end |
17 | 10 | ||
18 | - def self.qt_calculator_hash | ||
19 | - {:project => ProjectFixtures.project_hash, :date => ModuleResultFixtures.create_hash[:date], | ||
20 | - :load_time => 14878, :analysis_time => 1022, :source_tree => ModuleNodeFixtures.qt_calculator_tree_hash, | ||
21 | - :collect_time => 14878} | 11 | + def self.project_result_hash |
12 | + { | ||
13 | + :project => ProjectFixtures.project_hash, | ||
14 | + :date => ModuleResultFixtures.module_result_hash[:date], | ||
15 | + :load_time => 14878, | ||
16 | + :analysis_time => 1022, | ||
17 | + :source_tree => ModuleNodeFixtures.module_node_hash, | ||
18 | + :collect_time => 14878 | ||
19 | + } | ||
22 | end | 20 | end |
23 | 21 | ||
24 | end | 22 | end |
plugins/mezuro/test/unit/kalibro/client/project_result_client_test.rb
@@ -1,58 +0,0 @@ | @@ -1,58 +0,0 @@ | ||
1 | -require "test_helper" | ||
2 | - | ||
3 | -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures" | ||
4 | - | ||
5 | -class ProjectResultClientTest < ActiveSupport::TestCase | ||
6 | - | ||
7 | - def setup | ||
8 | - @port = mock | ||
9 | - Kalibro::Client::Port.expects(:new).with('ProjectResult').returns(@port) | ||
10 | - @client = Kalibro::Client::ProjectResultClient.new | ||
11 | - | ||
12 | - @result = ProjectResultFixtures.qt_calculator | ||
13 | - @project_name = @result.project.name | ||
14 | - @date = @result.date | ||
15 | - @flag = DateTime.now.sec % 2 == 0 | ||
16 | - | ||
17 | - @request = {:project_name => @project_name} | ||
18 | - @request_with_date = {:project_name => @project_name, :date => @date} | ||
19 | - @flag_response = {:has_results => @flag} | ||
20 | - @result_response = {:project_result => @result.to_hash} | ||
21 | - end | ||
22 | - | ||
23 | - should 'retrieve if project has results' do | ||
24 | - @port.expects(:request).with(:has_results_for, @request).returns(@flag_response) | ||
25 | - assert_equal @flag, @client.has_results_for(@project_name) | ||
26 | - end | ||
27 | - | ||
28 | - should 'retrieve if project has results before date' do | ||
29 | - @port.expects(:request).with(:has_results_before, @request_with_date).returns(@flag_response) | ||
30 | - assert_equal @flag, @client.has_results_before(@project_name, @date) | ||
31 | - end | ||
32 | - | ||
33 | - should 'retrieve if project has results after date' do | ||
34 | - @port.expects(:request).with(:has_results_after, @request_with_date).returns(@flag_response) | ||
35 | - assert_equal @flag, @client.has_results_after(@project_name, @date) | ||
36 | - end | ||
37 | - | ||
38 | - should 'get first result of project' do | ||
39 | - @port.expects(:request).with(:get_first_result_of, @request).returns(@result_response) | ||
40 | - assert_equal @result, @client.first_result(@project_name) | ||
41 | - end | ||
42 | - | ||
43 | - should 'get last result of project' do | ||
44 | - @port.expects(:request).with(:get_last_result_of, @request).returns(@result_response) | ||
45 | - assert_equal @result, @client.last_result(@project_name) | ||
46 | - end | ||
47 | - | ||
48 | - should 'get first result of project after date' do | ||
49 | - @port.expects(:request).with(:get_first_result_after, @request_with_date).returns(@result_response) | ||
50 | - assert_equal @result, @client.first_result_after(@project_name, @date) | ||
51 | - end | ||
52 | - | ||
53 | - should 'get last result of project before date' do | ||
54 | - @port.expects(:request).with(:get_last_result_before, @request_with_date).returns(@result_response) | ||
55 | - assert_equal @result, @client.last_result_before(@project_name, @date) | ||
56 | - end | ||
57 | - | ||
58 | -end | ||
59 | \ No newline at end of file | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/entities/module_node_test.rb
@@ -1,20 +0,0 @@ | @@ -1,20 +0,0 @@ | ||
1 | -require "test_helper" | ||
2 | - | ||
3 | -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_node_fixtures" | ||
4 | - | ||
5 | -class ModuleNodeTest < ActiveSupport::TestCase | ||
6 | - | ||
7 | - def setup | ||
8 | - @hash = ModuleNodeFixtures.qt_calculator_tree_hash | ||
9 | - @node = ModuleNodeFixtures.qt_calculator_tree | ||
10 | - end | ||
11 | - | ||
12 | - should 'create module node from hash' do | ||
13 | - assert_equal @node, Kalibro::Entities::ModuleNode.from_hash(@hash) | ||
14 | - end | ||
15 | - | ||
16 | - should 'convert children hash to array of ModuleNode' do | ||
17 | - assert_equal @hash, @node.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/project_result_test.rb
@@ -1,49 +0,0 @@ | @@ -1,49 +0,0 @@ | ||
1 | -require "test_helper" | ||
2 | - | ||
3 | -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures" | ||
4 | - | ||
5 | -class ProjectResultTest < ActiveSupport::TestCase | ||
6 | - | ||
7 | - def setup | ||
8 | - @hash = ProjectResultFixtures.qt_calculator_hash | ||
9 | - @result = ProjectResultFixtures.qt_calculator | ||
10 | - end | ||
11 | - | ||
12 | - should 'create project result from hash' do | ||
13 | - assert_equal @result, Kalibro::Entities::ProjectResult.from_hash(@hash) | ||
14 | - end | ||
15 | - | ||
16 | - should 'convert project result to hash' do | ||
17 | - assert_equal @hash, @result.to_hash | ||
18 | - end | ||
19 | - | ||
20 | - should 'retrieve formatted load time' do | ||
21 | - assert_equal '00:00:14', @result.formatted_load_time | ||
22 | - end | ||
23 | - | ||
24 | - should 'retrieve formatted analysis time' do | ||
25 | - assert_equal '00:00:01', @result.formatted_analysis_time | ||
26 | - end | ||
27 | - | ||
28 | - should 'retrieve module node' do | ||
29 | - node = @result.get_node("main") | ||
30 | - assert_equal @hash[:source_tree][:child][2], node.to_hash | ||
31 | - end | ||
32 | - | ||
33 | - should 'retrive complex module' do | ||
34 | - node = @result.get_node("org.Window") | ||
35 | - assert_equal @hash[:source_tree][:child][0][:child].first, node.to_hash | ||
36 | - end | ||
37 | - | ||
38 | - should 'return source tree node when nil is given' do | ||
39 | - assert_equal @hash[:source_tree], @result.node_of(nil).to_hash | ||
40 | - end | ||
41 | - | ||
42 | - should 'return source tree node when project name is given' do | ||
43 | - assert_equal @hash[:source_tree], @result.node_of(@result.project.name).to_hash | ||
44 | - end | ||
45 | - | ||
46 | - should 'return correct node when module name is given' do | ||
47 | - assert_equal @hash[:source_tree][:child][2], @result.node_of("main").to_hash | ||
48 | - end | ||
49 | -end |
@@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
1 | +require "test_helper" | ||
2 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_node_fixtures" | ||
3 | + | ||
4 | +class ModuleNodeTest < ActiveSupport::TestCase | ||
5 | + | ||
6 | + def setup | ||
7 | + @hash = ModuleNodeFixtures.module_node_hash | ||
8 | + @node = ModuleNodeFixtures.module_node | ||
9 | + end | ||
10 | + | ||
11 | + should 'create module node from hash' do | ||
12 | + assert_equal( @node.child[0].module.name, Kalibro::ModuleNode.new(@hash).child[0].module.name) | ||
13 | + end | ||
14 | + | ||
15 | + should 'convert children hash to array of ModuleNode' do | ||
16 | + assert_equal @hash, @node.to_hash | ||
17 | + end | ||
18 | + | ||
19 | +end |
@@ -0,0 +1,98 @@ | @@ -0,0 +1,98 @@ | ||
1 | +require "test_helper" | ||
2 | + | ||
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures" | ||
4 | + | ||
5 | +class ProjectResultTest < ActiveSupport::TestCase | ||
6 | + | ||
7 | + def setup | ||
8 | + @hash = ProjectResultFixtures.project_result_hash | ||
9 | + @project_result = ProjectResultFixtures.project_result | ||
10 | + | ||
11 | +# Kalibro::Client::Port.expects(:new).with('ProjectResult').returns(@port) | ||
12 | +# @client = Kalibro::Client::ProjectResultClient.new | ||
13 | + | ||
14 | + @project_name = @project_result.project.name | ||
15 | + @date = @project_result.date | ||
16 | +# @flag = DateTime.now.sec % 2 == 0 | ||
17 | + | ||
18 | + @request = {:project_name => @project_name} | ||
19 | + @request_with_date = {:project_name => @project_name, :date => @date} | ||
20 | +# @flag_response = {:has_results => @flag} | ||
21 | + @result_response = {:project_result => @project_result.to_hash} | ||
22 | + end | ||
23 | + | ||
24 | + should 'get last result' do | ||
25 | + Kalibro::ProjectResult.expects(:request).with('ProjectResult',:get_last_result_of, @request).returns(@result_response) | ||
26 | + assert_equal @project_result.analysis_time , Kalibro::ProjectResult.last_result(@project_name).analysis_time | ||
27 | + end | ||
28 | +=begin | ||
29 | + should 'create project result from hash' do | ||
30 | + assert_equal @result, Kalibro::ProjectResult.from_hash(@hash) | ||
31 | + end | ||
32 | + | ||
33 | + should 'convert project result to hash' do | ||
34 | + assert_equal @hash, @result.to_hash | ||
35 | + end | ||
36 | + | ||
37 | + should 'retrieve formatted load time' do | ||
38 | + assert_equal '00:00:14', @result.formatted_load_time | ||
39 | + end | ||
40 | + | ||
41 | + should 'retrieve formatted analysis time' do | ||
42 | + assert_equal '00:00:01', @result.formatted_analysis_time | ||
43 | + end | ||
44 | + | ||
45 | + should 'retrieve module node' do | ||
46 | + node = @result.get_node("main") | ||
47 | + assert_equal @hash[:source_tree][:child][2], node.to_hash | ||
48 | + end | ||
49 | + | ||
50 | + should 'retrive complex module' do | ||
51 | + node = @result.get_node("org.Window") | ||
52 | + assert_equal @hash[:source_tree][:child][0][:child].first, node.to_hash | ||
53 | + end | ||
54 | + | ||
55 | + should 'return source tree node when nil is given' do | ||
56 | + assert_equal @hash[:source_tree], @result.node_of(nil).to_hash | ||
57 | + end | ||
58 | + | ||
59 | + should 'return source tree node when project name is given' do | ||
60 | + assert_equal @hash[:source_tree], @result.node_of(@result.project.name).to_hash | ||
61 | + end | ||
62 | + | ||
63 | + should 'return correct node when module name is given' do | ||
64 | + assert_equal @hash[:source_tree][:child][2], @result.node_of("main").to_hash | ||
65 | + end | ||
66 | + | ||
67 | + should 'retrieve if project has results' do | ||
68 | + @port.expects(:request).with(:has_results_for, @request).returns(@flag_response) | ||
69 | + assert_equal @flag, @client.has_results_for(@project_name) | ||
70 | + end | ||
71 | + | ||
72 | + should 'retrieve if project has results before date' do | ||
73 | + @port.expects(:request).with(:has_results_before, @request_with_date).returns(@flag_response) | ||
74 | + assert_equal @flag, @client.has_results_before(@project_name, @date) | ||
75 | + end | ||
76 | + | ||
77 | + should 'retrieve if project has results after date' do | ||
78 | + @port.expects(:request).with(:has_results_after, @request_with_date).returns(@flag_response) | ||
79 | + assert_equal @flag, @client.has_results_after(@project_name, @date) | ||
80 | + end | ||
81 | + | ||
82 | + should 'get first result of project' do | ||
83 | + @port.expects(:request).with(:get_first_result_of, @request).returns(@result_response) | ||
84 | + assert_equal @result, @client.first_result(@project_name) | ||
85 | + end | ||
86 | + | ||
87 | + | ||
88 | + should 'get first result of project after date' do | ||
89 | + @port.expects(:request).with(:get_first_result_after, @request_with_date).returns(@result_response) | ||
90 | + assert_equal @result, @client.first_result_after(@project_name, @date) | ||
91 | + end | ||
92 | + | ||
93 | + should 'get last result of project before date' do | ||
94 | + @port.expects(:request).with(:get_last_result_before, @request_with_date).returns(@result_response) | ||
95 | + assert_equal @result, @client.last_result_before(@project_name, @date) | ||
96 | + end | ||
97 | +=end | ||
98 | +end |