testability-driver 0.9.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_composition.rb +1 -1
  2. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb +11 -7
  3. data/lib/tdriver/base/behaviour/behaviours/object_composition.rb +8 -0
  4. data/lib/tdriver/base/behaviour/factory.rb +229 -209
  5. data/lib/tdriver/base/errors.rb +3 -0
  6. data/lib/tdriver/base/state_object.rb +11 -20
  7. data/lib/tdriver/base/sut/controller.rb +4 -4
  8. data/lib/tdriver/base/sut/factory.rb +205 -170
  9. data/lib/tdriver/base/sut/generic/behaviours/application.rb +256 -174
  10. data/lib/tdriver/base/sut/generic/behaviours/find.rb +17 -11
  11. data/lib/tdriver/base/sut/generic/behaviours/flash_behaviour.rb +57 -66
  12. data/lib/tdriver/base/sut/generic/behaviours/sut.rb +578 -497
  13. data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +41 -15
  14. data/lib/tdriver/base/sut/generic/behaviours/verification.rb +48 -19
  15. data/lib/tdriver/base/sut/generic/commands/fixture.rb +47 -0
  16. data/lib/tdriver/base/sut/generic/commands/key_sequence.rb +25 -13
  17. data/lib/tdriver/base/sut/generic/commands/screen_capture.rb +16 -10
  18. data/lib/tdriver/base/sut/generic/plugin.rb +9 -3
  19. data/lib/tdriver/base/sut/sut.rb +41 -33
  20. data/lib/tdriver/base/test_object/abstract.rb +26 -3
  21. data/lib/tdriver/base/test_object/adapter.rb +399 -0
  22. data/lib/tdriver/base/test_object/behaviours/syncronization.rb +56 -14
  23. data/lib/tdriver/base/test_object/behaviours/test_object.rb +663 -197
  24. data/lib/tdriver/base/test_object/cache.rb +132 -0
  25. data/lib/tdriver/base/test_object/factory.rb +677 -426
  26. data/lib/tdriver/base/test_object/factory_new.rb +202 -0
  27. data/lib/tdriver/base/test_object/identificator.rb +24 -17
  28. data/lib/tdriver/base/test_object/loader.rb +9 -3
  29. data/lib/tdriver/base/test_object/verification.rb +181 -0
  30. data/lib/tdriver/loader.rb +1 -1
  31. data/lib/tdriver/report/report.rb +2 -0
  32. data/lib/tdriver/report/report_api.rb +4 -4
  33. data/lib/tdriver/report/report_creator.rb +29 -3
  34. data/lib/tdriver/report/report_data_presentation.rb +7 -3
  35. data/lib/tdriver/report/report_execution_statistics.rb +80 -21
  36. data/lib/tdriver/report/report_javascript.rb +192 -0
  37. data/lib/tdriver/report/report_test_case_run.rb +22 -0
  38. data/lib/tdriver/report/report_test_run.rb +62 -55
  39. data/lib/tdriver/report/report_writer.rb +57 -56
  40. data/lib/tdriver/tdriver.rb +14 -41
  41. data/lib/tdriver/util/common/error.rb +1 -0
  42. data/lib/tdriver/util/common/exceptions.rb +12 -0
  43. data/lib/tdriver/util/common/file.rb +12 -6
  44. data/lib/tdriver/util/common/gem.rb +2 -1
  45. data/lib/tdriver/util/common/hash.rb +152 -0
  46. data/lib/tdriver/util/common/kernel.rb +49 -34
  47. data/lib/tdriver/util/common/loader.rb +21 -17
  48. data/lib/tdriver/util/common/numeric.rb +39 -0
  49. data/lib/tdriver/util/common/object.rb +115 -0
  50. data/lib/tdriver/util/common/string.rb +55 -2
  51. data/lib/tdriver/util/dbaccess/dbaccess.rb +194 -161
  52. data/lib/tdriver/util/dynamic_attribute_filter.rb +6 -0
  53. data/lib/tdriver/util/hooking.rb +2 -2
  54. data/lib/tdriver/util/loader.rb +2 -2
  55. data/lib/tdriver/util/localisation/localisation.rb +277 -18
  56. data/lib/tdriver/util/logger.rb +142 -13
  57. data/lib/tdriver/util/parameter/parameter_hash.rb +8 -5
  58. data/lib/tdriver/util/parameter/parameter_xml.rb +18 -2
  59. data/lib/tdriver/util/recorder.rb +17 -12
  60. data/lib/tdriver/util/user_data/user_data.rb +3 -2
  61. data/lib/tdriver/util/{video_rec.rb → video_utils.rb} +136 -16
  62. data/lib/tdriver/util/xml/abstraction.rb +7 -0
  63. data/lib/tdriver/util/xml/attribute.rb +32 -0
  64. data/lib/tdriver/util/xml/loader.rb +8 -2
  65. data/lib/tdriver/util/xml/nil_node.rb +95 -0
  66. data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +46 -7
  67. data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +19 -9
  68. data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +1 -1
  69. data/lib/tdriver/util/xml/parsers/nokogiri/element.rb +13 -1
  70. data/lib/tdriver/util/xml/parsers/nokogiri/loader.rb +6 -0
  71. data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +27 -15
  72. data/lib/tdriver/util/xml/parsers/nokogiri/text.rb +57 -0
  73. data/lib/tdriver/util/xml/text.rb +32 -0
  74. data/lib/tdriver/util/xml/xml.rb +35 -22
  75. data/lib/tdriver/version.rb +1 -1
  76. data/lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb +41 -34
  77. data/lib/tdriver-devtools/doc/generate.rb +31 -6
  78. data/lib/tdriver-devtools/doc/xslt/template.xsl +46 -25
  79. data/lib/tdriver-devtools/tests/feature_tests/example/behaviour_example.rb +100 -0
  80. data/lib/tdriver-devtools/tests/feature_tests/update +1 -1
  81. data/lib/tdriver.rb +0 -3
  82. data/xml/behaviours/generic.xml +1 -1
  83. data/xml/defaults/generic.xml +4 -90
  84. data/xml/templates/generic.xml +33 -25
  85. metadata +21 -29
  86. data/lib/tdriver-devtools/behaviour/xml_generator/example/flick-example.rb +0 -245
  87. data/lib/tdriver-devtools/behaviour/xml_generator/example/sut.rb +0 -964
  88. data/lib/tdriver-devtools/behaviour/xml_generator/generate.rb +0 -68
  89. data/lib/tdriver-devtools/behaviour/xml_generator/lib/custom_rdoc_generator.rb +0 -1865
  90. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument.default.template +0 -1
  91. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument.template +0 -3
  92. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument_type.template +0 -4
  93. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.exception.template +0 -4
  94. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.arguments.template +0 -4
  95. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.deprecated.template +0 -3
  96. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.exceptions.template +0 -3
  97. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.info.template +0 -1
  98. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.returns.template +0 -3
  99. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.tables.template +0 -3
  100. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.template +0 -12
  101. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.returns.template +0 -5
  102. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.item.template +0 -1
  103. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.row.template +0 -2
  104. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.template +0 -7
  105. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.template +0 -14
  106. data/lib/tdriver-devtools/behaviour/xml_generator/update +0 -3
  107. data/lib/tdriver-devtools/tests/feature_tests/example/flick-example.rb +0 -233
  108. data/lib/tdriver-devtools/tests/feature_tests/example/impl.rb +0 -194
