Commit 82df2dfdd6a5e71884baefae5c31ccf5dbaa241f
Committed by
Paulo Meireles
1 parent
1bad209b
Exists in
master
and in
29 other branches
Adding test directory
Showing
28 changed files
with
1017 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,11 @@ |
1 | +require File.dirname(__FILE__) + '/../../../test/test_helper' | |
2 | +require File.dirname(__FILE__) + '/../controllers/mezuro_plugin_myprofile_controller' | |
3 | + | |
4 | +class MezuroTest < ActiveSupport::TestCase | |
5 | + | |
6 | + should 'create a mezuro project' do | |
7 | + controller = MezuroPluginMyprofileController.new | |
8 | + controller.create | |
9 | + end | |
10 | + | |
11 | +end | ... | ... |
plugins/mezuro/test/unit/kalibro/client/base_tool_client_test.rb
0 → 100644
... | ... | @@ -0,0 +1,33 @@ |
1 | +class BaseToolClientTest < Test::Unit::TestCase | |
2 | + | |
3 | + def setup | |
4 | + @port = mock | |
5 | + Kalibro::Client::Port.expects(:new).with('BaseTool').returns(@port) | |
6 | + @client = Kalibro::Client::BaseToolClient.new | |
7 | + end | |
8 | + | |
9 | + should 'get base tool names (zero)' do | |
10 | + @port.expects(:request).with(:get_base_tool_names).returns({}) | |
11 | + assert_equal [], @client.base_tool_names | |
12 | + end | |
13 | + | |
14 | + should 'get base tool names (one)' do | |
15 | + name = 'Analizo' | |
16 | + @port.expects(:request).with(:get_base_tool_names).returns({:base_tool_name => name}) | |
17 | + assert_equal [name], @client.base_tool_names | |
18 | + end | |
19 | + | |
20 | + should 'get base tool names' do | |
21 | + names = ['Analizo', 'Checkstyle'] | |
22 | + @port.expects(:request).with(:get_base_tool_names).returns({:base_tool_name => names}) | |
23 | + assert_equal names, @client.base_tool_names | |
24 | + end | |
25 | + | |
26 | + should 'get base tool by name' do | |
27 | + analizo = BaseToolTest.analizo | |
28 | + request_body = {:base_tool_name => 'Analizo'} | |
29 | + @port.expects(:request).with(:get_base_tool, request_body).returns({:base_tool => analizo.to_hash}) | |
30 | + assert_equal analizo, @client.base_tool('Analizo') | |
31 | + end | |
32 | + | |
33 | +end | |
0 | 34 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/client/configuration_client_test.rb
0 → 100644
... | ... | @@ -0,0 +1,46 @@ |
1 | +class ConfigurationClientTest < Test::Unit::TestCase | |
2 | + | |
3 | + def setup | |
4 | + @port = mock | |
5 | + Kalibro::Client::Port.expects(:new).with('Configuration').returns(@port) | |
6 | + @client = Kalibro::Client::ConfigurationClient.new | |
7 | + end | |
8 | + | |
9 | + should 'save configuration' do | |
10 | + configuration = ConfigurationTest.kalibro_configuration | |
11 | + @port.expects(:request).with(:save_configuration, {:configuration => configuration.to_hash}) | |
12 | + @client.save(configuration) | |
13 | + end | |
14 | + | |
15 | + should 'get configuration names (zero)' do | |
16 | + @port.expects(:request).with(:get_configuration_names).returns({}) | |
17 | + assert_equal [], @client.configuration_names | |
18 | + end | |
19 | + | |
20 | + should 'get configuration names (one)' do | |
21 | + name = 'Kalibro for Java' | |
22 | + @port.expects(:request).with(:get_configuration_names).returns({:configuration_name => name}) | |
23 | + assert_equal [name], @client.configuration_names | |
24 | + end | |
25 | + | |
26 | + should 'get configuration names' do | |
27 | + names = ['Kalibro for Java', 'ConfigurationClientTest configuration'] | |
28 | + @port.expects(:request).with(:get_configuration_names).returns({:configuration_name => names}) | |
29 | + assert_equal names, @client.configuration_names | |
30 | + end | |
31 | + | |
32 | + should 'get configuration by name' do | |
33 | + configuration = ConfigurationTest.kalibro_configuration | |
34 | + request_body = {:configuration_name => configuration.name} | |
35 | + response_hash = {:configuration => configuration.to_hash} | |
36 | + @port.expects(:request).with(:get_configuration, request_body).returns(response_hash) | |
37 | + assert_equal configuration, @client.configuration(configuration.name) | |
38 | + end | |
39 | + | |
40 | + should 'remove configuration by name' do | |
41 | + name = 'ConfigurationClientTest' | |
42 | + @port.expects(:request).with(:remove_configuration, {:configuration_name => name}) | |
43 | + @client.remove(name) | |
44 | + end | |
45 | + | |
46 | +end | |
0 | 47 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/client/kalibro_client_test.rb
0 → 100644
... | ... | @@ -0,0 +1,21 @@ |
1 | +class KalibroClientTest < Test::Unit::TestCase | |
2 | + | |
3 | + def setup | |
4 | + @port = mock | |
5 | + Kalibro::Client::Port.expects(:new).with('Kalibro').returns(@port) | |
6 | + @client = Kalibro::Client::KalibroClient.new | |
7 | + end | |
8 | + | |
9 | + should 'get supported repository types' do | |
10 | + types = ['BAZAAR', 'GIT', 'SUBVERSION'] | |
11 | + @port.expects(:request).with(:get_supported_repository_types).returns({:repository_type => types}) | |
12 | + assert_equal types, @client.supported_repository_types | |
13 | + end | |
14 | + | |
15 | + should 'process project' do | |
16 | + name = 'KalibroClientTest' | |
17 | + @port.expects(:request).with(:process_project, {:project_name => name}) | |
18 | + @client.process_project(name) | |
19 | + end | |
20 | + | |
21 | +end | |
0 | 22 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/client/module_result_client_test.rb
0 → 100644
... | ... | @@ -0,0 +1,24 @@ |
1 | +class ModuleResultClientTest < Test::Unit::TestCase | |
2 | + | |
3 | + def setup | |
4 | + @port = mock | |
5 | + Kalibro::Client::Port.expects(:new).with('ModuleResult').returns(@port) | |
6 | + @client = Kalibro::Client::ModuleResultClient.new | |
7 | + @result = ModuleResultTest.fixture | |
8 | + end | |
9 | + | |
10 | + should 'get module result' do | |
11 | + request_body = {:project_name => 'Qt-Calculator', :module_name => 'main', :date => '42'} | |
12 | + response = {:module_result => @result.to_hash} | |
13 | + @port.expects(:request).with(:get_module_result, request_body).returns(response) | |
14 | + assert_equal @result, @client.module_result('Qt-Calculator', 'main', '42') | |
15 | + end | |
16 | + | |
17 | + should 'get result history' do | |
18 | + request_body = {:project_name => 'Qt-Calculator', :module_name => 'main'} | |
19 | + response = {:module_result => @result.to_hash} | |
20 | + @port.expects(:request).with(:get_result_history, request_body).returns(response) | |
21 | + assert_equal [@result], @client.result_history('Qt-Calculator', 'main') | |
22 | + end | |
23 | + | |
24 | +end | |
0 | 25 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,24 @@ |
1 | +class PortTest < Test::Unit::TestCase | |
2 | + | |
3 | + def setup | |
4 | + @service_address = Kalibro::Client::Port.service_address | |
5 | + @client = mock | |
6 | + Savon::Client.expects(:new).with("#{@service_address}PortTestEndpoint/?wsdl").returns(@client) | |
7 | + @port = Kalibro::Client::Port.new('PortTest') | |
8 | + end | |
9 | + | |
10 | + should 'default address be valinhos' do | |
11 | + assert_equal 'http://valinhos.ime.usp.br:50688/KalibroService/', @service_address | |
12 | + end | |
13 | + | |
14 | + should 'request action and return response' do | |
15 | + response_body = {:port_test_response_key => 'PortTest response value'} | |
16 | + response_hash = {:port_test_action_response => response_body} | |
17 | + response = mock | |
18 | + response.expects(:to_hash).returns(response_hash) | |
19 | + @client.expects(:request).with(:kalibro, :port_test_action).returns(response) | |
20 | + | |
21 | + assert_equal response_body, @port.request(:port_test_action) | |
22 | + end | |
23 | + | |
24 | +end | |
0 | 25 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/client/project_client_test.rb
0 → 100644
... | ... | @@ -0,0 +1,46 @@ |
1 | +class ProjectClientTest < Test::Unit::TestCase | |
2 | + | |
3 | + def setup | |
4 | + @port = mock | |
5 | + Kalibro::Client::Port.expects(:new).with('Project').returns(@port) | |
6 | + @client = Kalibro::Client::ProjectClient.new | |
7 | + end | |
8 | + | |
9 | + should 'save project' do | |
10 | + project = ProjectTest.qt_calculator | |
11 | + @port.expects(:request).with(:save_project, {:project => project.to_hash}) | |
12 | + @client.save(project) | |
13 | + end | |
14 | + | |
15 | + should 'get project names (zero)' do | |
16 | + @port.expects(:request).with(:get_project_names).returns({}) | |
17 | + assert_equal [], @client.project_names | |
18 | + end | |
19 | + | |
20 | + should 'get project names (one)' do | |
21 | + name = 'Qt-Calculator' | |
22 | + @port.expects(:request).with(:get_project_names).returns({:project_name => name}) | |
23 | + assert_equal [name], @client.project_names | |
24 | + end | |
25 | + | |
26 | + should 'get project names' do | |
27 | + names = ['Hello World', 'Qt-Calculator'] | |
28 | + @port.expects(:request).with(:get_project_names).returns({:project_name => names}) | |
29 | + assert_equal names, @client.project_names | |
30 | + end | |
31 | + | |
32 | + should 'get project by name' do | |
33 | + project = ProjectTest.qt_calculator | |
34 | + request_body = {:project_name => project.name} | |
35 | + response_hash = {:project => project.to_hash} | |
36 | + @port.expects(:request).with(:get_project, request_body).returns(response_hash) | |
37 | + assert_equal project, @client.project(project.name) | |
38 | + end | |
39 | + | |
40 | + should 'remove project by name' do | |
41 | + name = 'ProjectClientTest' | |
42 | + @port.expects(:request).with(:remove_project, {:project_name => name}) | |
43 | + @client.remove(name) | |
44 | + end | |
45 | + | |
46 | +end | |
0 | 47 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/client/project_result_client_test.rb
0 → 100644
... | ... | @@ -0,0 +1,67 @@ |
1 | +class ProjectResultClientTest < Test::Unit::TestCase | |
2 | + | |
3 | + def setup | |
4 | + @port = mock | |
5 | + Kalibro::Client::Port.expects(:new).with('ProjectResult').returns(@port) | |
6 | + @client = Kalibro::Client::ProjectResultClient.new | |
7 | + | |
8 | + @result = ProjectResultTest.qt_calculator | |
9 | + @project_name = @result.project.name | |
10 | + @date = @result.date | |
11 | + @flag = DateTime.now.sec % 2 == 0 | |
12 | + end | |
13 | + | |
14 | + should 'retrieve if project has results' do | |
15 | + @port.expects(:request).with(:has_results_for, request).returns(flag_response) | |
16 | + assert_equal @flag, @client.has_results_for(@project_name) | |
17 | + end | |
18 | + | |
19 | + should 'retrieve if project has results before date' do | |
20 | + @port.expects(:request).with(:has_results_before, request_with_date).returns(flag_response) | |
21 | + assert_equal @flag, @client.has_results_before(@project_name, @date) | |
22 | + end | |
23 | + | |
24 | + should 'retrieve if project has results after date' do | |
25 | + @port.expects(:request).with(:has_results_after, request_with_date).returns(flag_response) | |
26 | + assert_equal @flag, @client.has_results_after(@project_name, @date) | |
27 | + end | |
28 | + | |
29 | + should 'get first result of project' do | |
30 | + @port.expects(:request).with(:get_first_result_of, request).returns(result_response) | |
31 | + assert_equal @result, @client.first_result(@project_name) | |
32 | + end | |
33 | + | |
34 | + should 'get last result of project' do | |
35 | + @port.expects(:request).with(:get_last_result_of, request).returns(result_response) | |
36 | + assert_equal @result, @client.last_result(@project_name) | |
37 | + end | |
38 | + | |
39 | + should 'get first result of project after date' do | |
40 | + @port.expects(:request).with(:get_first_result_after, request_with_date).returns(result_response) | |
41 | + assert_equal @result, @client.first_result_after(@project_name, @date) | |
42 | + end | |
43 | + | |
44 | + should 'get last result of project before date' do | |
45 | + @port.expects(:request).with(:get_last_result_before, request_with_date).returns(result_response) | |
46 | + assert_equal @result, @client.last_result_before(@project_name, @date) | |
47 | + end | |
48 | + | |
49 | + private | |
50 | + | |
51 | + def request | |
52 | + {:project_name => @project_name} | |
53 | + end | |
54 | + | |
55 | + def request_with_date | |
56 | + {:project_name => @project_name, :date => @date} | |
57 | + end | |
58 | + | |
59 | + def flag_response | |
60 | + {:has_results => @flag} | |
61 | + end | |
62 | + | |
63 | + def result_response | |
64 | + {:project_result => @result.to_hash} | |
65 | + end | |
66 | + | |
67 | +end | |
0 | 68 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/base_tool_test.rb
0 → 100644
... | ... | @@ -0,0 +1,32 @@ |
1 | +class BaseToolTest < Test::Unit::TestCase | |
2 | + | |
3 | + def self.analizo | |
4 | + total_cof = NativeMetricTest.total_cof | |
5 | + amloc = NativeMetricTest.amloc | |
6 | + base_tool = Kalibro::Entities::BaseTool.new | |
7 | + base_tool.name = 'Analizo' | |
8 | + base_tool.supported_metrics = [total_cof, amloc] | |
9 | + base_tool | |
10 | + end | |
11 | + | |
12 | + def self.analizo_hash | |
13 | + total_cof_hash = NativeMetricTest.total_cof_hash | |
14 | + amloc_hash = NativeMetricTest.amloc_hash | |
15 | + {:name => 'Analizo', | |
16 | + :supported_metric => [total_cof_hash, amloc_hash]} | |
17 | + end | |
18 | + | |
19 | + def setup | |
20 | + @hash = self.class.analizo_hash | |
21 | + @base_tool = self.class.analizo | |
22 | + end | |
23 | + | |
24 | + should 'create base tool from hash' do | |
25 | + assert_equal @base_tool, Kalibro::Entities::BaseTool.from_hash(@hash) | |
26 | + end | |
27 | + | |
28 | + should 'convert base tool to hash' do | |
29 | + assert_equal @hash, @base_tool.to_hash | |
30 | + end | |
31 | + | |
32 | +end | |
0 | 33 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/compound_metric_test.rb
0 → 100644
... | ... | @@ -0,0 +1,29 @@ |
1 | +class CompoundMetricTest < Test::Unit::TestCase | |
2 | + | |
3 | + def self.sc | |
4 | + sc = Kalibro::Entities::CompoundMetric.new | |
5 | + sc.name = 'Structural Complexity' | |
6 | + sc.scope = 'CLASS' | |
7 | + sc.script = 'return cbo * lcom4;' | |
8 | + sc | |
9 | + end | |
10 | + | |
11 | + def self.sc_hash | |
12 | + {:name => 'Structural Complexity', :scope => 'CLASS', | |
13 | + :script => 'return cbo * lcom4;'} | |
14 | + end | |
15 | + | |
16 | + def setup | |
17 | + @hash = self.class.sc_hash | |
18 | + @metric = self.class.sc | |
19 | + end | |
20 | + | |
21 | + should 'create compound metric from hash' do | |
22 | + assert_equal @metric, Kalibro::Entities::CompoundMetric.from_hash(@hash) | |
23 | + end | |
24 | + | |
25 | + should 'convert compound metric to hash' do | |
26 | + assert_equal @hash, @metric.to_hash | |
27 | + end | |
28 | + | |
29 | +end | |
0 | 30 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/compound_metric_with_error_test.rb
0 → 100644
... | ... | @@ -0,0 +1,28 @@ |
1 | +class CompoundMetricWithErrorTest < Test::Unit::TestCase | |
2 | + | |
3 | + def self.fixture | |
4 | + fixture = Kalibro::Entities::CompoundMetricWithError.new | |
5 | + fixture.metric = CompoundMetricTest.sc | |
6 | + fixture.error = ErrorTest.fixture | |
7 | + fixture | |
8 | + end | |
9 | + | |
10 | + def self.fixture_hash | |
11 | + {:metric => CompoundMetricTest.sc_hash, | |
12 | + :error => ErrorTest.fixture_hash} | |
13 | + end | |
14 | + | |
15 | + def setup | |
16 | + @hash = self.class.fixture_hash | |
17 | + @entity = self.class.fixture | |
18 | + end | |
19 | + | |
20 | + should 'create error from hash' do | |
21 | + assert_equal @entity, Kalibro::Entities::CompoundMetricWithError.from_hash(@hash) | |
22 | + end | |
23 | + | |
24 | + should 'convert error to hash' do | |
25 | + assert_equal @hash, @entity.to_hash | |
26 | + end | |
27 | + | |
28 | +end | |
0 | 29 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/configuration_test.rb
0 → 100644
... | ... | @@ -0,0 +1,34 @@ |
1 | +class ConfigurationTest < Test::Unit::TestCase | |
2 | + | |
3 | + def self.kalibro_configuration | |
4 | + amloc_configuration = MetricConfigurationTest.amloc_configuration | |
5 | + sc_configuration = MetricConfigurationTest.sc_configuration | |
6 | + configuration = Kalibro::Entities::Configuration.new | |
7 | + configuration.name = 'Kalibro for Java' | |
8 | + configuration.description = 'Kalibro configuration for Java projects.' | |
9 | + configuration.metric_configurations = [amloc_configuration, sc_configuration] | |
10 | + configuration | |
11 | + end | |
12 | + | |
13 | + def self.kalibro_configuration_hash | |
14 | + amloc_hash = MetricConfigurationTest.amloc_configuration_hash | |
15 | + sc_hash = MetricConfigurationTest.sc_configuration_hash | |
16 | + {:name => 'Kalibro for Java', | |
17 | + :description => 'Kalibro configuration for Java projects.', | |
18 | + :metric_configuration => [amloc_hash, sc_hash]} | |
19 | + end | |
20 | + | |
21 | + def setup | |
22 | + @hash = self.class.kalibro_configuration_hash | |
23 | + @configuration = self.class.kalibro_configuration | |
24 | + end | |
25 | + | |
26 | + should 'create configuration from hash' do | |
27 | + assert_equal @configuration, Kalibro::Entities::Configuration.from_hash(@hash) | |
28 | + end | |
29 | + | |
30 | + should 'convert configuration to hash' do | |
31 | + assert_equal @hash, @configuration.to_hash | |
32 | + end | |
33 | + | |
34 | +end | |
0 | 35 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/entity_test.rb
0 → 100644
... | ... | @@ -0,0 +1,49 @@ |
1 | +class EntityTest < Test::Unit::TestCase | |
2 | + | |
3 | + def setup | |
4 | + @hash = {:name => 'Carlos', :age => 25, | |
5 | + :brothers => [{:name => 'Saulo', :age => 22}, {:name => 'Isis', :age => 26}]} | |
6 | + @person = Person.create('Carlos', 25) | |
7 | + @person.brothers = [Person.create('Saulo', 22), Person.create('Isis', 26)] | |
8 | + @clone = @person.clone | |
9 | + end | |
10 | + | |
11 | + should 'be equal to clone' do | |
12 | + assert_equal @person, @clone | |
13 | + end | |
14 | + | |
15 | + should 'be different when field is different' do | |
16 | + @clone.name = 'Other' | |
17 | + assert @person != @clone | |
18 | + end | |
19 | + | |
20 | + should 'not throw exception when comparing with incompatible object' do | |
21 | + assert @person != @hash | |
22 | + end | |
23 | + | |
24 | + should 'create from hash' do | |
25 | + assert_equal @person, Person.from_hash(@hash) | |
26 | + end | |
27 | + | |
28 | + should 'convert to hash' do | |
29 | + assert_equal @hash, @person.to_hash | |
30 | + end | |
31 | + | |
32 | + class Person < Kalibro::Entities::Entity | |
33 | + | |
34 | + attr_accessor :name, :age, :brothers | |
35 | + | |
36 | + def self.create(name, age) | |
37 | + person = Person.new | |
38 | + person.name = name | |
39 | + person.age = age | |
40 | + person | |
41 | + end | |
42 | + | |
43 | + def brothers=(value) | |
44 | + @brothers = to_entity_array(value, Person) | |
45 | + end | |
46 | + | |
47 | + end | |
48 | + | |
49 | +end | |
0 | 50 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,32 @@ |
1 | +class ErrorTest < Test::Unit::TestCase | |
2 | + | |
3 | + def self.fixture | |
4 | + error = Kalibro::Entities::Error.new | |
5 | + error.message = 'Error message from ErrorTest' | |
6 | + element1 = StackTraceElementTest.fixture | |
7 | + element2 = StackTraceElementTest.fixture('errorTestMethod', 84) | |
8 | + error.stack_trace = [element1, element2] | |
9 | + error | |
10 | + end | |
11 | + | |
12 | + def self.fixture_hash | |
13 | + element1 = StackTraceElementTest.fixture_hash | |
14 | + element2 = StackTraceElementTest.fixture_hash('errorTestMethod', 84) | |
15 | + {:message => 'Error message from ErrorTest', | |
16 | + :stack_trace_element => [element1, element2]} | |
17 | + end | |
18 | + | |
19 | + def setup | |
20 | + @hash = self.class.fixture_hash | |
21 | + @error = self.class.fixture | |
22 | + end | |
23 | + | |
24 | + should 'create error from hash' do | |
25 | + assert_equal @error, Kalibro::Entities::Error.from_hash(@hash) | |
26 | + end | |
27 | + | |
28 | + should 'convert error to hash' do | |
29 | + assert_equal @hash, @error.to_hash | |
30 | + end | |
31 | + | |
32 | +end | |
0 | 33 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/metric_configuration_test.rb
0 → 100644
... | ... | @@ -0,0 +1,55 @@ |
1 | +class MetricConfigurationTest < Test::Unit::TestCase | |
2 | + | |
3 | + def self.amloc_configuration | |
4 | + range1 = RangeTest.amloc_excellent | |
5 | + range2 = RangeTest.amloc_bad | |
6 | + amloc = Kalibro::Entities::MetricConfiguration.new | |
7 | + amloc.metric = NativeMetricTest.amloc | |
8 | + amloc.code = 'amloc' | |
9 | + amloc.weight = 1.0 | |
10 | + amloc.aggregation_form = 'AVERAGE' | |
11 | + amloc.ranges = [range1, range2] | |
12 | + amloc | |
13 | + end | |
14 | + | |
15 | + def self.sc_configuration | |
16 | + sc = Kalibro::Entities::MetricConfiguration.new | |
17 | + sc.metric = CompoundMetricTest.sc | |
18 | + sc.code = 'sc' | |
19 | + sc.weight = 1.0 | |
20 | + sc.aggregation_form = 'AVERAGE' | |
21 | + sc | |
22 | + end | |
23 | + | |
24 | + def self.amloc_configuration_hash | |
25 | + range1 = RangeTest.amloc_excellent_hash | |
26 | + range2 = RangeTest.amloc_bad_hash | |
27 | + {:metric => NativeMetricTest.amloc_hash, | |
28 | + :code => 'amloc', :weight => 1.0, :aggregation_form => 'AVERAGE', | |
29 | + :range => [range1, range2]} | |
30 | + end | |
31 | + | |
32 | + def self.sc_configuration_hash | |
33 | + {:metric => CompoundMetricTest.sc_hash, | |
34 | + :code => 'sc', :weight => 1.0, :aggregation_form => 'AVERAGE'} | |
35 | + end | |
36 | + | |
37 | + def setup | |
38 | + @hash = self.class.amloc_configuration_hash | |
39 | + @range = self.class.amloc_configuration | |
40 | + end | |
41 | + | |
42 | + should 'create metric configuration from hash' do | |
43 | + assert_equal @range, Kalibro::Entities::MetricConfiguration.from_hash(@hash) | |
44 | + end | |
45 | + | |
46 | + should 'convert metric configuration to hash' do | |
47 | + assert_equal @hash, @range.to_hash | |
48 | + end | |
49 | + | |
50 | + should 'create appropriate metric type' do | |
51 | + assert self.class.amloc_configuration.metric.instance_of?(Kalibro::Entities::NativeMetric) | |
52 | + assert self.class.sc_configuration.metric.instance_of?(Kalibro::Entities::CompoundMetric) | |
53 | + end | |
54 | + | |
55 | +end | |
0 | 56 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/metric_result_test.rb
0 → 100644
... | ... | @@ -0,0 +1,54 @@ |
1 | +class MetricResultTest < Test::Unit::TestCase | |
2 | + | |
3 | + def self.amloc_result | |
4 | + result = Kalibro::Entities::MetricResult.new | |
5 | + result.metric = NativeMetricTest.amloc | |
6 | + result.value = 0.0 | |
7 | + result.descendent_results = [40.0, 42.0] | |
8 | + result.range = RangeTest.amloc_excellent | |
9 | + result | |
10 | + end | |
11 | + | |
12 | + def self.sc_result | |
13 | + result = Kalibro::Entities::MetricResult.new | |
14 | + result.metric = CompoundMetricTest.sc | |
15 | + result.value = 1.0 | |
16 | + result.descendent_results = [2.0, 42.0] | |
17 | + result | |
18 | + end | |
19 | + | |
20 | + def self.amloc_result_hash | |
21 | + {:metric => NativeMetricTest.amloc_hash, | |
22 | + :value => 0.0, :descendent_result => [40.0, 42.0], | |
23 | + :range => RangeTest.amloc_excellent_hash} | |
24 | + end | |
25 | + | |
26 | + def self.sc_result_hash | |
27 | + {:metric => CompoundMetricTest.sc_hash, | |
28 | + :value => 1.0, :descendent_result => [2.0, 42.0]} | |
29 | + end | |
30 | + | |
31 | + def setup | |
32 | + @hash = self.class.amloc_result_hash | |
33 | + @result = self.class.amloc_result | |
34 | + end | |
35 | + | |
36 | + should 'create metric result from hash' do | |
37 | + assert_equal @result, Kalibro::Entities::MetricResult.from_hash(@hash) | |
38 | + end | |
39 | + | |
40 | + should 'convert metric result to hash' do | |
41 | + assert_equal @hash, @result.to_hash | |
42 | + end | |
43 | + | |
44 | + should 'create appropriate metric type' do | |
45 | + assert self.class.amloc_result.metric.instance_of?(Kalibro::Entities::NativeMetric) | |
46 | + assert self.class.sc_result.metric.instance_of?(Kalibro::Entities::CompoundMetric) | |
47 | + end | |
48 | + | |
49 | + should 'convert single descendent result to array' do | |
50 | + @result.descendent_result = 1 | |
51 | + assert_equal [1], @result.descendent_results | |
52 | + end | |
53 | + | |
54 | +end | |
0 | 55 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/metric_test.rb
0 → 100644
... | ... | @@ -0,0 +1,22 @@ |
1 | +class MetricTest < Test::Unit::TestCase | |
2 | + | |
3 | + def setup | |
4 | + name = 'MetricTest metric' | |
5 | + scope = 'METHOD' | |
6 | + description = 'Metric created for testing' | |
7 | + @hash = {:name => name, :scope => scope, :description => description} | |
8 | + @metric = Kalibro::Entities::Metric.new | |
9 | + @metric.name = name | |
10 | + @metric.scope = scope | |
11 | + @metric.description = description | |
12 | + end | |
13 | + | |
14 | + should 'create metric from hash' do | |
15 | + assert_equal @metric, Kalibro::Entities::Metric.from_hash(@hash) | |
16 | + end | |
17 | + | |
18 | + should 'convert metric to hash' do | |
19 | + assert_equal @hash, @metric.to_hash | |
20 | + end | |
21 | + | |
22 | +end | |
0 | 23 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/module_node_test.rb
0 → 100644
... | ... | @@ -0,0 +1,41 @@ |
1 | +class ModuleNodeTest < Test::Unit::TestCase | |
2 | + | |
3 | + def self.qt_calculator_tree | |
4 | + node = Kalibro::Entities::ModuleNode.new | |
5 | + node.module = ModuleTest.qt_calculator | |
6 | + node.children = [new_node('Dialog', 'CLASS'), new_node('main', 'CLASS')] | |
7 | + node | |
8 | + end | |
9 | + | |
10 | + def self.new_node(name, granularity) | |
11 | + the_module = Kalibro::Entities::Module.new | |
12 | + the_module.name = name | |
13 | + the_module.granularity = granularity | |
14 | + node = Kalibro::Entities::ModuleNode.new | |
15 | + node.module = the_module | |
16 | + node | |
17 | + end | |
18 | + | |
19 | + def self.qt_calculator_tree_hash | |
20 | + {:module => ModuleTest.qt_calculator_hash, | |
21 | + :child => [ | |
22 | + {:module => {:name => 'Dialog', :granularity => 'CLASS'}}, | |
23 | + {:module => {:name => 'main', :granularity => 'CLASS'}} | |
24 | + ] | |
25 | + } | |
26 | + end | |
27 | + | |
28 | + def setup | |
29 | + @hash = self.class.qt_calculator_tree_hash | |
30 | + @node = self.class.qt_calculator_tree | |
31 | + end | |
32 | + | |
33 | + should 'create module node from hash' do | |
34 | + assert_equal @node, Kalibro::Entities::ModuleNode.from_hash(@hash) | |
35 | + end | |
36 | + | |
37 | + should 'convert children hash to array of ModuleNode' do | |
38 | + assert_equal @hash, @node.to_hash | |
39 | + end | |
40 | + | |
41 | +end | |
0 | 42 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/module_result_test.rb
0 → 100644
... | ... | @@ -0,0 +1,39 @@ |
1 | +require File.dirname(__FILE__) + '/../../../../../../test/test_helper' | |
2 | + | |
3 | +class ModuleResultTest < Test::Unit::TestCase | |
4 | + | |
5 | + def self.fixture | |
6 | + amloc_result = MetricResultTest.amloc_result | |
7 | + sc_result = MetricResultTest.sc_result | |
8 | + fixture = Kalibro::Entities::ModuleResult.new | |
9 | + fixture.module = ModuleTest.qt_calculator | |
10 | + fixture.date = DateTime.parse('Thu, 20 Oct 2011 18:26:43.151 +0000') | |
11 | + fixture.grade = 10.0 | |
12 | + fixture.metric_results = [amloc_result, sc_result] | |
13 | + fixture.compound_metrics_with_error = [CompoundMetricWithErrorTest.fixture] | |
14 | + fixture | |
15 | + end | |
16 | + | |
17 | + def self.fixture_hash | |
18 | + amloc_result = MetricResultTest.amloc_result_hash | |
19 | + sc_result = MetricResultTest.sc_result_hash | |
20 | + {:module => ModuleTest.qt_calculator_hash, | |
21 | + :date => DateTime.parse('Thu, 20 Oct 2011 18:26:43.151 +0000'), | |
22 | + :grade => 10.0, :metric_result => [amloc_result, sc_result], | |
23 | + :compound_metric_with_error => [CompoundMetricWithErrorTest.fixture_hash]} | |
24 | + end | |
25 | + | |
26 | + def setup | |
27 | + @hash = self.class.fixture_hash | |
28 | + @result = self.class.fixture | |
29 | + end | |
30 | + | |
31 | + should 'create module result from hash' do | |
32 | + assert_equal @result, Kalibro::Entities::ModuleResult.from_hash(@hash) | |
33 | + end | |
34 | + | |
35 | + should 'convert module result to hash' do | |
36 | + assert_equal @hash, @result.to_hash | |
37 | + end | |
38 | + | |
39 | +end | |
0 | 40 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/module_test.rb
0 → 100644
... | ... | @@ -0,0 +1,28 @@ |
1 | +class ModuleTest < Test::Unit::TestCase | |
2 | + | |
3 | + def self.qt_calculator | |
4 | + entity = Kalibro::Entities::Module.new | |
5 | + entity.name = ProjectTest.qt_calculator.name | |
6 | + entity.granularity = 'APPLICATION' | |
7 | + entity | |
8 | + end | |
9 | + | |
10 | + def self.qt_calculator_hash | |
11 | + name = ProjectTest.qt_calculator.name | |
12 | + {:name => name, :granularity => 'APPLICATION'} | |
13 | + end | |
14 | + | |
15 | + def setup | |
16 | + @hash = self.class.qt_calculator_hash | |
17 | + @module = self.class.qt_calculator | |
18 | + end | |
19 | + | |
20 | + should 'create module from hash' do | |
21 | + assert_equal @module, Kalibro::Entities::Module.from_hash(@hash) | |
22 | + end | |
23 | + | |
24 | + should 'convert module to hash' do | |
25 | + assert_equal @hash, @module.to_hash | |
26 | + end | |
27 | + | |
28 | +end | |
0 | 29 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/native_metric_test.rb
0 → 100644
... | ... | @@ -0,0 +1,44 @@ |
1 | +class NativeMetricTest < Test::Unit::TestCase | |
2 | + | |
3 | + def self.total_cof | |
4 | + total_cof = Kalibro::Entities::NativeMetric.new | |
5 | + total_cof.name = 'Total Coupling Factor' | |
6 | + total_cof.scope = 'APPLICATION' | |
7 | + total_cof.origin = 'Analizo' | |
8 | + total_cof.language = 'JAVA' | |
9 | + total_cof | |
10 | + end | |
11 | + | |
12 | + def self.amloc | |
13 | + total_cof = Kalibro::Entities::NativeMetric.new | |
14 | + total_cof.name = 'Average Method LOC' | |
15 | + total_cof.scope = 'CLASS' | |
16 | + total_cof.origin = 'Analizo' | |
17 | + total_cof.language = 'JAVA' | |
18 | + total_cof | |
19 | + end | |
20 | + | |
21 | + def self.total_cof_hash | |
22 | + {:name => 'Total Coupling Factor', :scope => 'APPLICATION', | |
23 | + :origin => 'Analizo', :language => 'JAVA'} | |
24 | + end | |
25 | + | |
26 | + def self.amloc_hash | |
27 | + {:name => 'Average Method LOC', :scope => 'CLASS', | |
28 | + :origin => 'Analizo', :language => 'JAVA'} | |
29 | + end | |
30 | + | |
31 | + def setup | |
32 | + @hash = self.class.amloc_hash | |
33 | + @metric = self.class.amloc | |
34 | + end | |
35 | + | |
36 | + should 'create native metric from hash' do | |
37 | + assert_equal @metric, Kalibro::Entities::NativeMetric.from_hash(@hash) | |
38 | + end | |
39 | + | |
40 | + should 'convert native metric to hash' do | |
41 | + assert_equal @hash, @metric.to_hash | |
42 | + end | |
43 | + | |
44 | +end | |
0 | 45 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/project_result_test.rb
0 → 100644
... | ... | @@ -0,0 +1,42 @@ |
1 | +class ProjectResultTest < Test::Unit::TestCase | |
2 | + | |
3 | + def self.qt_calculator | |
4 | + result = Kalibro::Entities::ProjectResult.new | |
5 | + result.project = ProjectTest.qt_calculator | |
6 | + result.date = DateTime.parse('Thu, 20 Oct 2011 18:26:43.151 +0000') | |
7 | + result.load_time = 14878 | |
8 | + result.analysis_time = 1022 | |
9 | + result.source_tree = ModuleNodeTest.qt_calculator_tree | |
10 | + result | |
11 | + end | |
12 | + | |
13 | + def self.qt_calculator_hash | |
14 | + {:project => ProjectTest.qt_calculator_hash, | |
15 | + :date => DateTime.parse('Thu, 20 Oct 2011 18:26:43.151 +0000'), | |
16 | + :load_time => 14878, | |
17 | + :analysis_time => 1022, | |
18 | + :source_tree => ModuleNodeTest.qt_calculator_tree_hash} | |
19 | + end | |
20 | + | |
21 | + def setup | |
22 | + @hash = self.class.qt_calculator_hash | |
23 | + @result = self.class.qt_calculator | |
24 | + end | |
25 | + | |
26 | + should 'create project result from hash' do | |
27 | + assert_equal @result, Kalibro::Entities::ProjectResult.from_hash(@hash) | |
28 | + end | |
29 | + | |
30 | + should 'convert project result to hash' do | |
31 | + assert_equal @hash, @result.to_hash | |
32 | + end | |
33 | + | |
34 | + should 'retrieve formatted load time' do | |
35 | + assert_equal '00:00:14', @result.formatted_load_time | |
36 | + end | |
37 | + | |
38 | + should 'retrieve formatted analysis time' do | |
39 | + assert_equal '00:00:01', @result.formatted_analysis_time | |
40 | + end | |
41 | + | |
42 | +end | |
0 | 43 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/project_test.rb
0 → 100644
... | ... | @@ -0,0 +1,35 @@ |
1 | +class ProjectTest < Test::Unit::TestCase | |
2 | + | |
3 | + def self.qt_calculator | |
4 | + project = Kalibro::Entities::Project.new | |
5 | + project.name = 'Qt-Calculator by ProjectTest' | |
6 | + project.license = 'GPL' | |
7 | + project.description = 'Calculator for Qt' | |
8 | + project.repository = RepositoryTest.qt_calculator | |
9 | + project.configuration_name = 'Kalibro for Java' | |
10 | + project.state = 'READY' | |
11 | + project | |
12 | + end | |
13 | + | |
14 | + def self.qt_calculator_hash | |
15 | + {:name => 'Qt-Calculator by ProjectTest', :license => 'GPL', | |
16 | + :description => 'Calculator for Qt', | |
17 | + :repository => RepositoryTest.qt_calculator_hash, | |
18 | + :configuration_name => 'Kalibro for Java', | |
19 | + :state => 'READY'} | |
20 | + end | |
21 | + | |
22 | + def setup | |
23 | + @hash = self.class.qt_calculator_hash | |
24 | + @project = self.class.qt_calculator | |
25 | + end | |
26 | + | |
27 | + should 'create project from hash' do | |
28 | + assert_equal @project, Kalibro::Entities::Project.from_hash(@hash) | |
29 | + end | |
30 | + | |
31 | + should 'convert project to hash' do | |
32 | + assert_equal @hash, @project.to_hash | |
33 | + end | |
34 | + | |
35 | +end | |
0 | 36 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,48 @@ |
1 | +class RangeTest < Test::Unit::TestCase | |
2 | + | |
3 | + Infinity = 1.0/0.0 | |
4 | + | |
5 | + def self.amloc_excellent | |
6 | + range = Kalibro::Entities::Range.new | |
7 | + range.beginning = 0.0 | |
8 | + range.end = 7.0 | |
9 | + range.label = 'Excellent' | |
10 | + range.grade = 10.0 | |
11 | + range.color = 'ff00ff00' | |
12 | + range | |
13 | + end | |
14 | + | |
15 | + def self.amloc_bad | |
16 | + range = Kalibro::Entities::Range.new | |
17 | + range.beginning = 19.5 | |
18 | + range.end = Infinity | |
19 | + range.label = 'Bad' | |
20 | + range.grade = 0.0 | |
21 | + range.color = 'ffff0000' | |
22 | + range | |
23 | + end | |
24 | + | |
25 | + def self.amloc_excellent_hash | |
26 | + {:beginning => 0.0, :end => 7.0, :label => 'Excellent', | |
27 | + :grade => 10.0, :color => 'ff00ff00'} | |
28 | + end | |
29 | + | |
30 | + def self.amloc_bad_hash | |
31 | + {:beginning => 19.5, :end => Infinity, :label => 'Bad', | |
32 | + :grade => 0.0, :color => 'ffff0000'} | |
33 | + end | |
34 | + | |
35 | + def setup | |
36 | + @hash = self.class.amloc_bad_hash | |
37 | + @range = self.class.amloc_bad | |
38 | + end | |
39 | + | |
40 | + should 'create range from hash' do | |
41 | + assert_equal @range, Kalibro::Entities::Range.from_hash(@hash) | |
42 | + end | |
43 | + | |
44 | + should 'convert range to hash' do | |
45 | + assert_equal @hash, @range.to_hash | |
46 | + end | |
47 | + | |
48 | +end | |
0 | 49 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/repository_test.rb
0 → 100644
... | ... | @@ -0,0 +1,28 @@ |
1 | +class RepositoryTest < Test::Unit::TestCase | |
2 | + | |
3 | + def self.qt_calculator | |
4 | + repository = Kalibro::Entities::Repository.new | |
5 | + repository.type = 'SUBVERSION' | |
6 | + repository.address = 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator' | |
7 | + repository | |
8 | + end | |
9 | + | |
10 | + def self.qt_calculator_hash | |
11 | + {:type => 'SUBVERSION', | |
12 | + :address => 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator'} | |
13 | + end | |
14 | + | |
15 | + def setup | |
16 | + @hash = self.class.qt_calculator_hash | |
17 | + @repository = self.class.qt_calculator | |
18 | + end | |
19 | + | |
20 | + should 'create repository from hash' do | |
21 | + assert_equal @repository, Kalibro::Entities::Repository.from_hash(@hash) | |
22 | + end | |
23 | + | |
24 | + should 'convert repository to hash' do | |
25 | + assert_equal @hash, @repository.to_hash | |
26 | + end | |
27 | + | |
28 | +end | |
0 | 29 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/stack_trace_element_test.rb
0 → 100644
... | ... | @@ -0,0 +1,32 @@ |
1 | +class StackTraceElementTest < Test::Unit::TestCase | |
2 | + | |
3 | + def self.fixture(method_name = 'stackTraceElementTestMethod', line_number = 42) | |
4 | + stack_trace_element = Kalibro::Entities::StackTraceElement.new | |
5 | + stack_trace_element.declaring_class = 'org.declaring.Class' | |
6 | + stack_trace_element.method_name = method_name | |
7 | + stack_trace_element.file_name = 'Class.java' | |
8 | + stack_trace_element.line_number = line_number | |
9 | + stack_trace_element | |
10 | + end | |
11 | + | |
12 | + def self.fixture_hash(method_name = 'stackTraceElementTestMethod', line_number = 42) | |
13 | + {:declaring_class => 'org.declaring.Class', | |
14 | + :method_name => method_name, | |
15 | + :file_name => 'Class.java', | |
16 | + :line_number => line_number} | |
17 | + end | |
18 | + | |
19 | + def setup | |
20 | + @hash = self.class.fixture_hash | |
21 | + @stack_trace_element = self.class.fixture | |
22 | + end | |
23 | + | |
24 | + should 'create stack trace element from hash' do | |
25 | + assert_equal @stack_trace_element, Kalibro::Entities::StackTraceElement.from_hash(@hash) | |
26 | + end | |
27 | + | |
28 | + should 'convert stack trace element to hash' do | |
29 | + assert_equal @hash, @stack_trace_element.to_hash | |
30 | + end | |
31 | + | |
32 | +end | |
0 | 33 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
0 → 100644
... | ... | @@ -0,0 +1,42 @@ |
1 | +class ProjectContentTest < Test::Unit::TestCase | |
2 | + | |
3 | + def setup | |
4 | + @project = ProjectTest.qt_calculator | |
5 | + @content = MezuroPlugin::ProjectContent.new | |
6 | + @content.name = @project.name | |
7 | + @content.license = @project.license | |
8 | + @content.description = @project.description | |
9 | + @content.repository_type = @project.repository.type | |
10 | + @content.repository_url = @project.repository.address | |
11 | + @content.configuration_name = @project.configuration_name | |
12 | + end | |
13 | + | |
14 | + should 'be an article' do | |
15 | + assert_kind_of Article, @content | |
16 | + end | |
17 | + | |
18 | + should 'provide proper short description' do | |
19 | + assert_equal 'Kalibro project', MezuroPlugin::ProjectContent.short_description | |
20 | + end | |
21 | + | |
22 | + should 'provide proper description' do | |
23 | + assert_equal 'Software project tracked by Kalibro', MezuroPlugin::ProjectContent.description | |
24 | + end | |
25 | + | |
26 | + should 'have an html view' do | |
27 | + assert_not_nil @content.to_html | |
28 | + end | |
29 | + | |
30 | + should 'run send project to service on after_save callback' do | |
31 | + @content.expects :send_project_to_service | |
32 | + @content.run_callbacks :after_save | |
33 | + end | |
34 | + | |
35 | + should 'send correct project to service' do | |
36 | + client = mock | |
37 | + Kalibro::Client::ProjectClient.expects(:new).returns(client) | |
38 | + client.expects(:save).with(@project) | |
39 | + @content.send :send_project_to_service | |
40 | + end | |
41 | + | |
42 | +end | |
0 | 43 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,31 @@ |
1 | +class MezuroPluginTest < Test::Unit::TestCase | |
2 | + | |
3 | + def setup | |
4 | + @plugin = MezuroPlugin.new | |
5 | + end | |
6 | + | |
7 | + should 'be a noosfero plugin' do | |
8 | + assert_kind_of Noosfero::Plugin, @plugin | |
9 | + end | |
10 | + | |
11 | + should 'have name' do | |
12 | + assert_equal 'Mezuro', MezuroPlugin.plugin_name | |
13 | + end | |
14 | + | |
15 | + should 'have description' do | |
16 | + assert_equal _('A metric analizer plugin.'), MezuroPlugin.plugin_description | |
17 | + end | |
18 | + | |
19 | + should 'have project content type' do | |
20 | + assert_equal MezuroPlugin::ProjectContent, @plugin.content_types | |
21 | + end | |
22 | + | |
23 | + should 'have stylesheet' do | |
24 | + assert @plugin.stylesheet? | |
25 | + end | |
26 | + | |
27 | + should 'list javascript files' do | |
28 | + assert_equal 'javascripts/collapsable.js', @plugin.js_files | |
29 | + end | |
30 | + | |
31 | +end | |
0 | 32 | \ No newline at end of file | ... | ... |