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