@@ -43,7 +43,7 @@ module MobyBehaviour
43
43
  module ObjectBehaviourComposition
44
44
 
45
45
  public
46
-
46
+ # == nodoc
47
47
  # == description
48
48
  # Apply all behaviour modules to target object which meets the given rules. Target object can be either type of "sut", "application" or "*" (any test object).
49
49
  # == tables
@@ -125,17 +125,23 @@ module MobyBehaviour
125
125
  # description: When 'return_result' is false
126
126
  # example: nil
127
127
  #
128
- # == footer
128
+ # == exceptions
129
+ # TypeError
130
+ # description: Wrong argument type %s for method name (expected Symbol or String)
131
+ #
132
+ # ArgumentError
133
+ # description: Test object type of %s does not have method %s
129
134
  #
130
135
  def describe_method( method_name, print = true, return_result = false )
131
136
 
137
+ # verify that method_name is type of Symbol or String
138
+ method_name.check_type( [ Symbol, String ], "Wrong argument type $1 for method name (expected $2)" )
139
+
132
140
  # convert to symbol if method_name is a string
133
141
  method_name = method_name.to_sym if method_name.kind_of?( String )
134
142
 
135
- Kernel::raise ArgumentError.new("Wrong argument type for method name. (Actual: #{ method_name.class }, Expected: Symbol)") unless method_name.kind_of?( Symbol )
136
-
137
143
  # print result to stdout if argument not boolean
