Class UniverseParserTest
In: test/universe_parser_test.rb
Parent: Test::Unit::TestCase

Methods

Public Instance methods

[Source]

# File test/universe_parser_test.rb, line 32
  def setup
    @parser = Core::Providers::Multiverse::Parser.new
    $logger = Logger.new(STDOUT)
    $logger.level = Logger::DEBUG
    $logger.level = Logger::FATAL
    $logger.datetime_format = '%H:%M:%S'
  end

Check that exceptions caused by malformed XML are properly captured by the parser

[Source]

# File test/universe_parser_test.rb, line 161
  def test_malformed
    xml_ko ="    <universe>\n      <meta\n        <cr---eator />\n      </meta>\n      //-->\n    </universe>\n" 
    assert_raises(Multiverse::UniverseParsingException) do
      universe = @parser.parse( :string => xml_ko )
    end
  end
 Check that the universe contains the bare minimun meta info. requirements

 in order for the universe to be usable:

 * name
 * uid

[Source]

# File test/universe_parser_test.rb, line 53
  def test_meta_basics
    # check that meta info contains name and uid, and that both are valid.
    # checking the uniqueness of uid is done in the multiverse test case
    xml_ok ="    <universe>\n      <meta>\n        <name>Networking</name>\n        <uid>baa4f8f55d68308fdbbed8c2f1eccfc3640f0cf9</uid>\n      </meta>\n    </universe>\n" 
    xml_ko ="    <universe>\n      <meta>\n        <uid></uid>\n        <creator name=\"etd\" email=\"etd[ at ]nomejortu- dot -com\" />\n        <url>http://dradis.nomejortu.com/</url>\n      </meta>\n    </universe>\n" 

    assert_nothing_raised do
      universe = @parser.parse( :string => xml_ok )
    end
    
    assert_raises(Multiverse::UniverseParsingException) do
      universe = @parser.parse( :string => xml_ko )
    end
  end

Check that the creator tag is properly parsed, both name and email are optional attributes

[Source]

# File test/universe_parser_test.rb, line 113
  def test_meta_creator
    xml_ok1 ="    <universe>\n      <meta>\n        <name>Networking</name>\n        <uid>baa4f8f55d68308fdbbed8c2f1eccfc3640f0cf9</uid>\n        <creator name=\"etd\" />\n      </meta>\n    </universe>\n" 
    xml_ok2 ="    <universe>\n      <meta>\n        <name>Networking</name>\n        <uid>baa4f8f55d68308fdbbed8c2f1eccfc3640f0cf9</uid>\n        <creator email=\"etd[ at ]nomejortu- dot -com\" />\n      </meta>\n    </universe>\n" 
    xml_ko ="    <universe>\n      <meta>\n        <name>Networking</name>\n        <uid>baa4f8f55d68308fdbbed8c2f1eccfc3640f0cf9</uid>\n        <creator />\n      </meta>\n    </universe>\n" 
    universe1 = @parser.parse( :string => xml_ok1 )
    assert_equal 3, universe1.meta.keys.size
    assert_equal 'etd', universe1.meta[:creator][:name]
    assert_nil universe1.meta[:creator].fetch(:email, nil)

    universe2 = @parser.parse( :string => xml_ok2 )
    assert_equal 3, universe2.meta.keys.size
    assert_equal 'etd[ at ]nomejortu- dot -com', universe2.meta[:creator][:email]
    assert_nil universe2.meta[:creator].fetch(:name, nil)

    assert_raises(Multiverse::UniverseParsingException) do
      universe3 = @parser.parse( :string => xml_ko )
    end    
  end

Check that all the elements of the meta section are properly parsed

[Source]

# File test/universe_parser_test.rb, line 86
  def test_meta_full
    xml_ok ="    <universe>\n      <meta>\n        <name>Networking</name>\n        <version>1.0</version>\n        <namespace>net</namespace>\n        <uid>baa4f8f55d68308fdbbed8c2f1eccfc3640f0cf9</uid>\n        <creator name=\"etd\" email=\"etd[ at ]nomejortu- dot -com\" />\n        <url>http://dradis.nomejortu.com/</url>\n      </meta>\n    </universe>\n" 
    universe = @parser.parse( :string => xml_ok )
    assert_equal 6, universe.meta.keys.size
    assert_equal 'Networking', universe.meta[:name]
    assert_equal '1.0', universe.meta[:version]
    assert_equal 'net', universe.meta[:namespace]
    assert_equal 'baa4f8f55d68308fdbbed8c2f1eccfc3640f0cf9', universe.meta[:uid]
    assert_equal 'etd', universe.meta[:creator][:name]
    assert_equal 'etd[ at ]nomejortu- dot -com', universe.meta[:creator][:email]
    assert_equal 'http://dradis.nomejortu.com/', universe.meta[:url]
  end

Check that the parser identifies all the nodes in the universe definition file

[Source]

# File test/universe_parser_test.rb, line 42
  def test_node_count
    file = File.dirname(__FILE__) + '/../multiverse/networking/universe.xml'
    universe = @parser.parse( :file => file )
        
    assert_equal 4, universe.nodes.size
  end

Check that sections that are not understood by the framework are not parsed and do not raise exceptions

[Source]

# File test/universe_parser_test.rb, line 178
  def test_unknow_section
    xml_ok ="    <universe>\n      <meta>\n        <name>Networking</name>\n        <uid>baa4f8f55d68308fdbbed8c2f1eccfc3640f0cf9</uid>\n        <creator email=\"etd[ at ]nomejortu- dot -com\" />\n      </meta>\n      <etdsoft>\n        <!-- this section must be ignored by the parser -->\n      </etdsoft>\n      <nodes>\n        <node type=\"1\" name=\"Host\" />\n        <node type=\"2\" name=\"Protocol\" />\n      </nodes>      \n    </universe>\n" 
    universe = nil
    assert_nothing_raised do
      universe = @parser.parse( :string => xml_ok )
    end    
    assert_equal 2, universe.nodes.size
  end

[Validate]