testability-driver 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb +2 -2
  2. data/lib/tdriver-devtools/tdriver-devtools.rb +1 -1
  3. data/lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb +3 -3
  4. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_composition.rb +6 -1
  5. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb +5 -3
  6. data/lib/tdriver/base/behaviour/behaviours/object_composition.rb +1 -1
  7. data/lib/tdriver/base/behaviour/factory.rb +225 -225
  8. data/lib/tdriver/base/errors.rb +1 -1
  9. data/lib/tdriver/base/state_object.rb +227 -179
  10. data/lib/tdriver/base/sut/controller.rb +2 -2
  11. data/lib/tdriver/base/sut/factory.rb +190 -182
  12. data/lib/tdriver/base/sut/generic/behaviours/application.rb +69 -25
  13. data/lib/tdriver/base/sut/generic/behaviours/controller.rb +1 -1
  14. data/lib/tdriver/base/sut/generic/behaviours/find.rb +4 -4
  15. data/lib/tdriver/base/sut/generic/behaviours/flash_behaviour.rb +3 -3
  16. data/lib/tdriver/base/sut/generic/behaviours/sut.rb +350 -165
  17. data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +9 -9
  18. data/lib/tdriver/base/sut/generic/behaviours/verification.rb +191 -103
  19. data/lib/tdriver/base/sut/generic/commands/application.rb +1 -1
  20. data/lib/tdriver/base/sut/generic/commands/key_sequence.rb +1 -1
  21. data/lib/tdriver/base/sut/generic/commands/screen_capture.rb +1 -1
  22. data/lib/tdriver/base/sut/generic/plugin.rb +1 -1
  23. data/lib/tdriver/base/sut/sut.rb +5 -1
  24. data/lib/tdriver/base/test_object/abstract.rb +136 -151
  25. data/lib/tdriver/base/test_object/adapter.rb +293 -82
  26. data/lib/tdriver/base/test_object/behaviours/syncronization.rb +20 -17
  27. data/lib/tdriver/base/test_object/behaviours/test_object.rb +159 -532
  28. data/lib/tdriver/base/test_object/cache.rb +1 -1
  29. data/lib/tdriver/base/test_object/factory.rb +254 -605
  30. data/lib/tdriver/base/test_object/identificator.rb +1 -1
  31. data/lib/tdriver/base/test_object/loader.rb +1 -1
  32. data/lib/tdriver/base/test_object/verification.rb +17 -17
  33. data/lib/tdriver/loader.rb +20 -9
  34. data/lib/tdriver/report/report.rb +5 -0
  35. data/lib/tdriver/report/report_creator.rb +2 -2
  36. data/lib/tdriver/report/report_cucumber_listener.rb +4 -4
  37. data/lib/tdriver/report/report_cucumber_reporter.rb +4 -4
  38. data/lib/tdriver/report/report_execution_statistics.rb +22 -22
  39. data/lib/tdriver/report/report_grouping.rb +2 -2
  40. data/lib/tdriver/report/report_javascript.rb +11 -4
  41. data/lib/tdriver/report/report_test_case_run.rb +2 -2
  42. data/lib/tdriver/report/report_test_run.rb +5 -5
  43. data/lib/tdriver/report/report_test_unit.rb +74 -26
  44. data/lib/tdriver/report/report_writer.rb +70 -13
  45. data/lib/tdriver/tdriver.rb +17 -8
  46. data/lib/tdriver/util/common/array.rb +1 -1
  47. data/lib/tdriver/util/common/crc16.rb +1 -1
  48. data/lib/tdriver/util/common/environment.rb +1 -1
  49. data/lib/tdriver/util/common/file.rb +18 -9
  50. data/lib/tdriver/util/common/gem.rb +1 -1
  51. data/lib/tdriver/util/common/hash.rb +21 -0
  52. data/lib/tdriver/util/common/kernel.rb +1 -1
  53. data/lib/tdriver/util/common/loader.rb +5 -2
  54. data/lib/tdriver/util/common/numeric.rb +54 -3
  55. data/lib/tdriver/util/common/retryable.rb +30 -12
  56. data/lib/tdriver/util/common/stackable.rb +185 -0
  57. data/lib/tdriver/util/common/string.rb +21 -5
  58. data/lib/tdriver/util/{dbaccess/dbaccess.rb → database/access.rb} +4 -1
  59. data/lib/tdriver/util/{dbaccess/dbconnection.rb → database/connection.rb} +3 -0
  60. data/lib/tdriver/util/{dbaccess → database}/error.rb +0 -1
  61. data/lib/tdriver/util/{dbaccess → database}/loader.rb +5 -6
  62. data/lib/tdriver/util/{dynamic_attribute_filter.rb → filters/dynamic_attributes.rb} +1 -1
  63. data/lib/tdriver/util/hooking/hooking.rb +477 -0
  64. data/lib/tdriver/util/loader.rb +35 -29
  65. data/lib/tdriver/util/localisation/error.rb +0 -1
  66. data/lib/tdriver/util/localisation/loader.rb +1 -4
  67. data/lib/tdriver/util/localisation/localisation.rb +30 -27
  68. data/lib/tdriver/util/{common.rb → logger/loader.rb} +2 -4
  69. data/lib/tdriver/util/logger/logger.rb +574 -0
  70. data/lib/tdriver/util/operator_data/loader.rb +4 -3
  71. data/lib/tdriver/util/operator_data/operator_data.rb +5 -5
  72. data/lib/tdriver/util/parameter/parameter.rb +7 -1
  73. data/lib/tdriver/util/parameter/parameter_hash.rb +1 -1
  74. data/lib/tdriver/util/parameter/parameter_template.rb +1 -1
  75. data/lib/tdriver/util/parameter/parameter_user_api.rb +28 -20
  76. data/lib/tdriver/util/parameter/parameter_xml.rb +1 -1
  77. data/lib/tdriver/util/plugin/abstract.rb +1 -1
  78. data/lib/tdriver/util/plugin/service.rb +1 -1
  79. data/lib/tdriver/util/{localisation.rb → recorder/loader.rb} +4 -3
  80. data/lib/tdriver/util/recorder/recorder.rb +66 -0
  81. data/lib/tdriver/util/recorder/scripter.rb +258 -0
  82. data/lib/tdriver/util/{stats.rb → statistics/statistics.rb} +7 -8
  83. data/lib/tdriver/util/user_data/error.rb +0 -1
  84. data/lib/tdriver/util/user_data/loader.rb +1 -2
  85. data/lib/tdriver/util/user_data/user_data.rb +6 -6
  86. data/lib/tdriver/util/video/camera.rb +67 -0
  87. data/lib/tdriver/util/video/camera_linux.rb +139 -0
  88. data/lib/tdriver/util/video/camera_windows.rb +174 -0
  89. data/lib/tdriver/util/video/loader.rb +31 -0
  90. data/lib/tdriver/util/video/video_utils.rb +139 -0
  91. data/lib/tdriver/util/xml/abstraction.rb +56 -5
  92. data/lib/tdriver/util/xml/builder.rb +2 -5
  93. data/lib/tdriver/util/{parameter.rb → xml/comment.rb} +10 -2
  94. data/lib/tdriver/util/xml/loader.rb +32 -22
  95. data/lib/tdriver/util/xml/nil_node.rb +2 -2
  96. data/lib/tdriver/util/xml/parsers/loader.rb +0 -1
  97. data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +18 -44
  98. data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +9 -13
  99. data/lib/tdriver/util/xml/parsers/nokogiri/builder.rb +9 -3
  100. data/lib/tdriver/util/xml/parsers/nokogiri/comment.rb +39 -0
  101. data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +6 -11
  102. data/lib/tdriver/util/xml/parsers/nokogiri/element.rb +2 -122
  103. data/lib/tdriver/util/xml/parsers/nokogiri/loader.rb +26 -16
  104. data/lib/tdriver/util/xml/parsers/nokogiri/node.rb +203 -0
  105. data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +1 -2
  106. data/lib/tdriver/util/xml/parsers/nokogiri/text.rb +2 -20
  107. data/lib/tdriver/util/xml/xml.rb +52 -20
  108. data/lib/tdriver/verify/verify.rb +238 -81
  109. data/xml/behaviours/generic.xml +12 -10
  110. metadata +156 -180
  111. data/lib/tdriver/base/test_object/factory_new.rb +0 -202
  112. data/lib/tdriver/util/hooking.rb +0 -434
  113. data/lib/tdriver/util/logger.rb +0 -506
  114. data/lib/tdriver/util/recorder.rb +0 -297
  115. data/lib/tdriver/util/video_utils.rb +0 -384
  116. data/lib/tdriver/util/xml/nil_element.rb +0 -89