138
- print = true unless [ TrueClass, FalseClass ].include? print.class
144
+ print = true unless [ TrueClass, FalseClass ].include?( print.class )
139
145
 
140
146
  # return result not printed out to stdout
141
147
  return_result = true unless print
@@ -154,7 +160,7 @@ module MobyBehaviour
154
160
 
155
161
  }
156
162
 
157
- Kernel::raise RuntimeError.new("No such method for object type of #{ self.type }") if result_hash.nil?
163
+ Kernel::raise ArgumentError.new( "Test object type of %s does not have method %s" % [ self.type, method_name ] ) if result_hash.nil?
158
164
 
159
165
  if print
160
166
 
@@ -209,8 +215,6 @@ module MobyBehaviour
209
215
  # NilClass
210
216
  # description: When 'return_result' is false
211
217
  # example: nil
212
- #
213
- # == footer
214
218
  #
215
219
  def describe( print = true, return_result = false )
216
220
 
@@ -61,6 +61,8 @@ module MobyBehaviour
61
61
  # === raises
62
62
  def add_parent( parent_object )
63
63
 
64
+ warn("Warning: Deprecated method, use store to @parent instead of using this method")
65
+
64
66
  @parent = parent_object
65
67
 
66
68
  end
@@ -73,6 +75,8 @@ module MobyBehaviour
73
75
  # ?
74
76
  def remove_parent()
75
77
 
78
+ warn("Warning: Deprecated method, set @parent to nil instead of using this method")
79
+
76
80
  @parent = nil
77
81
 
78
82
  end
@@ -86,6 +90,8 @@ module MobyBehaviour
86
90
  # === raises
87
91
  def add_child( new_child_object )
88
92
 
93
+ warn("Warning: Deprecated method, use @child_object_cache.add_object instead of this method")
94
+
89
95
  @_child_object_cache.merge!( new_child_object.hash => new_child_object )
90
96
 
91
97
  end
@@ -99,6 +105,8 @@ module MobyBehaviour
99
105
  # === raises
100
106
  def remove_child( target_child_object )
101
107
 
108
+ warn("Warning: Deprecated method, use @child_object_cache.add_object instead of this method")
109
+
102
110
  @_child_object_cache.delete( target_child_object.hash )
103
111
 
104
112
  end
@@ -19,302 +19,321 @@
19
19
 
20
20
  module MobyBase
21
21
 
22
- # TODO: document BehaviourFactory class
23
- class BehaviourFactory
22
+ # TODO: document BehaviourFactory class
23
+ class BehaviourFactory
24
24
 
25
- include Singleton
25
+ include Singleton
26
26
 
27
- def initialize
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
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
- rules.default = ['*']
121
+ rules.default = ['*']
122
122
 
123
- Kernel::raise ArgumentError.new( "No target object 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
135
  # verify if plugin is enabled -- exception will be catched if plugin is not registered
136
- MobyUtil::PluginService.instance.plugin_enabled?( plugin ) rescue false
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(
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
+ )
146
151
 
147
- @@modules_cache.fetch( behaviour_data[ :module ][ :name ] ){ | name |
148
-
149
- # ... or store to cache for the next time if not found
150
- @@modules_cache[ name ] = MobyUtil::KernelHelper.get_constant( name )
152
+ rescue NameError => exception
151
153
 
152
- }
154
+ Kernel::raise exception.class.new(
155
+ "Implementation for behaviour %s does not exist. (%s)" % [ behaviour_data[ :name ], behaviour_data[ :module ][ :name ] ]
156
+ )
153
157
 
154
- )
158
+ rescue Exception => exception
155
159
 
