module TestHelpers
  module FakeWeb
    module Utilization

      def fake_backend_utilization(report, application_id = @application_id, service_id = @service_id, provider_key = @provider_key)
        body = %{
<?xml version="1.0" encoding="UTF-8"?>
<utilization> }
        #max_utilization = report[:max_utilization]
        #max_usage_report = report[:max_usage_report]
        #body << %{<max_utilization value="#{max_utilization}"/>} if max_utilization
        #body << %{<max_usage_report period="#{max_usage_report[:period]}" metric_name="#{max_usage_report[:name]}" max_value="#{max_usage_report[:max]}" current_value="#{max_usage_report[:current]}"/>} if max_usage_report.present?
        body << %{
  <usage_reports>
    #{ report[:usage_reports].map do |report|
         %{<usage_report period="#{report[:period]}" metric_name="#{report[:name]}" max_value="#{report[:max]}" current_value="#{report[:current]}"/>}
       end.join }
  </usage_reports> }
        body << '</utilization>'

        ::FakeWeb.register_uri :get, fake_app_url("/utilization.xml?provider_key=#{provider_key}&service_id=#{service_id}", application_id),
                               :status => [200, 'OK'], :content_type => CONTENT_TYPE,
                               :body => body
      end
    end
  end
end


