Class: SippyCup::XMLScenario

Inherits:
Object
  • Object
show all
Defined in:
lib/sippy_cup/xml_scenario.rb

Overview

A representation of a SIPp XML scenario

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, xml, media, args = {}) ⇒ XMLScenario

Create a scenario instance

Parameters:

  • name (String)

    The scenario’s name

  • xml (String)

    The XML document representing the scenario

  • media (String)

    The media to be invoked by the scenario in PCAP format

  • args (Hash) (defaults to: {})

    options to customise the scenario. @see Scenario#initialize.



20
21
22
23
# File 'lib/sippy_cup/xml_scenario.rb', line 20

def initialize(name, xml, media, args = {})
  @xml, @media = xml, media
  @scenario_options = args.merge name: name
end

Instance Attribute Details

#scenario_optionsHash (readonly)

Returns The options the scenario was created with, either from a manifest or passed as overrides.

Returns:

  • (Hash)

    The options the scenario was created with, either from a manifest or passed as overrides



10
11
12
# File 'lib/sippy_cup/xml_scenario.rb', line 10

def scenario_options
  @scenario_options
end

Instance Method Details

#to_tmpfilesHash<Symbol => Tempfile>

Write compiled Scenario XML and PCAP media to tempfiles.

These will automatically be closed and deleted once they have gone out of scope, and can be used to execute the scenario without leaving stuff behind.

Returns:

  • (Hash<Symbol => Tempfile>)

    handles to created Tempfiles at :scenario and :media

See Also:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sippy_cup/xml_scenario.rb', line 34

def to_tmpfiles
  scenario_file = Tempfile.new 'scenario'
  scenario_file.write @xml
  scenario_file.rewind

  if @media
    media_file = Tempfile.new 'media'
    media_file.write @media
    media_file.rewind
  else
    media_file = nil
  end

  {scenario: scenario_file, media: media_file}
end

#to_xmlString

Dump the scenario to a SIPp XML string

Returns:

  • (String)

    the SIPp XML scenario



54
55
56
# File 'lib/sippy_cup/xml_scenario.rb', line 54

def to_xml
  @xml
end