@@ -604,7 +604,7 @@ EXAMPLE
604
604
 
605
605
  params_array.each{ | param |
606
606
 
607
- if ( item = result.select{ | arg | arg.keys.include?( param.first ) }).empty?
607
+ if ( item = result.select{ | arg | arg.keys.include?( param.first ) }.to_a).empty? # Array conversion for ruby 1.9 compatibility
608
608
 
609
609
  raise_error("Error: Argument '#{ param.first }' is implemented but not documented in '#{ @current_method.name }' ($MODULE).\nNote that documented argument and variable name must be identical.", [ 'writer', 'accessor' ].include?( @processing ) ? 'attr_argument' : 'arguments' ) unless param.first.to_s.include?("#")
610
610
 
@@ -678,7 +678,7 @@ EXAMPLE
678
678
  # always add block parameters
679
679
  unimplemented_arguments.include?( documented_argument.to_a.flatten.first ) == false || documented_argument.to_a.flatten.first.include?("#")
680
680
 
681
- }
681
+ }.to_a # Array conversion for ruby 1.9 compatiblity
682
682
 
683
683
  end
684
684
 
@@ -55,7 +55,7 @@ safe_require('tdriver/version.rb', File.expand_path( File.join( File.dirname( _
55
55
  safe_require('tdriver/util/common/loader.rb', File.expand_path( File.join( File.dirname( __FILE__ ), '../tdriver/util/common/loader.rb' ) ) )
56
56
 
57
57
  require 'tmpdir'
58
- require 'fileutils'
58
+ require "fileutils" unless defined?( ::FileUtils )
59
59
 
60
60
  # default options
61
61
  @options = {
@@ -179,7 +179,7 @@ module Generators
179
179
  # first scenario with all required arguments
180
180
  if mode.to_s =~ /method/
181
181
 
182
- required_arguments = arguments_table.select{ | argument | argument.last == false }.collect{ | scenario | scenario.first }
182
+ required_arguments = arguments_table.select{ | argument | argument.last == false }.to_a.collect{ | scenario | scenario.first } # Array conversion for ruby 1.9 compatibility
183
183
 
184
184
  results << $templates[ mode ] % [ @current_method.name, "required", "(s)", @current_method.name, required_arguments.join(", ") ]
185
185
 
@@ -196,8 +196,8 @@ module Generators
196
196
  unless arguments_table.nil?
197
197
 
198
198
  # scenarios with one of each optional argument.. and eventually with all arguments
199
- arguments_table.select{ | argument | argument.last == true }.collect{ | scenario | scenario
200
-
199
+ arguments_table.select{ | argument | argument.last == true }.to_a.collect{ | scenario | scenario
200
+ # Array conversion for ruby 1.9 compatibility
201
201
  scenario = required_arguments << scenario.first
202
202
 
203
203
  results << $templates[ mode ] % [ @current_method.name, "optional", " '%s'" % scenario.last.first, @current_method.name, scenario.join(", ") ]
@@ -17,6 +17,9 @@
17
17
  ##
18
18
  ############################################################################
19
19
 
20
+ # deprecated: use MobyUtil::BehaviourFactory instead
21
+
22
+ =begin
20
23
  module MobyBehaviour
21
24
 
22
25
  # == description
@@ -86,9 +89,11 @@ module MobyBehaviour
86
89
  }
87
90
 
88
91
  end
92
+
89
93
  # enable hooking for performance measurement & debug logging
90
- MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
94
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
91
95
 
92
96
  end # ObjectBehaviourComposition
93
97
 
94
98
  end # MobyBehaviour
99
+ =end
@@ -239,8 +239,10 @@ module MobyBehaviour
239
239
  value = result_hash[ key ]
240
240
  result << "\n#{ key.to_s.capitalize }:\n"
241
241
  case value.class.to_s
242
- when "Array": result << "\t" << value.join("\n\t") << "\n"
243
- when "Hash": result << value.collect{ | key, value | "\t#{ key } => #{ value }" }.join("\n") << "\n"
242
+ when "Array"
243
+ result << "\t" << value.join("\n\t") << "\n"
244
+ when "Hash"
245
+ result << value.collect{ | key, value | "\t#{ key } => #{ value }" }.join("\n") << "\n"
244
246
  #else
245
247
  #result << "\t#{ value }\n"
246
248
  end
@@ -259,7 +261,7 @@ module MobyBehaviour
259
261
  end
260
262
 
261
263
  # enable hooking for performance measurement & debug logging
262
- MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
264
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
263
265
 
264
266
  end # ObjectBehaviourDescription
265
267
 
@@ -112,7 +112,7 @@ module MobyBehaviour
112
112
  end
113
113
 
114
114
  # enable hooking for performance measurement & debug logging
115
- MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
115
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
116
116
 
117
117
  end # ObjectComposition
118
118
 
@@ -22,318 +22,318 @@ module MobyBase
22
22
  # TODO: document BehaviourFactory class
23
23
  class BehaviourFactory
24
24
 
25
- include Singleton
26
-
27
- def initialize
25
+ include Singleton
26
+
27
+ def initialize
28
28
 
29
- @@behaviours = []
30
- @@behaviours_cache = {}
31
- @@modules_cache = {}
32
-
33
- # behaviour xml files path
34
- @@path = File.join( MobyUtil::FileHelper.tdriver_home, '/behaviours/*.xml' )
29
+ @@behaviours = []
30
+ @@behaviours_cache = {}
31
+ @@modules_cache = {}
32
+
33
+ # behaviour xml files path
34
+ @@path = File.join( MobyUtil::FileHelper.tdriver_home, '/behaviours/*.xml' )
35
35
 
36
- parse_behaviour_files(
36
+ parse_behaviour_files(
37
37
 
38
- load_behaviours( @@path )
38
+ load_behaviours( @@path )
39
39
 
40
- )
40
+ )
41
41
 
42
- end
42
+ end
43
43
 
44
- public
44
+ public
45
45
 
46
- def to_xml( rules = {} )
46
+ def to_xml( rules = {} )
47
47
 
48
- @_method_index = nil
48
+ @_method_index = nil
49
49
 
50
- rules.default = [ '*' ]
50
+ rules.default = [ '*' ]
51
51
 
52
- rules.each_pair{ | key, value |
52
+ rules.each_pair{ | key, value |
53
53
 
54
- rules[ key ] = [ value ] if value.kind_of?( String )
54
+ rules[ key ] = [ value ] if value.kind_of?( String )
55
55
 
56
- }
56
+ }
57
57
 
58
- MobyUtil::XML.build{
58
+ MobyUtil::XML.build{
59
59
 
60
- behaviours{
60
+ behaviours{
61
61
 
62
- @@behaviours.each_index{ | index |
62
+ @@behaviours.each_index{ | index |
63
63
 
64
- @_method_index = index
64
+ @_method_index = index
65
65
 
66
- behaviour = @@behaviours[ @_method_index ]
66
+ behaviour = @@behaviours[ @_method_index ]
67
67
 
68
- if ( ( rules[ :name ] == behaviour[ :name ] ) ||
68
+ if ( ( rules[ :name ] == behaviour[ :name ] ) ||
69
69
 
70
- ( rules[ :name ] == [ '*' ] ) &&
70
+ ( rules[ :name ] == [ '*' ] ) &&
71
71
 
72
- # ( !( rules[ :sut_type ] & behaviour[ :sut_type ] ).empty? ) &&
73
- ( !( rules[ :input_type ] & behaviour[ :input_type ] ).empty? ) &&
74
- ( !( rules[ :object_type ] & behaviour[ :object_type ] ).empty? ) &&
75
- ( !( rules[ :version ] & behaviour[ :version ] ).empty? )
72
+ # ( !( rules[ :sut_type ] & behaviour[ :sut_type ] ).empty? ) &&
73
+ ( !( rules[ :input_type ] & behaviour[ :input_type ] ).empty? ) &&
74
+ ( !( rules[ :object_type ] & behaviour[ :object_type ] ).empty? ) &&
75
+ ( !( rules[ :version ] & behaviour[ :version ] ).empty? )
76
76
 
77
- )
77
+ )
78
78
 
79
- behaviour( :name => @@behaviours[ @_method_index ][ :name ], :object_type => @@behaviours[ @_method_index ][ :object_type ].join(";") ){
80
- object_methods{
81
- @@behaviours[ @_method_index ][ :methods ].each { | key, value |
82
- object_method( :name => key.to_s ) {
83
- description( value[:description] )
84
- example( value[:example] )
85
- }
86
- }
87
- }
88
- }
79
+ behaviour( :name => @@behaviours[ @_method_index ][ :name ], :object_type => @@behaviours[ @_method_index ][ :object_type ].join(";") ){
80
+ object_methods{
81
+ @@behaviours[ @_method_index ][ :methods ].each { | key, value |
82
+ object_method( :name => key.to_s ) {
83
+ description( value[:description] )
84
+ example( value[:example] )
85
+ }
86
+ }
87
+ }
88
+ }
89
89
 
90
- end
90
+ end
91
91
 
92
- }
92
+ }
93
93
 
94
- }
94
+ }
95
95
 
96
- }.to_xml
96
+ }.to_xml
97
97
 
98
- end
98
+ end
99
99
 
100
- def get_behaviour_at_index( index )
100
+ def get_behaviour_at_index( index )
101
101
 
102
- result = @@behaviours[ index ]
102
+ result = @@behaviours[ index ]
103
103
 
104
- if result.nil?
104
+ if result.nil?
105
105
 
106
- Kernel::raise RuntimeError.new( "No behaviour at index #{ index }" )
106
+ Kernel::raise RuntimeError.new( "No behaviour at index #{ index }" )
107
107
 
108
- else
108
+ else
109
109
 
110
- result
110
+ result
111
111
 
112
- end
112
+ end
113
113
 
114
- end
114
+ end
115
115
 
116
- def apply_behaviour!( rules = {} )
116
+ def apply_behaviour!( rules = {} )
117
117
 
118
- # merge user-defined rules on top of default rules set
119
- #rules = { :sut_type => ['*'], :object_type => ['*'], :input_type => ['*'], :version => ['*'] }.merge!( rules )
118
+ # merge user-defined rules on top of default rules set
119
+ #rules = { :sut_type => ['*'], :object_type => ['*'], :input_type => ['*'], :version => ['*'] }.merge!( rules )
120
120
 
121
121
  rules.default = ['*']
122
122
 
123
- Kernel::raise ArgumentError.new( "Target object not defined in rules hash" ) if rules[ :object ].nil?
123
+ Kernel::raise ArgumentError.new( "Target object not defined in rules hash" ) if rules[ :object ].nil?
124
124
 
125
- # apply behaviours to target object
126
- ( get_object_behaviours( rules ) ).each{ | behaviour_index |
125
+ # apply behaviours to target object
126
+ ( get_object_behaviours( rules ) ).each{ | behaviour_index |
127
127
 
128
- behaviour_data = @@behaviours[ behaviour_index ]
128
+ behaviour_data = @@behaviours[ behaviour_index ]
129
129
 
130
- # skip if required plugin is not registered or enabled
131
- next if behaviour_data[ :requires ].collect{ | plugin |
130
+ # skip if required plugin is not registered or enabled
131
+ next if behaviour_data[ :requires ].collect{ | plugin |
132
132
 
133
- #MobyUtil::PluginService.instance.plugin_registered?( plugin ) && MobyUtil::PluginService.instance.plugin_enabled?( plugin )
133
+ #MobyUtil::PluginService.instance.plugin_registered?( plugin ) && MobyUtil::PluginService.instance.plugin_enabled?( plugin )
134
134
 
135
- # verify if plugin is enabled -- exception will be catched if plugin is not registered
136
- MobyUtil::PluginService.instance.plugin_enabled?( plugin ) rescue false
135
+ # verify if plugin is enabled -- exception will be catched if plugin is not registered
136
+ MobyUtil::PluginService.instance.plugin_enabled?( plugin ) rescue false
137
137
 
138
- }.include?( false )
138
+ }.include?( false )
139
139
 
140
- begin
140
+ begin
141
141
 
142
- #behaviour_module = MobyUtil::KernelHelper.get_constant( behaviour_data[ :module ][ :name ] )
142
+ #behaviour_module = MobyUtil::KernelHelper.get_constant( behaviour_data[ :module ][ :name ] )
143
143
 
144
- # retrieve behaviour module from cache and extend target object
145
- rules[ :object ].extend(
146
- @@modules_cache.fetch( behaviour_data[ :module ][ :name ] ){ | name |
147
- # ... or store to cache for the next time if not found
148
- @@modules_cache[ name ] = MobyUtil::KernelHelper.get_constant( name )
149
- }
150
- )
144
+ # retrieve behaviour module from cache and extend target object
145
+ rules[ :object ].extend(
146
+ @@modules_cache.fetch( behaviour_data[ :module ][ :name ] ){ | name |
147
+ # ... or store to cache for the next time if not found
148
+ @@modules_cache[ name ] = MobyUtil::KernelHelper.get_constant( name )
149
+ }
150
+ )
151
151
 
152
- rescue NameError => exception
152
+ rescue NameError => exception
153
153
 
154
- Kernel::raise exception.class.new(
155
- "Implementation for behaviour %s does not exist. (%s)" % [ behaviour_data[ :name ], behaviour_data[ :module ][ :name ] ]
156
- )
154
+ Kernel::raise exception.class.new(
155
+ "Implementation for behaviour %s does not exist. (%s)" % [ behaviour_data[ :name ], behaviour_data[ :module ][ :name ] ]
156
+ )
157
157
 
158
- rescue Exception => exception
158
+ rescue Exception => exception
159
159
 
160
- Kernel::raise RuntimeError.new(
161
- "Error while applying %s (%s) behaviour to target object. Reason: %s (%s)" % [
162
- behaviour_data[ :name ],
163
- behaviour_data[ :module ][ :name ],
164
- exception.message,
165
- exception.class
166
- ]
167
- )
160
+ Kernel::raise RuntimeError.new(
161
+ "Error while applying %s (%s) behaviour to target object. Reason: %s (%s)" % [
162
+ behaviour_data[ :name ],
163
+ behaviour_data[ :module ][ :name ],
164
+ exception.message,
165
+ exception.class
166
+ ]
167
+ )
168
168
 
169
- end
169
+ end
170
170
 
171
- # add behaviour information to test object
172
- rules[ :object ].instance_exec{
171
+ # add behaviour information to test object
172
+ rules[ :object ].instance_exec{
173
173
 
174
- @object_behaviours.push( behaviour_index ) unless @object_behaviours.include? behaviour_index
174
+ @object_behaviours.push( behaviour_index ) unless @object_behaviours.include? behaviour_index
175
175
 
176
- }
176
+ }
177
177
 
178
- }
178
+ }
179
179
 
180
- end
180
+ end
181
181
 
182
- private
182
+ private
183
183
 
184
- def load_behaviours( behaviour_files )
184
+ def load_behaviours( behaviour_files )
185
185
 
186
- behaviours_data = []
186
+ behaviours_data = []
187
187
 
188
- @file_name = ""
188
+ @file_name = ""
189
189
 
190
- begin
190
+ begin
191
191
 
192
- Dir.glob( behaviour_files ).each { | behaviour |
192
+ Dir.glob( behaviour_files ).each { | behaviour |
193
193
 
194
- @file_name = behaviour
194
+ @file_name = behaviour
195
195
 
196
- behaviours_data << { :filename => @file_name, :xml => MobyUtil::FileHelper.get_file( @file_name ) }
196
+ behaviours_data << { :filename => @file_name, :xml => MobyUtil::FileHelper.get_file( @file_name ) }
197
197
 
198
- }
198
+ }
199
199
 
200
- rescue MobyUtil::EmptyFilenameError
200
+ rescue MobyUtil::EmptyFilenameError
201
201
 
202
- Kernel::raise EmptyFilenameError.new( "Unable to load behaviours xml file due to filename is empty or nil" )
202
+ Kernel::raise EmptyFilenameError.new( "Unable to load behaviours xml file due to filename is empty or nil" )
203
203
 
204
- rescue MobyUtil::FileNotFoundError => ex
204
+ rescue MobyUtil::FileNotFoundError => ex
205
205
 
206
- Kernel::raise ex
206
+ Kernel::raise ex
207
207
 
208
- rescue IOError => ex
208
+ rescue IOError => ex
209
209
 
210
- Kernel::raise IOError.new("Error occured while loading behaviours xml file %s. Reason: %s" % [ @file_name, ex.message ] )
210
+ Kernel::raise IOError.new("Error occured while loading behaviours xml file %s. Reason: %s" % [ @file_name, ex.message ] )
211
211
 
212
- rescue => ex
212
+ rescue => ex
213
213
 
214
- Kernel::raise RuntimeError.new( "Error occured while parsing behaviours xml file %s. Reason: %s (%s)" % [ @file_name, ex.message, ex.class ] )
214
+ Kernel::raise RuntimeError.new( "Error occured while parsing behaviours xml file %s. Reason: %s (%s)" % [ @file_name, ex.message, ex.class ] )
215
215
 
216
- end
216
+ end
217
217
 
218
- behaviours_data
218
+ behaviours_data
219
219
 
220
- end
220
+ end
221
221
 
222
- def parse_behaviour_files( behaviour_files )
222
+ def parse_behaviour_files( behaviour_files )
223
223
 
224
- behaviour_files.each{ | behaviours |
224
+ behaviour_files.each{ | behaviours |
225
225
 
226
- begin
226
+ begin
227
227
 
228
228
  # skip parsing the xml if string is empty
229
229
  next if behaviours[ :xml ].empty?
230
230
 
231
- # parse behaviour xml
232
- document = MobyUtil::XML.parse_string( behaviours[ :xml ] )
231
+ # parse behaviour xml
232
+ document = MobyUtil::XML.parse_string( behaviours[ :xml ] )
233
233
 
234
- rescue => exception
234
+ rescue => exception
235
235
 
236
- Kernel::raise MobyUtil::XML::ParseError.new(
237
- "Error occured while parsing behaviour XML file %s. Error: %s " % [ behaviours[ :filename ], exception.message ]
238
- )
236
+ Kernel::raise MobyUtil::XML::ParseError.new(
237
+ "Error occured while parsing behaviour XML file %s. Error: %s " % [ behaviours[ :filename ], exception.message ]
238
+ )
239
239
 
240
- end
240
+ end
241
241
 
242
- # retrieve root attributes
243
- root_attributes = document.root.xpath( "/behaviours" ).first.attributes
242
+ # retrieve root attributes
243
+ root_attributes = document.root.xpath( "/behaviours" ).first.attributes
244
244
 
245
- # parse retrieve behaviour definitions
246
- document.root.xpath( "/behaviours/behaviour" ).each{ | node |
245
+ # parse retrieve behaviour definitions
246
+ document.root.xpath( "/behaviours/behaviour" ).each{ | node |
247
247
 
248
- # retrieve behaviour attributes & module node
249
- attributes = node.attributes
248
+ # retrieve behaviour attributes & module node
249
+ attributes = node.attributes
250
250
 
251
- name = attributes[ "name" ].to_s
252
- object_type = attributes[ "object_type" ].to_s
253
- input_type = attributes[ "input_type" ].to_s
254
- sut_type = attributes[ "sut_type" ].to_s
255
- version = attributes[ "version" ].to_s
251
+ name = attributes[ "name" ].to_s
252
+ object_type = attributes[ "object_type" ].to_s
253
+ input_type = attributes[ "input_type" ].to_s
254
+ sut_type = attributes[ "sut_type" ].to_s
255
+ version = attributes[ "version" ].to_s
256
256
 
257
- env = ( attributes[ "env" ] || '*' ).to_s
257
+ env = ( attributes[ "env" ] || '*' ).to_s
258
258
 
259
- module_node = node.xpath( 'module' ).first
260
-
261
- name = attributes[ "name" ].to_s
262
- object_type = attributes[ "object_type" ].to_s
263
- input_type = attributes[ "input_type" ].to_s
264
- sut_type = attributes[ "sut_type" ].to_s
265
- version = attributes[ "version" ].to_s
266
-
267
- # verify that all required attributes and nodes are found in behaviour xml node
268
- #Kernel::raise RuntimeError.new("Behaviour does not have a name, please see behaviour XML files") if name.empty?
269
- name.not_empty("Behaviour element does not have name (name) attribute defined, please see behaviour XML files", RuntimeError)
270
-
271
- #Kernel::raise RuntimeError.new("Behaviour target object type not defined for #{ name } in XML") if object_type.empty?
272
- object_type.not_empty("Behaviour element does not have target object type (object_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
259
+ module_node = node.xpath( 'module' ).first
260
+
261
+ name = attributes[ "name" ].to_s
262
+ object_type = attributes[ "object_type" ].to_s
263
+ input_type = attributes[ "input_type" ].to_s
264
+ sut_type = attributes[ "sut_type" ].to_s
265
+ version = attributes[ "version" ].to_s
266
+
267
+ # verify that all required attributes and nodes are found in behaviour xml node
268
+ #Kernel::raise RuntimeError.new("Behaviour does not have a name, please see behaviour XML files") if name.empty?
269
+ name.not_empty("Behaviour element does not have name (name) attribute defined, please see behaviour XML files", RuntimeError)
270
+
271
+ #Kernel::raise RuntimeError.new("Behaviour target object type not defined for #{ name } in XML") if object_type.empty?
272
+ object_type.not_empty("Behaviour element does not have target object type (object_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
273
273
 
274
- #Kernel::raise RuntimeError.new("Behaviour target object input type not defined for #{ name } in XML") if input_type.empty?
275
- input_type.not_empty("Behaviour element does not have target object input type (input_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
274
+ #Kernel::raise RuntimeError.new("Behaviour target object input type not defined for #{ name } in XML") if input_type.empty?
275
+ input_type.not_empty("Behaviour element does not have target object input type (input_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
276
276
 
277
- #Kernel::raise RuntimeError.new("Behaviour target object sut type not defined for #{ name } in XML") if sut_type.empty?
278
- sut_type.not_empty("Behaviour element does not have target object sut type (sut_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
277
+ #Kernel::raise RuntimeError.new("Behaviour target object sut type not defined for #{ name } in XML") if sut_type.empty?
278
+ sut_type.not_empty("Behaviour element does not have target object sut type (sut_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
279
279
 
280
- #Kernel::raise RuntimeError.new("Behaviour target object sut version not defined for #{ name } in XML") if version.empty?
281
- version.not_empty("Behaviour element does not have target object SUT version (version) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
280
+ #Kernel::raise RuntimeError.new("Behaviour target object sut version not defined for #{ name } in XML") if version.empty?
281
+ version.not_empty("Behaviour element does not have target object SUT version (version) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
282
282
 
283
- #Kernel::raise RuntimeError.new("Behaviour implementation module not defined for #{ name } in XML") if module_node.nil?
284
- module_node.not_nil("Behaviour does not have implementation module element defined, please see #{ name } in behaviour XML files", RuntimeError)
285
-
286
- # retrieve module name & implementation filename
287
- module_attributes = module_node.attributes
288
- module_file = module_attributes[ "file" ].to_s # optional
289
- module_name = module_attributes[ "name" ].to_s
290
-
291
- #Kernel::raise RuntimeError.new( "Behaviour implementation module name not defined for #{ name } in XML") if module_name.empty?
292
- module_name.not_empty("Behaviour does not have implementation module name defined, please see #{ name } in behaviour XML files", RuntimeError)
283
+ #Kernel::raise RuntimeError.new("Behaviour implementation module not defined for #{ name } in XML") if module_node.nil?
284
+ module_node.not_nil("Behaviour does not have implementation module element defined, please see #{ name } in behaviour XML files", RuntimeError)
285
+
286
+ # retrieve module name & implementation filename
287
+ module_attributes = module_node.attributes
288
+ module_file = module_attributes[ "file" ].to_s # optional
289
+ module_name = module_attributes[ "name" ].to_s
290
+
291
+ #Kernel::raise RuntimeError.new( "Behaviour implementation module name not defined for #{ name } in XML") if module_name.empty?
292
+ module_name.not_empty("Behaviour does not have implementation module name defined, please see #{ name } in behaviour XML files", RuntimeError)
293
293
 
294
- methods_hash = {}
294
+ methods_hash = {}
295
295
 
296
- # create hash of methods
297
- node.xpath( 'methods/method' ).each{ | method |
296
+ # create hash of methods
297
+ node.xpath( 'methods/method' ).each{ | method |
298
298
 
299
- # retrieve method description & example and store to methods hash
300
- methods_hash[ method.attribute( "name" ).to_s.to_sym ] = {
299
+ # retrieve method description & example and store to methods hash
300
+ methods_hash[ method.attribute( "name" ).to_s.to_sym ] = {
301
301
 
302
- :description => method.at_xpath( 'description/text()' ).to_s,
302
+ :description => method.at_xpath( 'description/text()' ).to_s,
303
303
 
304
- :example => method.at_xpath( 'example/text()' ).to_s
304
+ :example => method.at_xpath( 'example/text()' ).to_s
305
305
 
306
- }
306
+ }
307
307
 
308
- }
308
+ }
309
309
 
310
- # create and store beahaviour hash
311
- @@behaviours << {
310
+ # create and store beahaviour hash
311
+ @@behaviours << {
312
312
 
313
- :name => name,
314
- :requires => root_attributes[ "plugin" ].to_s.split(";"),
315
- :object_type => object_type.split(";"),
316
- :input_type => input_type.split(";"),
317
- # :sut_type => sut_type.split(";"),
318
- :version => version.split(";"),
319
- :env => env.split(";"),
313
+ :name => name,
314
+ :requires => root_attributes[ "plugin" ].to_s.split(";"),
315
+ :object_type => object_type.split(";"),
316
+ :input_type => input_type.split(";"),
317
+ # :sut_type => sut_type.split(";"),
318
+ :version => version.split(";"),
319
+ :env => env.split(";"),
320
320
 
321
- :module => {
322
- :file => module_file,
323
- :name => module_name
324
- },
321
+ :module => {
322
+ :file => module_file,
323
+ :name => module_name
324
+ },
325
325
 
326
- :methods => methods_hash
326
+ :methods => methods_hash
327
327
 
328
- }
328
+ }
329
329
 
330
- }
330
+ }
331
331
 
332
- }
332
+ }
333
333
 
334
- end
334
+ end
335
335
 
336
- def get_object_behaviours( rules )
336
+ def get_object_behaviours( rules )
337
337
 
338
338
  # calculate hash for behaviour rules / hash value will be used to identify similar objects
339
339
  behaviour_hash = Hash[ rules.select{ | key, value | key != :object } ].hash
@@ -345,55 +345,55 @@ module MobyBase
345
345
 
346
346
  else
347
347
 
348
- rules.default = [ '*' ]
348
+ rules.default = [ '*' ]
349
349
 
350
- extended_modules = []
350
+ extended_modules = []
351
351
 
352
- @@behaviours.each_with_index{ | behaviour, index |
352
+ @@behaviours.each_with_index{ | behaviour, index |
353
353
 
354
- if ( ( rules[ :name ] == behaviour[ :name ] ) ||
354
+ if ( ( rules[ :name ] == behaviour[ :name ] ) ||
355
355
 
356
- ( rules[ :name ] == [ '*' ] &&
356
+ ( rules[ :name ] == [ '*' ] &&
357
357
 
358
- # ( !( rules[ :sut_type ] & behaviour[ :sut_type ] ).empty? ) &&
359
- ( !( rules[ :object_type ] & behaviour[ :object_type ] ).empty? ) &&
360
- ( !( rules[ :input_type ] & behaviour[ :input_type ] ).empty? ) &&
361
- ( !( rules[ :env ] & behaviour[ :env ] ).empty? ) &&
362
- ( !( rules[ :version ] & behaviour[ :version ] ).empty? ) ) )
358
+ # ( !( rules[ :sut_type ] & behaviour[ :sut_type ] ).empty? ) &&
359
+ ( !( rules[ :object_type ] & behaviour[ :object_type ] ).empty? ) &&
360
+ ( !( rules[ :input_type ] & behaviour[ :input_type ] ).empty? ) &&
361
+ ( !( rules[ :env ] & behaviour[ :env ] ).empty? ) &&
362
+ ( !( rules[ :version ] & behaviour[ :version ] ).empty? ) ) )
363
363
 
364
- # retrieve list of extended modules
365
- extended_modules << index
364
+ # retrieve list of extended modules
365
+ extended_modules << index
366
366
 
367
- end
367
+ end
368
368
 
369
- }
369
+ }
370
370
 
371
371
  # store behaviour module indexes to cache
372
372
  @@behaviours_cache[ behaviour_hash ] = extended_modules
373
373
 
374
374
  end
375
375
 
376
- end
376
+ end
377
377
 
378
- def get_behaviour_from_cache( target, sut_type, object_type, sut_version, input_type )
378
+ def get_behaviour_from_cache( target, sut_type, object_type, sut_version, input_type )
379
379
 
380
- if @_behaviour_cache.has_key?( object_type )
380
+ if @_behaviour_cache.has_key?( object_type )
381
381
 
382
- # apply modules to target object
383
- @_behaviour_cache[ object_type ].each{ | module_name | target.instance_eval( "self.extend(#{ module_name })" ) }
382
+ # apply modules to target object
383
+ @_behaviour_cache[ object_type ].each{ | module_name | target.instance_eval( "self.extend(#{ module_name })" ) }
384
384
 
385
- # return true
386
- true
385
+ # return true
386
+ true
387
387
 
388
- else
389
- # return false
390
- false
391
- end
388
+ else
389
+ # return false
390
+ false
391
+ end
392
392
 
393
- end
393
+ end
394
394
 
395
- # enable hooking for performance measurement & debug logging
396
- MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
395
+ # enable hooking for performance measurement & debug logging
396
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
397
397
 
398
398
  end # BehaviourGenerator
399
399