project_result_test.rb
3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require "test_helper"
require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures"
class ProjectResultTest < ActiveSupport::TestCase
def setup
@hash = ProjectResultFixtures.project_result_hash
@project_result = ProjectResultFixtures.project_result
@project_name = @project_result.project.name
@date = @project_result.date
@flag = DateTime.now.sec % 2 == 0 #random choose between true or false
@request = {:project_name => @project_name}
@request_with_date = {:project_name => @project_name, :date => @date}
@flag_response = {:has_results => @flag}
@result_response = {:project_result => @project_result.to_hash}
end
should 'create project result from hash' do
assert_equal @project_result.analysis_time, Kalibro::ProjectResult.new(@hash).analysis_time
end
should 'convert project result to hash' do
assert_equal @hash, @project_result.to_hash
end
should 'get last result' do
Kalibro::ProjectResult.expects(:request).with('ProjectResult',:get_last_result_of, @request).returns(@result_response)
assert_equal @project_result.analysis_time , Kalibro::ProjectResult.last_result(@project_name).analysis_time
end
should 'get first result' do
Kalibro::ProjectResult.expects(:request).with('ProjectResult',:get_first_result_of, @request).returns(@result_response)
assert_equal @project_result.analysis_time, Kalibro::ProjectResult.first_result(@project_name).analysis_time
end
should 'get first result after date' do
Kalibro::ProjectResult.expects(:request).with('ProjectResult',:get_first_result_after, @request_with_date).returns(@result_response)
assert_equal @project_result.analysis_time, Kalibro::ProjectResult.first_result_after(@project_name, @date).analysis_time
end
should 'get last result before date' do
Kalibro::ProjectResult.expects(:request).with('ProjectResult',:get_last_result_before, @request_with_date).returns(@result_response)
assert_equal @project_result.analysis_time, Kalibro::ProjectResult.last_result_before(@project_name, @date).analysis_time
end
should 'verify if project has results' do
Kalibro::ProjectResult.expects(:request).with('ProjectResult',:has_results_for, @request).returns(@flag_response)
assert_equal @flag, Kalibro::ProjectResult.has_results?(@project_name)
end
should 'verify if project has results before date' do
Kalibro::ProjectResult.expects(:request).with('ProjectResult',:has_results_before, @request_with_date).returns(@flag_response)
assert_equal @flag, Kalibro::ProjectResult.has_results_before?(@project_name, @date)
end
should 'verify if project has results after date' do
Kalibro::ProjectResult.expects(:request).with('ProjectResult',:has_results_after, @request_with_date).returns(@flag_response)
assert_equal @flag, Kalibro::ProjectResult.has_results_after?(@project_name, @date)
end
should 'retrieve formatted load time' do
assert_equal '00:00:14', @project_result.formatted_load_time
end
should 'retrieve formatted analysis time' do
assert_equal '00:00:01', @project_result.formatted_analysis_time
end
should 'retrive complex module' do
assert_equal @hash[:source_tree][:child][0][:child].first, @project_result.node("org.Window").to_hash
end
should 'return source tree node when nil is given' do
assert_equal @hash[:source_tree], @project_result.node(nil).to_hash
end
should 'return source tree node when project name is given' do
assert_equal @hash[:source_tree], @project_result.node(@project_result.project.name).to_hash
end
should 'return correct node when module name is given' do
assert_equal @hash[:source_tree][:child][2], @project_result.node("main").to_hash
end
end