Sha256: 5eb616dff60dce3d9763b1b8a6e5fdda7f679af23074e4a64301e3ab6820e7d2

Contents?: true

Size: 1.84 KB

Versions: 12

Compression:

Stored size: 1.84 KB

Contents

module JmeterPerf
  class ExtendedDSL < DSL
    def http_request(*args, &)
      params = args.shift || {}
      params = {url: params}.merge(args.shift || {}) if params.is_a?(String)

      params[:method] ||= case __callee__.to_s
      when "visit"
        "GET"
      when "submit"
        "POST"
      else
        __callee__.to_s.upcase
      end

      params[:name] ||= params[:url]

      parse_http_request(params)

      if params[:sample]
        transaction name: params[:name], parent: true do
          loops count: params[:sample].to_i do
            params.delete(:sample)
            attach_node(http_request_node(params), &block)
          end
        end
      else
        attach_node(http_request_node(params), &)
      end
    end

    def http_request_node(params)
      JmeterPerf::DSL::HTTPRequest.new(params).tap do |node|
        if params[:implementation]
          node.doc.children.first.add_child(
            Nokogiri::XML(JmeterPerf::Helpers::String.strip_heredoc(
              <<-EOS
                <stringProp name="HTTPSampler.implementation">#{params[:implementation]}</stringProp>
              EOS
            )).children
          )
        end

        if params[:comments]
          node.doc.children.first.add_child(
            Nokogiri::XML(JmeterPerf::Helpers::String.strip_heredoc(
              <<-EOS
                <stringProp name="TestPlan.comments">#{params[:comments]}</stringProp>
              EOS
            )).children
          )
        end
      end
    end

    alias_method :request, :http_request
    alias_method :get, :http_request
    alias_method :visit, :http_request
    alias_method :post, :http_request
    alias_method :submit, :http_request
    alias_method :delete, :http_request
    alias_method :patch, :http_request
    alias_method :put, :http_request
    alias_method :head, :http_request
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
jmeter_perf-1.1.1 lib/jmeter_perf/extend/samplers/http_request.rb
jmeter_perf-1.1.0 lib/jmeter_perf/extend/samplers/http_request.rb
jmeter_perf-1.0.10 lib/jmeter_perf/extend/samplers/http_request.rb
jmeter_perf-1.0.9 lib/jmeter_perf/extend/samplers/http_request.rb
jmeter_perf-1.0.8 lib/jmeter_perf/extend/samplers/http_request.rb
jmeter_perf-1.0.7 lib/jmeter_perf/extend/samplers/http_request.rb
jmeter_perf-1.0.6 lib/jmeter_perf/extend/samplers/http_request.rb
jmeter_perf-1.0.5 lib/jmeter_perf/extend/samplers/http_request.rb
jmeter_perf-1.0.4 lib/jmeter_perf/extend/samplers/http_request.rb
jmeter_perf-1.0.2 lib/jmeter_perf/extend/samplers/http_request.rb
jmeter_perf-1.0.1 lib/jmeter_perf/extend/samplers/http_request.rb
jmeter_perf-1.0.0 lib/jmeter_perf/extend/samplers/http_request.rb