Commit e03ad5db6eb5da1549d65a238be4a1559ea348f4
Committed by
Carlos Morais
1 parent
cbdb8c12
Exists in
master
and in
28 other branches
[mezuro] Creating MetricConfigurationClient
Showing
3 changed files
with
78 additions
and
0 deletions
Show diff stats
plugins/mezuro/lib/kalibro/client/metric_configuration_client.rb
0 → 100644
| @@ -0,0 +1,28 @@ | @@ -0,0 +1,28 @@ | ||
| 1 | +class Kalibro::Client::MetricConfigurationClient | ||
| 2 | + | ||
| 3 | + def initialize | ||
| 4 | + @port = Kalibro::Client::Port.new('MetricConfiguration') | ||
| 5 | + end | ||
| 6 | + | ||
| 7 | + def save(metric_configuration, configuration_name) | ||
| 8 | + @port.request(:save_metric_configuration, { | ||
| 9 | + :metric_configuration => metric_configuration.to_hash, | ||
| 10 | + :configuration_name => configuration_name}) | ||
| 11 | + end | ||
| 12 | + | ||
| 13 | + def metric_configuration(configuration_name, metric_name) | ||
| 14 | + hash = @port.request(:get_metric_configuration, { | ||
| 15 | + :configuration_name => configuration_name, | ||
| 16 | + :metric_name => metric_name | ||
| 17 | + })[:metric_configuration] | ||
| 18 | + Kalibro::Entities::MetricConfiguration.from_hash(hash) | ||
| 19 | + end | ||
| 20 | + | ||
| 21 | + def remove (configuration_name, metric_name) | ||
| 22 | + @port.request(:remove_metric_configuration, { | ||
| 23 | + :configuration_name => configuration_name, | ||
| 24 | + :metric_name=> metric_name | ||
| 25 | + }) | ||
| 26 | + end | ||
| 27 | + | ||
| 28 | +end | ||
| 0 | \ No newline at end of file | 29 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/entity.rb
| @@ -24,6 +24,12 @@ class Kalibro::Entities::Entity | @@ -24,6 +24,12 @@ class Kalibro::Entities::Entity | ||
| 24 | fields.each do |field| | 24 | fields.each do |field| |
| 25 | field_value = self.get(field) | 25 | field_value = self.get(field) |
| 26 | hash[field] = convert_to_hash(field_value) if ! field_value.nil? | 26 | hash[field] = convert_to_hash(field_value) if ! field_value.nil? |
| 27 | +# TODO | ||
| 28 | +# if field_value is object | ||
| 29 | +# hash[:attributes!] += {field.to_sym => | ||
| 30 | +# {'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | ||
| 31 | +# 'xsi:type' => 'kalibro:' + field_value_type + 'Xml' } } | ||
| 32 | +# end | ||
| 27 | end | 33 | end |
| 28 | hash | 34 | hash |
| 29 | end | 35 | end |
plugins/mezuro/test/unit/kalibro/client/metric_configuration_client_test.rb
0 → 100644
| @@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
| 1 | +require "test_helper" | ||
| 2 | + | ||
| 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures" | ||
| 4 | + | ||
| 5 | +class MetricConfigurationClientTest < ActiveSupport::TestCase | ||
| 6 | + | ||
| 7 | + def setup | ||
| 8 | + @port = mock | ||
| 9 | + Kalibro::Client::Port.expects(:new).with('MetricConfiguration').returns(@port) | ||
| 10 | + @client = Kalibro::Client::MetricConfigurationClient.new | ||
| 11 | + end | ||
| 12 | + | ||
| 13 | + should 'save metric configuration' do | ||
| 14 | + configuration = MetricConfigurationFixtures.amloc_configuration | ||
| 15 | + @port.expects(:request).with(:save_metric_configuration, { | ||
| 16 | + :metric_configuration => configuration.to_hash, | ||
| 17 | + :configuration_name => 'x' | ||
| 18 | + }) | ||
| 19 | + @client.save(configuration, 'x') | ||
| 20 | + end | ||
| 21 | + | ||
| 22 | + should 'get metric configuration by name' do | ||
| 23 | + configuration = MetricConfigurationFixtures.amloc_configuration | ||
| 24 | + request_body = { | ||
| 25 | + :configuration_name => 'configuration.name', | ||
| 26 | + :metric_name => configuration.metric.name | ||
| 27 | + } | ||
| 28 | + response_hash = {:metric_configuration => configuration.to_hash} | ||
| 29 | + @port.expects(:request).with(:get_metric_configuration, request_body).returns(response_hash) | ||
| 30 | + assert_equal configuration, @client.metric_configuration('configuration.name', configuration.metric.name) | ||
| 31 | + end | ||
| 32 | + | ||
| 33 | + should 'remove metric configuration by name' do | ||
| 34 | + metric_name = 'MetricConfigurationClientTest' | ||
| 35 | + configuration_name = 'xxxx' | ||
| 36 | + request_body = { | ||
| 37 | + :configuration_name => configuration_name, | ||
| 38 | + :metric_name => metric_name | ||
| 39 | + } | ||
| 40 | + @port.expects(:request).with(:remove_metric_configuration, request_body) | ||
| 41 | + @client.remove(configuration_name, metric_name) | ||
| 42 | + end | ||
| 43 | + | ||
| 44 | +end | ||
| 0 | \ No newline at end of file | 45 | \ No newline at end of file |