156
- rescue NameError => exception
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
+ )
157
168
 
158
- Kernel::raise exception.class.new(
159
- "Implementation for behaviour %s does not exist. (%s)" % [ behaviour_data[ :name ], behaviour_data[ :module ][ :name ] ]
160
- )
169
+ end
161
170
 
162
- rescue Exception => exception
171
+ # add behaviour information to test object
172
+ rules[ :object ].instance_exec{
163
173
 
164
- Kernel::raise RuntimeError.new(
165
- "Error while applying %s (%s) behaviour to target object. Reason: %s (%s)" % [
166
- behaviour_data[ :name ],
167
- behaviour_data[ :module ][ :name ],
168
- exception.message,
169
- exception.class
170
- ]
171
- )
174
+ @object_behaviours.push( behaviour_index ) unless @object_behaviours.include? behaviour_index
172
175
 
173
- end
176
+ }
174
177
 
175
- # add behaviour information to test object
176
- rules[ :object ].instance_exec{
178
+ }
177
179
 
178
- @object_behaviours.push( behaviour_index ) unless @object_behaviours.include? behaviour_index
180
+ end
179
181
 
180
- }
182
+ private
181
183
 
182
- }
184
+ def load_behaviours( behaviour_files )
183
185
 
184
- end
186
+ behaviours_data = []
185
187
 
186
- private
188
+ @file_name = ""
187
189
 
188
- def load_behaviours( behaviour_files )
190
+ begin
189
191
 
190
- behaviours_data = []
192
+ Dir.glob( behaviour_files ).each { | behaviour |
191
193
 
192
- @file_name = ""
194
+ @file_name = behaviour
193
195
 
194
- begin
196
+ behaviours_data << { :filename => @file_name, :xml => MobyUtil::FileHelper.get_file( @file_name ) }
195
197
 
196
- Dir.glob( behaviour_files ).each { | behaviour |
198
+ }
197
199
 
198
- @file_name = behaviour
200
+ rescue MobyUtil::EmptyFilenameError
199
201
 
200
- behaviours_data << { :filename => @file_name, :xml => MobyUtil::FileHelper.get_file( @file_name ) }
202
+ Kernel::raise EmptyFilenameError.new( "Unable to load behaviours xml file due to filename is empty or nil" )
201
203
 
202
- }
204
+ rescue MobyUtil::FileNotFoundError => ex
203
205
 
204
- rescue MobyUtil::EmptyFilenameError
206
+ Kernel::raise ex
205
207
 
206
- Kernel::raise EmptyFilenameError.new( "Unable to load behaviours xml file due to filename is empty or nil" )
208
+ rescue IOError => ex
207
209
 
208
- rescue MobyUtil::FileNotFoundError => ex
210
+ Kernel::raise IOError.new("Error occured while loading behaviours xml file %s. Reason: %s" % [ @file_name, ex.message ] )
209
211
 
210
- Kernel::raise ex
212
+ rescue => ex
211
213
 
212
- rescue IOError => ex
214
+ Kernel::raise RuntimeError.new( "Error occured while parsing behaviours xml file %s. Reason: %s (%s)" % [ @file_name, ex.message, ex.class ] )
213
215
 
214
- Kernel::raise IOError.new("Error occured while loading behaviours xml file %s. Reason: %s" % [ @file_name, ex.message ] )
216
+ end
215
217
 
216
- rescue => ex
218
+ behaviours_data
217
219
 
218
- Kernel::raise RuntimeError.new( "Error occured while parsing behaviours xml file %s. Reason: %s (%s)" % [ @file_name, ex.message, ex.class ] )
220
+ end
219
221
 
220
- end
222
+ def parse_behaviour_files( behaviour_files )
221
223
 
