Commit 57daefcbbf633528cb9cf6ca84526c2569047d4b
Committed by
Paulo Meireles
1 parent
0d44cd8b
Exists in
master
and in
29 other branches
[Mezuro] made project result unit tests
Showing
3 changed files
with
77 additions
and
60 deletions
Show diff stats
plugins/mezuro/test/fixtures/project_fixtures.rb
... | ... | @@ -6,6 +6,25 @@ class ProjectFixtures |
6 | 6 | Kalibro::Project.new project_hash |
7 | 7 | end |
8 | 8 | |
9 | + def self.project_hash | |
10 | + { | |
11 | + :name => 'Qt-Calculator', | |
12 | + :license => 'GPL', | |
13 | + :description => 'Calculator for Qt', | |
14 | + :repository => RepositoryFixtures.repository_hash, | |
15 | + :configuration_name => 'Kalibro for Java', | |
16 | + :state => 'READY', | |
17 | + :attributes! => | |
18 | + { | |
19 | + :repository=> | |
20 | + { | |
21 | + "xsi:type"=>"kalibro:repositoryXml", | |
22 | + "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance" | |
23 | + } | |
24 | + } | |
25 | + } | |
26 | + end | |
27 | + | |
9 | 28 | def self.project_content |
10 | 29 | content = MezuroPlugin::ProjectContent.new |
11 | 30 | content.name = 'Qt-Calculator' |
... | ... | @@ -18,15 +37,4 @@ class ProjectFixtures |
18 | 37 | content |
19 | 38 | end |
20 | 39 | |
21 | - def self.project_hash | |
22 | - { | |
23 | - :name => 'Qt-Calculator', | |
24 | - :license => 'GPL', | |
25 | - :description => 'Calculator for Qt', | |
26 | - :repository => RepositoryFixtures.repository_hash, | |
27 | - :configuration_name => 'Kalibro for Java', | |
28 | - :state => 'READY' | |
29 | - } | |
30 | - end | |
31 | - | |
32 | 40 | end | ... | ... |
plugins/mezuro/test/fixtures/project_result_fixtures.rb
... | ... | @@ -15,7 +15,20 @@ class ProjectResultFixtures |
15 | 15 | :load_time => 14878, |
16 | 16 | :analysis_time => 1022, |
17 | 17 | :source_tree => ModuleNodeFixtures.module_node_hash, |
18 | - :collect_time => 14878 | |
18 | + :collect_time => 14878, | |
19 | + :attributes! => | |
20 | + { | |
21 | + :source_tree => | |
22 | + { | |
23 | + "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance", | |
24 | + "xsi:type"=>"kalibro:moduleNodeXml" | |
25 | + }, | |
26 | + :project => | |
27 | + { | |
28 | + "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance", | |
29 | + "xsi:type"=>"kalibro:projectXml" | |
30 | + } | |
31 | + } | |
19 | 32 | } |
20 | 33 | end |
21 | 34 | ... | ... |
plugins/mezuro/test/unit/kalibro/project_result_test.rb
... | ... | @@ -8,91 +8,87 @@ class ProjectResultTest < ActiveSupport::TestCase |
8 | 8 | @hash = ProjectResultFixtures.project_result_hash |
9 | 9 | @project_result = ProjectResultFixtures.project_result |
10 | 10 | |
11 | -# Kalibro::Client::Port.expects(:new).with('ProjectResult').returns(@port) | |
12 | -# @client = Kalibro::Client::ProjectResultClient.new | |
13 | - | |
14 | 11 | @project_name = @project_result.project.name |
15 | 12 | @date = @project_result.date |
16 | -# @flag = DateTime.now.sec % 2 == 0 | |
13 | + @flag = DateTime.now.sec % 2 == 0 #random choose between true or false | |
17 | 14 | |
18 | 15 | @request = {:project_name => @project_name} |
19 | 16 | @request_with_date = {:project_name => @project_name, :date => @date} |
20 | -# @flag_response = {:has_results => @flag} | |
17 | + @flag_response = {:has_results => @flag} | |
21 | 18 | @result_response = {:project_result => @project_result.to_hash} |
22 | 19 | end |
23 | 20 | |
21 | + should 'create project result from hash' do | |
22 | + assert_equal @project_result.analysis_time, Kalibro::ProjectResult.new(@hash).analysis_time | |
23 | + end | |
24 | + | |
25 | + should 'convert project result to hash' do | |
26 | + assert_equal @hash, @project_result.to_hash | |
27 | + end | |
28 | + | |
24 | 29 | should 'get last result' do |
25 | 30 | Kalibro::ProjectResult.expects(:request).with('ProjectResult',:get_last_result_of, @request).returns(@result_response) |
26 | 31 | assert_equal @project_result.analysis_time , Kalibro::ProjectResult.last_result(@project_name).analysis_time |
27 | 32 | end |
28 | -=begin | |
29 | - should 'create project result from hash' do | |
30 | - assert_equal @result, Kalibro::ProjectResult.from_hash(@hash) | |
33 | + | |
34 | + should 'get first result' do | |
35 | + Kalibro::ProjectResult.expects(:request).with('ProjectResult',:get_first_result_of, @request).returns(@result_response) | |
36 | + assert_equal @project_result.analysis_time, Kalibro::ProjectResult.first_result(@project_name).analysis_time | |
31 | 37 | end |
32 | 38 | |
33 | - should 'convert project result to hash' do | |
34 | - assert_equal @hash, @result.to_hash | |
39 | + should 'get first result after date' do | |
40 | + Kalibro::ProjectResult.expects(:request).with('ProjectResult',:get_first_result_after, @request_with_date).returns(@result_response) | |
41 | + assert_equal @project_result.analysis_time, Kalibro::ProjectResult.first_result_after(@project_name, @date).analysis_time | |
42 | + end | |
43 | + | |
44 | + should 'get last result before date' do | |
45 | + Kalibro::ProjectResult.expects(:request).with('ProjectResult',:get_last_result_before, @request_with_date).returns(@result_response) | |
46 | + assert_equal @project_result.analysis_time, Kalibro::ProjectResult.last_result_before(@project_name, @date).analysis_time | |
47 | + end | |
48 | + | |
49 | + should 'verify if project has results' do | |
50 | + Kalibro::ProjectResult.expects(:request).with('ProjectResult',:has_results_for, @request).returns(@flag_response) | |
51 | + assert_equal @flag, Kalibro::ProjectResult.has_results?(@project_name) | |
52 | + end | |
53 | + | |
54 | + should 'verify if project has results before date' do | |
55 | + Kalibro::ProjectResult.expects(:request).with('ProjectResult',:has_results_before, @request_with_date).returns(@flag_response) | |
56 | + assert_equal @flag, Kalibro::ProjectResult.has_results_before?(@project_name, @date) | |
57 | + end | |
58 | + | |
59 | + should 'verify if project has results after date' do | |
60 | + Kalibro::ProjectResult.expects(:request).with('ProjectResult',:has_results_after, @request_with_date).returns(@flag_response) | |
61 | + assert_equal @flag, Kalibro::ProjectResult.has_results_after?(@project_name, @date) | |
35 | 62 | end |
36 | 63 | |
37 | 64 | should 'retrieve formatted load time' do |
38 | - assert_equal '00:00:14', @result.formatted_load_time | |
65 | + assert_equal '00:00:14', @project_result.formatted_load_time | |
39 | 66 | end |
40 | 67 | |
41 | 68 | should 'retrieve formatted analysis time' do |
42 | - assert_equal '00:00:01', @result.formatted_analysis_time | |
69 | + assert_equal '00:00:01', @project_result.formatted_analysis_time | |
43 | 70 | end |
44 | 71 | |
45 | 72 | should 'retrieve module node' do |
46 | - node = @result.get_node("main") | |
73 | + node = @project_result.get_node("main") | |
47 | 74 | assert_equal @hash[:source_tree][:child][2], node.to_hash |
48 | 75 | end |
49 | 76 | |
50 | 77 | should 'retrive complex module' do |
51 | - node = @result.get_node("org.Window") | |
78 | + node = @project_result.get_node("org.Window") | |
52 | 79 | assert_equal @hash[:source_tree][:child][0][:child].first, node.to_hash |
53 | 80 | end |
54 | 81 | |
55 | 82 | should 'return source tree node when nil is given' do |
56 | - assert_equal @hash[:source_tree], @result.node_of(nil).to_hash | |
83 | + assert_equal @hash[:source_tree], @project_result.node_of(nil).to_hash | |
57 | 84 | end |
58 | 85 | |
59 | 86 | 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 | |
87 | + assert_equal @hash[:source_tree], @project_result.node_of(@project_result.project.name).to_hash | |
61 | 88 | end |
62 | 89 | |
63 | 90 | 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) | |
91 | + assert_equal @hash[:source_tree][:child][2], @project_result.node_of("main").to_hash | |
75 | 92 | end |
76 | 93 | |
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 | 94 | end | ... | ... |