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.
- data/lib/tdriver/base/behaviour/behaviours/object_behaviour_composition.rb +1 -1
- data/lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb +11 -7
- data/lib/tdriver/base/behaviour/behaviours/object_composition.rb +8 -0
- data/lib/tdriver/base/behaviour/factory.rb +229 -209
- data/lib/tdriver/base/errors.rb +3 -0
- data/lib/tdriver/base/state_object.rb +11 -20
- data/lib/tdriver/base/sut/controller.rb +4 -4
- data/lib/tdriver/base/sut/factory.rb +205 -170
- data/lib/tdriver/base/sut/generic/behaviours/application.rb +256 -174
- data/lib/tdriver/base/sut/generic/behaviours/find.rb +17 -11
- data/lib/tdriver/base/sut/generic/behaviours/flash_behaviour.rb +57 -66
- data/lib/tdriver/base/sut/generic/behaviours/sut.rb +578 -497
- data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +41 -15
- data/lib/tdriver/base/sut/generic/behaviours/verification.rb +48 -19
- data/lib/tdriver/base/sut/generic/commands/fixture.rb +47 -0
- data/lib/tdriver/base/sut/generic/commands/key_sequence.rb +25 -13
- data/lib/tdriver/base/sut/generic/commands/screen_capture.rb +16 -10
- data/lib/tdriver/base/sut/generic/plugin.rb +9 -3
- data/lib/tdriver/base/sut/sut.rb +41 -33
- data/lib/tdriver/base/test_object/abstract.rb +26 -3
- data/lib/tdriver/base/test_object/adapter.rb +399 -0
- data/lib/tdriver/base/test_object/behaviours/syncronization.rb +56 -14
- data/lib/tdriver/base/test_object/behaviours/test_object.rb +663 -197
- data/lib/tdriver/base/test_object/cache.rb +132 -0
- data/lib/tdriver/base/test_object/factory.rb +677 -426
- data/lib/tdriver/base/test_object/factory_new.rb +202 -0
- data/lib/tdriver/base/test_object/identificator.rb +24 -17
- data/lib/tdriver/base/test_object/loader.rb +9 -3
- data/lib/tdriver/base/test_object/verification.rb +181 -0
- data/lib/tdriver/loader.rb +1 -1
- data/lib/tdriver/report/report.rb +2 -0
- data/lib/tdriver/report/report_api.rb +4 -4
- data/lib/tdriver/report/report_creator.rb +29 -3
- data/lib/tdriver/report/report_data_presentation.rb +7 -3
- data/lib/tdriver/report/report_execution_statistics.rb +80 -21
- data/lib/tdriver/report/report_javascript.rb +192 -0
- data/lib/tdriver/report/report_test_case_run.rb +22 -0
- data/lib/tdriver/report/report_test_run.rb +62 -55
- data/lib/tdriver/report/report_writer.rb +57 -56
- data/lib/tdriver/tdriver.rb +14 -41
- data/lib/tdriver/util/common/error.rb +1 -0
- data/lib/tdriver/util/common/exceptions.rb +12 -0
- data/lib/tdriver/util/common/file.rb +12 -6
- data/lib/tdriver/util/common/gem.rb +2 -1
- data/lib/tdriver/util/common/hash.rb +152 -0
- data/lib/tdriver/util/common/kernel.rb +49 -34
- data/lib/tdriver/util/common/loader.rb +21 -17
- data/lib/tdriver/util/common/numeric.rb +39 -0
- data/lib/tdriver/util/common/object.rb +115 -0
- data/lib/tdriver/util/common/string.rb +55 -2
- data/lib/tdriver/util/dbaccess/dbaccess.rb +194 -161
- data/lib/tdriver/util/dynamic_attribute_filter.rb +6 -0
- data/lib/tdriver/util/hooking.rb +2 -2
- data/lib/tdriver/util/loader.rb +2 -2
- data/lib/tdriver/util/localisation/localisation.rb +277 -18
- data/lib/tdriver/util/logger.rb +142 -13
- data/lib/tdriver/util/parameter/parameter_hash.rb +8 -5
- data/lib/tdriver/util/parameter/parameter_xml.rb +18 -2
- data/lib/tdriver/util/recorder.rb +17 -12
- data/lib/tdriver/util/user_data/user_data.rb +3 -2
- data/lib/tdriver/util/{video_rec.rb → video_utils.rb} +136 -16
- data/lib/tdriver/util/xml/abstraction.rb +7 -0
- data/lib/tdriver/util/xml/attribute.rb +32 -0
- data/lib/tdriver/util/xml/loader.rb +8 -2
- data/lib/tdriver/util/xml/nil_node.rb +95 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +46 -7
- data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +19 -9
- data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +1 -1
- data/lib/tdriver/util/xml/parsers/nokogiri/element.rb +13 -1
- data/lib/tdriver/util/xml/parsers/nokogiri/loader.rb +6 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +27 -15
- data/lib/tdriver/util/xml/parsers/nokogiri/text.rb +57 -0
- data/lib/tdriver/util/xml/text.rb +32 -0
- data/lib/tdriver/util/xml/xml.rb +35 -22
- data/lib/tdriver/version.rb +1 -1
- data/lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb +41 -34
- data/lib/tdriver-devtools/doc/generate.rb +31 -6
- data/lib/tdriver-devtools/doc/xslt/template.xsl +46 -25
- data/lib/tdriver-devtools/tests/feature_tests/example/behaviour_example.rb +100 -0
- data/lib/tdriver-devtools/tests/feature_tests/update +1 -1
- data/lib/tdriver.rb +0 -3
- data/xml/behaviours/generic.xml +1 -1
- data/xml/defaults/generic.xml +4 -90
- data/xml/templates/generic.xml +33 -25
- metadata +21 -29
- data/lib/tdriver-devtools/behaviour/xml_generator/example/flick-example.rb +0 -245
- data/lib/tdriver-devtools/behaviour/xml_generator/example/sut.rb +0 -964
- data/lib/tdriver-devtools/behaviour/xml_generator/generate.rb +0 -68
- data/lib/tdriver-devtools/behaviour/xml_generator/lib/custom_rdoc_generator.rb +0 -1865
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument.default.template +0 -1
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument.template +0 -3
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument_type.template +0 -4
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.exception.template +0 -4
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.arguments.template +0 -4
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.deprecated.template +0 -3
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.exceptions.template +0 -3
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.info.template +0 -1
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.returns.template +0 -3
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.tables.template +0 -3
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.template +0 -12
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.returns.template +0 -5
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.item.template +0 -1
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.row.template +0 -2
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.template +0 -7
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.template +0 -14
- data/lib/tdriver-devtools/behaviour/xml_generator/update +0 -3
- data/lib/tdriver-devtools/tests/feature_tests/example/flick-example.rb +0 -233
- 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
|
-
# ==
|
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
|
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
|
-
|
23
|
-
|
22
|
+
# TODO: document BehaviourFactory class
|
23
|
+
class BehaviourFactory
|
24
24
|
|
25
|
-
|
25
|
+
include Singleton
|
26
26
|
|
27
|
-
|
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
135
|
# verify if plugin is enabled -- exception will be catched if plugin is not registered
|
136
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
159
|
-
"Implementation for behaviour %s does not exist. (%s)" % [ behaviour_data[ :name ], behaviour_data[ :module ][ :name ] ]
|
160
|
-
)
|
169
|
+
end
|
161
170
|
|
162
|
-
|
171
|
+
# add behaviour information to test object
|
172
|
+
rules[ :object ].instance_exec{
|
163
173
|
|
164
|
-
|
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
|
-
|
176
|
+
}
|
174
177
|
|
175
|
-
|
176
|
-
rules[ :object ].instance_exec{
|
178
|
+
}
|
177
179
|
|
178
|
-
|
180
|
+
end
|
179
181
|
|
180
|
-
|
182
|
+
private
|
181
183
|
|
182
|
-
|
184
|
+
def load_behaviours( behaviour_files )
|
183
185
|
|
184
|
-
|
186
|
+
behaviours_data = []
|
185
187
|
|
186
|
-
|
188
|
+
@file_name = ""
|
187
189
|
|
188
|
-
|
190
|
+
begin
|
189
191
|
|
190
|
-
|
192
|
+
Dir.glob( behaviour_files ).each { | behaviour |
|
191
193
|
|
192
|
-
|
194
|
+
@file_name = behaviour
|
193
195
|
|
194
|
-
|
196
|
+
behaviours_data << { :filename => @file_name, :xml => MobyUtil::FileHelper.get_file( @file_name ) }
|
195
197
|
|
196
|
-
|
198
|
+
}
|
197
199
|
|
198
|
-
|
200
|
+
rescue MobyUtil::EmptyFilenameError
|
199
201
|
|
200
|
-
|
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
|
-
|
206
|
+
Kernel::raise ex
|
205
207
|
|
206
|
-
|
208
|
+
rescue IOError => ex
|
207
209
|
|
208
|
-
|
210
|
+
Kernel::raise IOError.new("Error occured while loading behaviours xml file %s. Reason: %s" % [ @file_name, ex.message ] )
|
209
211
|
|
210
|
-
|
212
|
+
rescue => ex
|
211
213
|
|
212
|
-
|
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
|
-
|
216
|
+
end
|
215
217
|
|
216
|
-
|
218
|
+
behaviours_data
|
217
219
|
|
218
|
-
|
220
|
+
end
|
219
221
|
|
220
|
-
|
222
|
+
def parse_behaviour_files( behaviour_files )
|
221
223
|
|
222
|
-
|
224
|
+
behaviour_files.each{ | behaviours |
|
223
225
|
|
224
|
-
|
226
|
+
begin
|
225
227
|
|
226
|
-
|
228
|
+
# skip parsing the xml if string is empty
|
229
|
+
next if behaviours[ :xml ].empty?
|
227
230
|
|
228
|
-
|
231
|
+
# parse behaviour xml
|
232
|
+
document = MobyUtil::XML.parse_string( behaviours[ :xml ] )
|
229
233
|
|
230
|
-
|
234
|
+
rescue => exception
|
231
235
|
|
232
|
-
|
233
|
-
|
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
|
-
|
240
|
+
end
|
236
241
|
|
237
|
-
|
238
|
-
|
239
|
-
)
|
242
|
+
# retrieve root attributes
|
243
|
+
root_attributes = document.root.xpath( "/behaviours" ).first.attributes
|
240
244
|
|
241
|
-
|
245
|
+
# parse retrieve behaviour definitions
|
246
|
+
document.root.xpath( "/behaviours/behaviour" ).each{ | node |
|
242
247
|
|
243
|
-
|
244
|
-
|
248
|
+
# retrieve behaviour attributes & module node
|
249
|
+
attributes = node.attributes
|
245
250
|
|
246
|
-
|
247
|
-
|
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
|
-
|
250
|
-
attributes = node.attributes
|
257
|
+
env = ( attributes[ "env" ] || '*' ).to_s
|
251
258
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
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
|
-
|
259
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
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
|
-
|
294
|
+
methods_hash = {}
|
276
295
|
|
277
|
-
|
296
|
+
# create hash of methods
|
297
|
+
node.xpath( 'methods/method' ).each{ | method |
|
278
298
|
|
279
|
-
|
280
|
-
|
299
|
+
# retrieve method description & example and store to methods hash
|
300
|
+
methods_hash[ method.attribute( "name" ).to_s.to_sym ] = {
|
281
301
|
|
282
|
-
|
283
|
-
methods_hash[ method.attribute( "name" ).to_s.to_sym ] = {
|
302
|
+
:description => method.at_xpath( 'description/text()' ).to_s,
|
284
303
|
|
285
|
-
|
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
|
-
|
293
|
-
|
310
|
+
# create and store beahaviour hash
|
311
|
+
@@behaviours << {
|
294
312
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
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
|
-
|
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
|
-
|
332
|
+
}
|
316
333
|
|
317
|
-
|
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
|
-
|
348
|
+
rules.default = [ '*' ]
|
330
349
|
|
331
|
-
|
350
|
+
extended_modules = []
|
332
351
|
|
333
|
-
|
352
|
+
@@behaviours.each_with_index{ | behaviour, index |
|
334
353
|
|
335
|
-
|
354
|
+
if ( ( rules[ :name ] == behaviour[ :name ] ) ||
|
336
355
|
|
337
|
-
|
356
|
+
( rules[ :name ] == [ '*' ] &&
|
338
357
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
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
|
-
|
345
|
-
|
364
|
+
# retrieve list of extended modules
|
365
|
+
extended_modules << index
|
346
366
|
|
347
|
-
|
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
|
-
|
376
|
+
end
|
357
377
|
|
358
|
-
|
378
|
+
def get_behaviour_from_cache( target, sut_type, object_type, sut_version, input_type )
|
359
379
|
|
360
|
-
|
380
|
+
if @_behaviour_cache.has_key?( object_type )
|
361
381
|
|
362
|
-
|
363
|
-
|
382
|
+
# apply modules to target object
|
383
|
+
@_behaviour_cache[ object_type ].each{ | module_name | target.instance_eval( "self.extend(#{ module_name })" ) }
|
364
384
|
|
365
|
-
|
366
|
-
|
385
|
+
# return true
|
386
|
+
true
|
367
387
|
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
388
|
+
else
|
389
|
+
# return false
|
390
|
+
false
|
391
|
+
end
|
372
392
|
|
373
|
-
|
393
|
+
end
|
374
394
|
|
375
|
-
|
376
|
-
|
395
|
+
# enable hooking for performance measurement & debug logging
|
396
|
+
MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
|
377
397
|
|
378
|
-
|
398
|
+
end # BehaviourGenerator
|
379
399
|
|
380
400
|
end # MobyBase
|