Module: TDriver::Abstraction::TestObjectAdapter

Included in:
OptimizedXML::TestObjectAdapter, TestObjectAdapter
Defined in:
lib/tdriver/base/test_object/xml/abstraction.rb

Instance Method Summary collapse

Instance Method Details

#identify_test_object_adapter_from_data(source) ⇒ Object

TODO: document me



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/tdriver/base/test_object/xml/abstraction.rb', line 27

def identify_test_object_adapter_from_data( source )
   
  # verify check that source data is given in correct format
  source.check_type [ String, MobyUtil::XML::Element ], 'wrong argument type $1 for XML data source (expected $2)'

  # parse if given source is type of string    
  source = MobyUtil::XML.parse_string( source ).root if source.kind_of?( String )

  # determine xml format        
  if source.kind_of?( MobyUtil::XML::Element )

    # detect optimized xml format
    if source.xpath('.//obj[1]').count > 0

      TDriver::OptimizedXML::TestObjectAdapter
    
    # or deprecated xml format
    elsif source.xpath('.//object[1]').count > 0

      TDriver::TestObjectAdapter
    
    # or raise exception if format was not detected
    else
    
      raise RuntimeError, 'Unsupported XML data format'

    end
            
  end # if

end