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.
- data/lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb +2 -2
- data/lib/tdriver-devtools/tdriver-devtools.rb +1 -1
- data/lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb +3 -3
- data/lib/tdriver/base/behaviour/behaviours/object_behaviour_composition.rb +6 -1
- data/lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb +5 -3
- data/lib/tdriver/base/behaviour/behaviours/object_composition.rb +1 -1
- data/lib/tdriver/base/behaviour/factory.rb +225 -225
- data/lib/tdriver/base/errors.rb +1 -1
- data/lib/tdriver/base/state_object.rb +227 -179
- data/lib/tdriver/base/sut/controller.rb +2 -2
- data/lib/tdriver/base/sut/factory.rb +190 -182
- data/lib/tdriver/base/sut/generic/behaviours/application.rb +69 -25
- data/lib/tdriver/base/sut/generic/behaviours/controller.rb +1 -1
- data/lib/tdriver/base/sut/generic/behaviours/find.rb +4 -4
- data/lib/tdriver/base/sut/generic/behaviours/flash_behaviour.rb +3 -3
- data/lib/tdriver/base/sut/generic/behaviours/sut.rb +350 -165
- data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +9 -9
- data/lib/tdriver/base/sut/generic/behaviours/verification.rb +191 -103
- data/lib/tdriver/base/sut/generic/commands/application.rb +1 -1
- data/lib/tdriver/base/sut/generic/commands/key_sequence.rb +1 -1
- data/lib/tdriver/base/sut/generic/commands/screen_capture.rb +1 -1
- data/lib/tdriver/base/sut/generic/plugin.rb +1 -1
- data/lib/tdriver/base/sut/sut.rb +5 -1
- data/lib/tdriver/base/test_object/abstract.rb +136 -151
- data/lib/tdriver/base/test_object/adapter.rb +293 -82
- data/lib/tdriver/base/test_object/behaviours/syncronization.rb +20 -17
- data/lib/tdriver/base/test_object/behaviours/test_object.rb +159 -532
- data/lib/tdriver/base/test_object/cache.rb +1 -1
- data/lib/tdriver/base/test_object/factory.rb +254 -605
- data/lib/tdriver/base/test_object/identificator.rb +1 -1
- data/lib/tdriver/base/test_object/loader.rb +1 -1
- data/lib/tdriver/base/test_object/verification.rb +17 -17
- data/lib/tdriver/loader.rb +20 -9
- data/lib/tdriver/report/report.rb +5 -0
- data/lib/tdriver/report/report_creator.rb +2 -2
- data/lib/tdriver/report/report_cucumber_listener.rb +4 -4
- data/lib/tdriver/report/report_cucumber_reporter.rb +4 -4
- data/lib/tdriver/report/report_execution_statistics.rb +22 -22
- data/lib/tdriver/report/report_grouping.rb +2 -2
- data/lib/tdriver/report/report_javascript.rb +11 -4
- data/lib/tdriver/report/report_test_case_run.rb +2 -2
- data/lib/tdriver/report/report_test_run.rb +5 -5
- data/lib/tdriver/report/report_test_unit.rb +74 -26
- data/lib/tdriver/report/report_writer.rb +70 -13
- data/lib/tdriver/tdriver.rb +17 -8
- data/lib/tdriver/util/common/array.rb +1 -1
- data/lib/tdriver/util/common/crc16.rb +1 -1
- data/lib/tdriver/util/common/environment.rb +1 -1
- data/lib/tdriver/util/common/file.rb +18 -9
- data/lib/tdriver/util/common/gem.rb +1 -1
- data/lib/tdriver/util/common/hash.rb +21 -0
- data/lib/tdriver/util/common/kernel.rb +1 -1
- data/lib/tdriver/util/common/loader.rb +5 -2
- data/lib/tdriver/util/common/numeric.rb +54 -3
- data/lib/tdriver/util/common/retryable.rb +30 -12
- data/lib/tdriver/util/common/stackable.rb +185 -0
- data/lib/tdriver/util/common/string.rb +21 -5
- data/lib/tdriver/util/{dbaccess/dbaccess.rb → database/access.rb} +4 -1
- data/lib/tdriver/util/{dbaccess/dbconnection.rb → database/connection.rb} +3 -0
- data/lib/tdriver/util/{dbaccess → database}/error.rb +0 -1
- data/lib/tdriver/util/{dbaccess → database}/loader.rb +5 -6
- data/lib/tdriver/util/{dynamic_attribute_filter.rb → filters/dynamic_attributes.rb} +1 -1
- data/lib/tdriver/util/hooking/hooking.rb +477 -0
- data/lib/tdriver/util/loader.rb +35 -29
- data/lib/tdriver/util/localisation/error.rb +0 -1
- data/lib/tdriver/util/localisation/loader.rb +1 -4
- data/lib/tdriver/util/localisation/localisation.rb +30 -27
- data/lib/tdriver/util/{common.rb → logger/loader.rb} +2 -4
- data/lib/tdriver/util/logger/logger.rb +574 -0
- data/lib/tdriver/util/operator_data/loader.rb +4 -3
- data/lib/tdriver/util/operator_data/operator_data.rb +5 -5
- data/lib/tdriver/util/parameter/parameter.rb +7 -1
- data/lib/tdriver/util/parameter/parameter_hash.rb +1 -1
- data/lib/tdriver/util/parameter/parameter_template.rb +1 -1
- data/lib/tdriver/util/parameter/parameter_user_api.rb +28 -20
- data/lib/tdriver/util/parameter/parameter_xml.rb +1 -1
- data/lib/tdriver/util/plugin/abstract.rb +1 -1
- data/lib/tdriver/util/plugin/service.rb +1 -1
- data/lib/tdriver/util/{localisation.rb → recorder/loader.rb} +4 -3
- data/lib/tdriver/util/recorder/recorder.rb +66 -0
- data/lib/tdriver/util/recorder/scripter.rb +258 -0
- data/lib/tdriver/util/{stats.rb → statistics/statistics.rb} +7 -8
- data/lib/tdriver/util/user_data/error.rb +0 -1
- data/lib/tdriver/util/user_data/loader.rb +1 -2
- data/lib/tdriver/util/user_data/user_data.rb +6 -6
- data/lib/tdriver/util/video/camera.rb +67 -0
- data/lib/tdriver/util/video/camera_linux.rb +139 -0
- data/lib/tdriver/util/video/camera_windows.rb +174 -0
- data/lib/tdriver/util/video/loader.rb +31 -0
- data/lib/tdriver/util/video/video_utils.rb +139 -0
- data/lib/tdriver/util/xml/abstraction.rb +56 -5
- data/lib/tdriver/util/xml/builder.rb +2 -5
- data/lib/tdriver/util/{parameter.rb → xml/comment.rb} +10 -2
- data/lib/tdriver/util/xml/loader.rb +32 -22
- data/lib/tdriver/util/xml/nil_node.rb +2 -2
- data/lib/tdriver/util/xml/parsers/loader.rb +0 -1
- data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +18 -44
- data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +9 -13
- data/lib/tdriver/util/xml/parsers/nokogiri/builder.rb +9 -3
- data/lib/tdriver/util/xml/parsers/nokogiri/comment.rb +39 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +6 -11
- data/lib/tdriver/util/xml/parsers/nokogiri/element.rb +2 -122
- data/lib/tdriver/util/xml/parsers/nokogiri/loader.rb +26 -16
- data/lib/tdriver/util/xml/parsers/nokogiri/node.rb +203 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +1 -2
- data/lib/tdriver/util/xml/parsers/nokogiri/text.rb +2 -20
- data/lib/tdriver/util/xml/xml.rb +52 -20
- data/lib/tdriver/verify/verify.rb +238 -81
- data/xml/behaviours/generic.xml +12 -10
- metadata +156 -180
- data/lib/tdriver/base/test_object/factory_new.rb +0 -202
- data/lib/tdriver/util/hooking.rb +0 -434
- data/lib/tdriver/util/logger.rb +0 -506
- data/lib/tdriver/util/recorder.rb +0 -297
- data/lib/tdriver/util/video_utils.rb +0 -384
- 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
|
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
|
-
|
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"
|
243
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
25
|
+
include Singleton
|
26
|
+
|
27
|
+
def initialize
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
36
|
+
parse_behaviour_files(
|
37
37
|
|
38
|
-
|
38
|
+
load_behaviours( @@path )
|
39
39
|
|
40
|
-
|
40
|
+
)
|
41
41
|
|
42
|
-
|
42
|
+
end
|
43
43
|
|
44
|
-
|
44
|
+
public
|
45
45
|
|
46
|
-
|
46
|
+
def to_xml( rules = {} )
|
47
47
|
|
48
|
-
|
48
|
+
@_method_index = nil
|
49
49
|
|
50
|
-
|
50
|
+
rules.default = [ '*' ]
|
51
51
|
|
52
|
-
|
52
|
+
rules.each_pair{ | key, value |
|
53
53
|
|
54
|
-
|
54
|
+
rules[ key ] = [ value ] if value.kind_of?( String )
|
55
55
|
|
56
|
-
|
56
|
+
}
|
57
57
|
|
58
|
-
|
58
|
+
MobyUtil::XML.build{
|
59
59
|
|
60
|
-
|
60
|
+
behaviours{
|
61
61
|
|
62
|
-
|
62
|
+
@@behaviours.each_index{ | index |
|
63
63
|
|
64
|
-
|
64
|
+
@_method_index = index
|
65
65
|
|
66
|
-
|
66
|
+
behaviour = @@behaviours[ @_method_index ]
|
67
67
|
|
68
|
-
|
68
|
+
if ( ( rules[ :name ] == behaviour[ :name ] ) ||
|
69
69
|
|
70
|
-
|
70
|
+
( rules[ :name ] == [ '*' ] ) &&
|
71
71
|
|
72
|
-
#
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
90
|
+
end
|
91
91
|
|
92
|
-
|
92
|
+
}
|
93
93
|
|
94
|
-
|
94
|
+
}
|
95
95
|
|
96
|
-
|
96
|
+
}.to_xml
|
97
97
|
|
98
|
-
|
98
|
+
end
|
99
99
|
|
100
|
-
|
100
|
+
def get_behaviour_at_index( index )
|
101
101
|
|
102
|
-
|
102
|
+
result = @@behaviours[ index ]
|
103
103
|
|
104
|
-
|
104
|
+
if result.nil?
|
105
105
|
|
106
|
-
|
106
|
+
Kernel::raise RuntimeError.new( "No behaviour at index #{ index }" )
|
107
107
|
|
108
|
-
|
108
|
+
else
|
109
109
|
|
110
|
-
|
110
|
+
result
|
111
111
|
|
112
|
-
|
112
|
+
end
|
113
113
|
|
114
|
-
|
114
|
+
end
|
115
115
|
|
116
|
-
|
116
|
+
def apply_behaviour!( rules = {} )
|
117
117
|
|
118
|
-
|
119
|
-
|
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
|
-
|
123
|
+
Kernel::raise ArgumentError.new( "Target object not defined in rules hash" ) if rules[ :object ].nil?
|
124
124
|
|
125
|
-
|
126
|
-
|
125
|
+
# apply behaviours to target object
|
126
|
+
( get_object_behaviours( rules ) ).each{ | behaviour_index |
|
127
127
|
|
128
|
-
|
128
|
+
behaviour_data = @@behaviours[ behaviour_index ]
|
129
129
|
|
130
|
-
|
131
|
-
|
130
|
+
# skip if required plugin is not registered or enabled
|
131
|
+
next if behaviour_data[ :requires ].collect{ | plugin |
|
132
132
|
|
133
|
-
|
133
|
+
#MobyUtil::PluginService.instance.plugin_registered?( plugin ) && MobyUtil::PluginService.instance.plugin_enabled?( plugin )
|
134
134
|
|
135
|
-
|
136
|
-
|
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
|
-
|
138
|
+
}.include?( false )
|
139
139
|
|
140
|
-
|
140
|
+
begin
|
141
141
|
|
142
|
-
|
142
|
+
#behaviour_module = MobyUtil::KernelHelper.get_constant( behaviour_data[ :module ][ :name ] )
|
143
143
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
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
|
-
|
152
|
+
rescue NameError => exception
|
153
153
|
|
154
|
-
|
155
|
-
|
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
|
-
|
158
|
+
rescue Exception => exception
|
159
159
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
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
|
-
|
169
|
+
end
|
170
170
|
|
171
|
-
|
172
|
-
|
171
|
+
# add behaviour information to test object
|
172
|
+
rules[ :object ].instance_exec{
|
173
173
|
|
174
|
-
|
174
|
+
@object_behaviours.push( behaviour_index ) unless @object_behaviours.include? behaviour_index
|
175
175
|
|
176
|
-
|
176
|
+
}
|
177
177
|
|
178
|
-
|
178
|
+
}
|
179
179
|
|
180
|
-
|
180
|
+
end
|
181
181
|
|
182
|
-
|
182
|
+
private
|
183
183
|
|
184
|
-
|
184
|
+
def load_behaviours( behaviour_files )
|
185
185
|
|
186
|
-
|
186
|
+
behaviours_data = []
|
187
187
|
|
188
|
-
|
188
|
+
@file_name = ""
|
189
189
|
|
190
|
-
|
190
|
+
begin
|
191
191
|
|
192
|
-
|
192
|
+
Dir.glob( behaviour_files ).each { | behaviour |
|
193
193
|
|
194
|
-
|
194
|
+
@file_name = behaviour
|
195
195
|
|
196
|
-
|
196
|
+
behaviours_data << { :filename => @file_name, :xml => MobyUtil::FileHelper.get_file( @file_name ) }
|
197
197
|
|
198
|
-
|
198
|
+
}
|
199
199
|
|
200
|
-
|
200
|
+
rescue MobyUtil::EmptyFilenameError
|
201
201
|
|
202
|
-
|
202
|
+
Kernel::raise EmptyFilenameError.new( "Unable to load behaviours xml file due to filename is empty or nil" )
|
203
203
|
|
204
|
-
|
204
|
+
rescue MobyUtil::FileNotFoundError => ex
|
205
205
|
|
206
|
-
|
206
|
+
Kernel::raise ex
|
207
207
|
|
208
|
-
|
208
|
+
rescue IOError => ex
|
209
209
|
|
210
|
-
|
210
|
+
Kernel::raise IOError.new("Error occured while loading behaviours xml file %s. Reason: %s" % [ @file_name, ex.message ] )
|
211
211
|
|
212
|
-
|
212
|
+
rescue => ex
|
213
213
|
|
214
|
-
|
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
|
-
|
216
|
+
end
|
217
217
|
|
218
|
-
|
218
|
+
behaviours_data
|
219
219
|
|
220
|
-
|
220
|
+
end
|
221
221
|
|
222
|
-
|
222
|
+
def parse_behaviour_files( behaviour_files )
|
223
223
|
|
224
|
-
|
224
|
+
behaviour_files.each{ | behaviours |
|
225
225
|
|
226
|
-
|
226
|
+
begin
|
227
227
|
|
228
228
|
# skip parsing the xml if string is empty
|
229
229
|
next if behaviours[ :xml ].empty?
|
230
230
|
|
231
|
-
|
232
|
-
|
231
|
+
# parse behaviour xml
|
232
|
+
document = MobyUtil::XML.parse_string( behaviours[ :xml ] )
|
233
233
|
|
234
|
-
|
234
|
+
rescue => exception
|
235
235
|
|
236
|
-
|
237
|
-
|
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
|
-
|
240
|
+
end
|
241
241
|
|
242
|
-
|
243
|
-
|
242
|
+
# retrieve root attributes
|
243
|
+
root_attributes = document.root.xpath( "/behaviours" ).first.attributes
|
244
244
|
|
245
|
-
|
246
|
-
|
245
|
+
# parse retrieve behaviour definitions
|
246
|
+
document.root.xpath( "/behaviours/behaviour" ).each{ | node |
|
247
247
|
|
248
|
-
|
249
|
-
|
248
|
+
# retrieve behaviour attributes & module node
|
249
|
+
attributes = node.attributes
|
250
250
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
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
|
-
|
257
|
+
env = ( attributes[ "env" ] || '*' ).to_s
|
258
258
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
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
|
-
|
275
|
-
|
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
|
-
|
278
|
-
|
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
|
-
|
281
|
-
|
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
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
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
|
-
|
294
|
+
methods_hash = {}
|
295
295
|
|
296
|
-
|
297
|
-
|
296
|
+
# create hash of methods
|
297
|
+
node.xpath( 'methods/method' ).each{ | method |
|
298
298
|
|
299
|
-
|
300
|
-
|
299
|
+
# retrieve method description & example and store to methods hash
|
300
|
+
methods_hash[ method.attribute( "name" ).to_s.to_sym ] = {
|
301
301
|
|
302
|
-
|
302
|
+
:description => method.at_xpath( 'description/text()' ).to_s,
|
303
303
|
|
304
|
-
|
304
|
+
:example => method.at_xpath( 'example/text()' ).to_s
|
305
305
|
|
306
|
-
|
306
|
+
}
|
307
307
|
|
308
|
-
|
308
|
+
}
|
309
309
|
|
310
|
-
|
311
|
-
|
310
|
+
# create and store beahaviour hash
|
311
|
+
@@behaviours << {
|
312
312
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
#
|
318
|
-
|
319
|
-
|
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
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
321
|
+
:module => {
|
322
|
+
:file => module_file,
|
323
|
+
:name => module_name
|
324
|
+
},
|
325
325
|
|
326
|
-
|
326
|
+
:methods => methods_hash
|
327
327
|
|
328
|
-
|
328
|
+
}
|
329
329
|
|
330
|
-
|
330
|
+
}
|
331
331
|
|
332
|
-
|
332
|
+
}
|
333
333
|
|
334
|
-
|
334
|
+
end
|
335
335
|
|
336
|
-
|
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
|
-
|
348
|
+
rules.default = [ '*' ]
|
349
349
|
|
350
|
-
|
350
|
+
extended_modules = []
|
351
351
|
|
352
|
-
|
352
|
+
@@behaviours.each_with_index{ | behaviour, index |
|
353
353
|
|
354
|
-
|
354
|
+
if ( ( rules[ :name ] == behaviour[ :name ] ) ||
|
355
355
|
|
356
|
-
|
356
|
+
( rules[ :name ] == [ '*' ] &&
|
357
357
|
|
358
|
-
#
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
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
|
-
|
365
|
-
|
364
|
+
# retrieve list of extended modules
|
365
|
+
extended_modules << index
|
366
366
|
|
367
|
-
|
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
|
-
|
376
|
+
end
|
377
377
|
|
378
|
-
|
378
|
+
def get_behaviour_from_cache( target, sut_type, object_type, sut_version, input_type )
|
379
379
|
|
380
|
-
|
380
|
+
if @_behaviour_cache.has_key?( object_type )
|
381
381
|
|
382
|
-
|
383
|
-
|
382
|
+
# apply modules to target object
|
383
|
+
@_behaviour_cache[ object_type ].each{ | module_name | target.instance_eval( "self.extend(#{ module_name })" ) }
|
384
384
|
|
385
|
-
|
386
|
-
|
385
|
+
# return true
|
386
|
+
true
|
387
387
|
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
388
|
+
else
|
389
|
+
# return false
|
390
|
+
false
|
391
|
+
end
|
392
392
|
|
393
|
-
|
393
|
+
end
|
394
394
|
|
395
|
-
|
396
|
-
|
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
|
|