Commit f909e2e2c722acff46ab41ae882b179d7062b345
Committed by
Carlos Morais
1 parent
3543b6b5
Exists in
master
and in
29 other branches
[mezuro] Functional tests and bug fixes for client
Showing
6 changed files
with
66 additions
and
8 deletions
Show diff stats
plugins/mezuro/lib/kalibro/client/port.rb
| ... | ... | @@ -7,7 +7,8 @@ end |
| 7 | 7 | class Kalibro::Client::Port |
| 8 | 8 | |
| 9 | 9 | def initialize(endpoint) |
| 10 | - @client = Savon::Client.new("#{service_address}#{endpoint}Endpoint/?wsdl") | |
| 10 | + @endpoint = endpoint | |
| 11 | + initialize_client | |
| 11 | 12 | end |
| 12 | 13 | |
| 13 | 14 | def service_address |
| ... | ... | @@ -18,9 +19,20 @@ class Kalibro::Client::Port |
| 18 | 19 | @service_address |
| 19 | 20 | end |
| 20 | 21 | |
| 22 | + def service_address=(address) | |
| 23 | + @service_address = address | |
| 24 | + initialize_client | |
| 25 | + end | |
| 26 | + | |
| 21 | 27 | def request(action, request_body = nil) |
| 22 | 28 | response = @client.request(:kalibro, action) { soap.body = request_body } |
| 23 | 29 | response.to_hash["#{action}_response".to_sym] |
| 24 | 30 | end |
| 25 | 31 | |
| 32 | + private | |
| 33 | + | |
| 34 | + def initialize_client | |
| 35 | + @client = Savon::Client.new("#{service_address}#{@endpoint}Endpoint/?wsdl") | |
| 36 | + end | |
| 37 | + | |
| 26 | 38 | end | ... | ... |
plugins/mezuro/lib/kalibro/entities/metric_configuration.rb
plugins/mezuro/lib/kalibro/entities/range.rb
| ... | ... | @@ -2,4 +2,14 @@ class Kalibro::Entities::Range < Kalibro::Entities::Entity |
| 2 | 2 | |
| 3 | 3 | attr_accessor :beginning, :end, :label, :grade, :color, :comments |
| 4 | 4 | |
| 5 | + def beginning=(value) | |
| 6 | + @beginning = value.to_f | |
| 7 | + @beginning = -1.0/0.0 if value == "-INF" | |
| 8 | + end | |
| 9 | + | |
| 10 | + def end=(value) | |
| 11 | + @end = value.to_f | |
| 12 | + @end = 1.0/0.0 if value == "INF" | |
| 13 | + end | |
| 14 | + | |
| 5 | 15 | end |
| 6 | 16 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/functional/base_tool_client_test.rb
| 1 | 1 | require "test_helper" |
| 2 | - | |
| 3 | -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/native_metric_fixtures" | |
| 2 | +require File.dirname(__FILE__) + '/fake_port' | |
| 4 | 3 | |
| 5 | 4 | class BaseToolClientTest < ActiveSupport::TestCase |
| 6 | 5 | |
| 7 | 6 | def setup |
| 7 | + fake_port = FakePort.new('BaseTool') | |
| 8 | + Kalibro::Client::Port.expects(:new).with('BaseTool').returns(fake_port) | |
| 8 | 9 | @client = Kalibro::Client::BaseToolClient.new |
| 9 | 10 | end |
| 10 | 11 | |
| ... | ... | @@ -14,9 +15,15 @@ class BaseToolClientTest < ActiveSupport::TestCase |
| 14 | 15 | |
| 15 | 16 | should 'get base tool by name' do |
| 16 | 17 | analizo = @client.base_tool('Analizo') |
| 17 | - amloc = NativeMetricFixtures.amloc | |
| 18 | - amloc.languages = ["C", "CPP", "JAVA"] | |
| 19 | - assert_includes analizo.supported_metrics, amloc | |
| 18 | + assert_equal 'Analizo', analizo.name | |
| 19 | + assert_equal 'Analizo description', analizo.description | |
| 20 | + assert_equal 1, analizo.supported_metrics.size | |
| 21 | + metric = analizo.supported_metrics[0] | |
| 22 | + assert_equal 'Analizo', metric.origin | |
| 23 | + assert_equal 'Analizo metric', metric.name | |
| 24 | + assert_equal 'Analizo metric description', metric.description | |
| 25 | + assert_equal 'METHOD', metric.scope | |
| 26 | + assert_equal ['CPP', 'JAVA'], metric.languages | |
| 20 | 27 | end |
| 21 | 28 | |
| 22 | 29 | end |
| 23 | 30 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/functional/metric_configuration_client_test.rb
| 1 | 1 | require "test_helper" |
| 2 | +require File.dirname(__FILE__) + '/fake_port' | |
| 2 | 3 | |
| 3 | 4 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures" |
| 4 | 5 | |
| 5 | 6 | class MetricConfigurationClientTest < ActiveSupport::TestCase |
| 6 | 7 | |
| 7 | 8 | def setup |
| 9 | + fake_port = FakePort.new('MetricConfiguration') | |
| 10 | + Kalibro::Client::Port.expects(:new).with('MetricConfiguration').returns(fake_port) | |
| 8 | 11 | @client = Kalibro::Client::MetricConfigurationClient.new |
| 9 | 12 | end |
| 10 | 13 | |
| ... | ... | @@ -14,8 +17,23 @@ class MetricConfigurationClientTest < ActiveSupport::TestCase |
| 14 | 17 | end |
| 15 | 18 | |
| 16 | 19 | should 'get metric configuration by name' do |
| 17 | - configuration = MetricConfigurationFixtures.amloc_configuration | |
| 18 | - assert_equal configuration, @client.metric_configuration('Configuration X', 'Metric X') | |
| 20 | + configuration = @client.metric_configuration('C', 'native') | |
| 21 | + assert_equal 'metricOfC', configuration.code | |
| 22 | + assert_equal 1.0, configuration.weight | |
| 23 | + assert_equal 'AVERAGE', configuration.aggregation_form | |
| 24 | + assert_equal 1, configuration.ranges.size | |
| 25 | + | |
| 26 | + range = configuration.ranges[0] | |
| 27 | + assert_equal -1.0/0.0, range.beginning | |
| 28 | + assert_equal 1.0/0.0, range.end | |
| 29 | + | |
| 30 | + metric = configuration.metric | |
| 31 | + puts metric | |
| 32 | + assert metric.is_a?(Kalibro::Entities::NativeMetric) | |
| 33 | + assert_equal 'Metric of C', metric.name | |
| 34 | + assert_equal 'METHOD', metric.scope | |
| 35 | + assert_equal ['JAVA'], metric.languages | |
| 36 | + assert_equal 'Metric of C description', metric.description | |
| 19 | 37 | end |
| 20 | 38 | |
| 21 | 39 | should 'remove metric configuration by name' do | ... | ... |