222
- behaviours_data
224
+ behaviour_files.each{ | behaviours |
223
225
 
224
- end
226
+ begin
225
227
 
226
- def parse_behaviour_files( behaviour_files )
228
+ # skip parsing the xml if string is empty
229
+ next if behaviours[ :xml ].empty?
227
230
 
228
- behaviour_files.each{ | behaviours |
231
+ # parse behaviour xml
232
+ document = MobyUtil::XML.parse_string( behaviours[ :xml ] )
229
233
 
230
- begin
234
+ rescue => exception
231
235
 
232
- # parse behaviour xml
233
- document = MobyUtil::XML.parse_string( behaviours[ :xml ] )
236
+ Kernel::raise MobyUtil::XML::ParseError.new(
237
+ "Error occured while parsing behaviour XML file %s. Error: %s " % [ behaviours[ :filename ], exception.message ]
238
+ )
234
239
 
235
- rescue => exception
240
+ end
236
241
 
237
- Kernel::raise MobyUtil::XML::ParseError.new(
238
- "Error occured while parsing behaviour XML file %s. Error: %s " % [ behaviours[ :filename ], exception.message ]
239
- )
242
+ # retrieve root attributes
243
+ root_attributes = document.root.xpath( "/behaviours" ).first.attributes
240
244
 
241
- end
245
+ # parse retrieve behaviour definitions
246
+ document.root.xpath( "/behaviours/behaviour" ).each{ | node |
242
247
 
243
- # retrieve root attributes
244
- root_attributes = document.root.xpath( "/behaviours" ).first.attributes
248
+ # retrieve behaviour attributes & module node
249
+ attributes = node.attributes
245
250
 
246
- # parse retrieve behaviour definitions
247
- document.root.xpath( "/behaviours/behaviour" ).each{ | node |
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
248
256
 
249
- # retrieve behaviour attributes & module node
250
- attributes = node.attributes
257
+ env = ( attributes[ "env" ] || '*' ).to_s
251
258
 
252
- name = attributes[ "name" ].to_s
253
- object_type = attributes[ "object_type" ].to_s
254
- input_type = attributes[ "input_type" ].to_s
255
- sut_type = attributes[ "sut_type" ].to_s
256
- version = attributes[ "version" ].to_s
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)
257
273
 
258
- # verify that all required attributes and nodes are found in behaviour xml node
259
- Kernel::raise RuntimeError.new("Behaviour does not have a name, please see behaviour XML files") if name.empty?
260
- Kernel::raise RuntimeError.new("Behaviour target object type not defined for #{ name } in XML") if object_type.empty?
261
- Kernel::raise RuntimeError.new("Behaviour target object input type not defined for #{ name } in XML") if input_type.empty?
262
- Kernel::raise RuntimeError.new("Behaviour target object sut type not defined for #{ name } in XML") if sut_type.empty?
263
- Kernel::raise RuntimeError.new("Behaviour target object sut version not defined for #{ name } in XML") if version.empty?
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)
264
276
 
265
- module_node = node.xpath( 'module' ).first
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)
266
279
 
267
- Kernel::raise RuntimeError.new("Behaviour implementation module not defined for #{ name } in XML") if module_node.nil?
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)
268
282
 
269
- # retrieve module name & implementation filename
270
- module_attributes = module_node.attributes
271
-
272
- module_file = module_attributes[ "file" ].to_s # optional
273
- module_name = module_attributes[ "name" ].to_s
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)
274
293
 
275
- Kernel::raise RuntimeError.new( "Behaviour implementation module name not defined for #{ name } in XML") if module_name.empty?
294
+ methods_hash = {}
276
295
 
277
- methods_hash = {}
296
+ # create hash of methods
297
+ node.xpath( 'methods/method' ).each{ | method |
278
298
 
279
- # create hash of methods
280
- node.xpath( 'methods/method' ).each{ | method |
299
+ # retrieve method description & example and store to methods hash
300
+ methods_hash[ method.attribute( "name" ).to_s.to_sym ] = {
281
301
 
282
- # retrieve method description & example and store to methods hash
283
- methods_hash[ method.attribute( "name" ).to_s.to_sym ] = {
302
+ :description => method.at_xpath( 'description/text()' ).to_s,
284
303
 
285
- :description => ( method.xpath( 'description' ).first.content rescue "" ),
286
- :example => ( method.xpath( 'example' ).first.content rescue "" )
304
+ :example => method.at_xpath( 'example/text()' ).to_s
287
305
 
288
- }
306
+ }
289
307
 
290
- }
308
+ }
291
309
 
292
- # create and store beahaviour hash
293
- @@behaviours << {
310
+ # create and store beahaviour hash
311
+ @@behaviours << {
294
312
 
295
- :name => name,
296
- :requires => root_attributes[ "plugin" ].to_s.split(";"),
297
- :object_type => object_type.split(";"),
298
- :input_type => input_type.split(";"),
299
- :sut_type => sut_type.split(";"),
300
- :version => version.split(";"),
301
-
302
- :module => {
303
- :file => module_file,
304
- :name => module_name
305
- },
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(";"),
306
320
 
307
- :methods => methods_hash
321
+ :module => {
322
+ :file => module_file,
323
+ :name => module_name
324
+ },
308
325
 
309
- }
326
+ :methods => methods_hash
310
327
 
311
- }
328
+ }
312
329
 
313
- }
330
+ }
314
331
 
315
- end
332
+ }
316
333
 
317
- def get_object_behaviours( rules )
334
+ end
335
+
336
+ def get_object_behaviours( rules )
318
337
 
319
338
  # calculate hash for behaviour rules / hash value will be used to identify similar objects
320
339
  behaviour_hash = Hash[ rules.select{ | key, value | key != :object } ].hash
@@ -326,55 +345,56 @@ module MobyBase
326
345
 
327
346
  else
328
347
 
329
- rules.default = [ '*' ]
348
+ rules.default = [ '*' ]
330
349
 
331
- extended_modules = []
350
+ extended_modules = []
332
351
 
333
- @@behaviours.each_with_index{ | behaviour, index |
352
+ @@behaviours.each_with_index{ | behaviour, index |
334
353
 
335
- if ( ( rules[ :name ] == behaviour[ :name ] ) ||
354
+ if ( ( rules[ :name ] == behaviour[ :name ] ) ||
336
355
 
337
- ( rules[ :name ] == [ '*' ] &&
356
+ ( rules[ :name ] == [ '*' ] &&
338
357
 
339
- ( !( rules[ :sut_type ] & behaviour[ :sut_type ] ).empty? ) &&
340
- ( !( rules[ :object_type ] & behaviour[ :object_type ] ).empty? ) &&
341
- ( !( rules[ :input_type ] & behaviour[ :input_type ] ).empty? ) &&
342
- ( !( 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? ) ) )
343
363
 
344
- # retrieve list of extended modules
345
- extended_modules << index
364
+ # retrieve list of extended modules
365
+ extended_modules << index
346
366
 
347
- end
367
+ end
348
368
 
349
- }
369
+ }
350
370
 
351
371
  # store behaviour module indexes to cache
352
372
  @@behaviours_cache[ behaviour_hash ] = extended_modules
353
373
 
354
374
  end
355
375
 
356
- end
376
+ end
357
377
 
358
- 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 )
359
379
 
360
- if @_behaviour_cache.has_key?( object_type )
380
+ if @_behaviour_cache.has_key?( object_type )
361
381
 
362
- # apply modules to target object
363
- @_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 })" ) }
364
384
 
365
- # return true
366
- true
385
+ # return true
386
+ true
367
387
 
368
- else
369
- # return false
370
- false
371
- end
388
+ else
389
+ # return false
390
+ false
391
+ end
372
392
 
373
- end
393
+ end
374
394
 
375
- # enable hooking for performance measurement & debug logging
376
- MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
395
+ # enable hooking for performance measurement & debug logging
396
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
377
397
 
378
- end # BehaviourGenerator
398
+ end # BehaviourGenerator
379
399
 
380
400
  end # MobyBase