Module: MessageHandler

Included in:
TestScriptEngine, TestScriptRunnable
Defined in:
lib/testscript_engine/message_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#debug_modeObject

Returns the value of attribute debug_mode.



2
3
4
# File 'lib/testscript_engine/message_handler.rb', line 2

def debug_mode
  @debug_mode
end

#modify_reportObject

Returns the value of attribute modify_report.



2
3
4
# File 'lib/testscript_engine/message_handler.rb', line 2

def modify_report
  @modify_report
end

Instance Method Details

#begin_symbolObject



200
201
202
# File 'lib/testscript_engine/message_handler.rb', line 200

def begin_symbol
  [10551].pack("U*")
end

#cascade_skips(message_type, actions, *options) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/testscript_engine/message_handler.rb', line 45

def cascade_skips(message_type, actions, *options)
  print_out "#{outcome_symbol("SKIP")} #{messages(message_type, *options)}"
  increase_space
  counter = 0
  while counter < actions.length
    action = actions[counter]
    if action.operation
      id = "Operation: [#{(action.operation.id || action.operation.label || 'unlabeled')}]"
    else
      id = "Assert: [#{(action.assert.id || action.assert.label || 'unlabeled')}]" if action.assert
    end
    skip(:eval_assert_result, "#{id} skipped.")
    counter += 1
  end
  decrease_space
end

#client(*args) ⇒ Object

< —- TO REVIEW —- >



155
156
157
158
159
# File 'lib/testscript_engine/message_handler.rb', line 155

def client(*args)
  client = super
  FHIR.logger.formatter = logger_formatter_with_spacing
  client
end

#decrease_spaceObject



16
17
18
# File 'lib/testscript_engine/message_handler.rb', line 16

def decrease_space
  @space.chomp!(unit_of_space)
end

#error(message_type, *options) ⇒ Object



141
142
143
144
145
# File 'lib/testscript_engine/message_handler.rb', line 141

def error(message_type, *options)
  message = messages(message_type, *options)
  super(message) if modify_report
  print_out "#{outcome_symbol("ERROR")} #{message}"
end

#fail(message_type, *options) ⇒ Object



123
124
125
126
127
# File 'lib/testscript_engine/message_handler.rb', line 123

def fail(message_type, *options)
  message = messages(message_type, *options)
  super(message) if modify_report
  print_out "#{outcome_symbol("FAIL")} #{message}"
end

#finish_symbolObject



204
205
206
# File 'lib/testscript_engine/message_handler.rb', line 204

def finish_symbol
  [024465].pack("U*")
end

#increase_spaceObject



12
13
14
# File 'lib/testscript_engine/message_handler.rb', line 12

def increase_space
  space << unit_of_space
end

#info(message_type, *options) ⇒ Object



41
42
43
# File 'lib/testscript_engine/message_handler.rb', line 41

def info(message_type, *options)
  print_out messages(message_type, *options)
end

#load_fixturesObject



111
112
113
114
115
# File 'lib/testscript_engine/message_handler.rb', line 111

def load_fixtures
  increase_space
  super
  decrease_space
end

#load_scriptsObject



62
63
64
65
66
# File 'lib/testscript_engine/message_handler.rb', line 62

def load_scripts
  print_out messages(:begin_loading_scripts, testscript_path)
  super
  print_out messages(:finish_loading_scripts)
end

#logger_formatter_with_spacingObject



165
166
167
168
169
170
171
172
173
# File 'lib/testscript_engine/message_handler.rb', line 165

def logger_formatter_with_spacing
  logger_formatters_with_spacing[space.length] || begin
    new_logger_formatter = proc do |severity, datetime, progname, msg|
      "#{space}#{unit_of_space}#{msg}\n"
    end
    logger_formatters_with_spacing[space.length] = new_logger_formatter
    new_logger_formatter
  end
end

#logger_formatters_with_spacingObject



161
162
163
# File 'lib/testscript_engine/message_handler.rb', line 161

def logger_formatters_with_spacing
  @logger_formatters_with_spacing ||= {}
end

#make_runnablesObject



68
69
70
71
72
73
74
# File 'lib/testscript_engine/message_handler.rb', line 68

def make_runnables
  print_out messages(:begin_creating_runnables)
  increase_space
  super
  decrease_space
  print_out messages(:finish_creating_runnables)
end

#messages(message, *options) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/testscript_engine/message_handler.rb', line 208

def messages(message, *options)
  message_text = case message
  when :abort_test
    "Due to an unsuccessful action in the [#{options[0]}] phase, remaining actions in this test will be skipped. Skipping the next #{options[1]} action(s)."
  when :bad_script
    "Given non-TestScript resource. Can not create runnable."
  when :bad_serialized_script
    "Can not deserialize resource into TestScript: [#{options[0]}]."
  when :begin_initialize_client
    start_message_format("INITIALIZE CLIENT")
  when :begin_creating_runnables
    start_message_format("MAKE RUNNABLE(S)")
  when :created_runnable
    "Created runnable from TestScript: [#{options[0]}]."
  when :finish_creating_runnables
    finish_message_format("MAKING RUNNABLE(S)")
  when :finish_initialize_client
    finish_message_format("INITIALIZING CLIENT")
  when :invalid_script
    "Can not load TestScript. Invalid resource: [#{options[0]}]."
  when :invalid_script
    "Given invalid TestScript resource. Can not create runnable."
  when :loaded_script
    "Loaded TestScript: [#{options[0]}]."
  when :loaded_static_fixture
    "Loaded static fixture [#{options[0]}]."
  when :no_postprocess
    "Nothing to postprocess."
  when :no_preprocess
    "Nothing to preprocess."
  when :no_setup
    "Nothing to setup."
  when :no_teardown
    "Nothing to teardown."
  when :overwrite_existing_script
    "Overwriting previously loaded TestScript: [#{options[0]}]."
  when :skip_on_fail
    "Due to the preceeding unsuccessful action, skipping the next #{options[0]} action(s)."
  when :unable_to_create_runnable
    "Can not create runnable from TestScript: [#{options[0]}]."
  when :unable_to_locate_runnable
    "Can not locate runnable with id: [#{options[0]}]. Can not execute."
  when :assertion_error
    "ERROR: Unable to process assertion: #{options[0]}"
  when :assertion_exception
    "#{options[0]}"
  when :bad_reference
    "Unable to read contents of reference: [#{options[0]}]. No reference extracted."
  when :bad_request
    "Unable to create a request from operation."
  when :bad_static_fixture_reference
    "Static fixture included unresolvable reference. Can not load fixture. Moving on."
  when :begin_loading_scripts
    start_message_format("LOAD TESTSCRIPTS", options[0])
  when :begin_preprocess
    start_message_format("PREPROCESS", options[0])
  when :begin_runnable_execution
    start_message_format("EXECUTE RUNNABLE", options[0])
  when :begin_setup
    start_message_format("SETUP")
  when :begin_teardown
    start_message_format("TEARDOWN")
  when :begin_test
    start_message_format("TEST")
  when :eval_assert_result
    "#{options[0]}"
  when :evaluate_assert
    "EVALUATING ASSERTION"
  when :execute_operation
    "OPERATION EXECUTION"
  when :execute_operation_error
    "Unable to execute operation. ERROR: [#{options[0]}]. [#{options[1]}]"
  when :finish_loading_scripts
    finish_message_format("LOADING SCRIPTS")
  when :finish_preprocess
    finish_message_format("PREPROCESS")
  when :finish_runnable_execution
    finish_message_format("EXECUTING RUNNABLE. FINAL EXECUTION SCORE: [#{testreport.score}]")
  when :finish_setup
    finish_message_format("SETUP")
  when :finish_teardown
    finish_message_format("TEARDOWN")
  when :finish_test
    finish_message_format("TEST")
  when :invalid_assert
    "Invalid assert. Can not evaluate."
  when :invalid_dump
    "Validation error: [#{options[0]}]"
  when :invalid_operation
    "Invalid operation. Can not execute."
  when :invalid_request
    "Unable to create a request using operation: [#{options[0]}]. Can not execute."
  when :no_contained_resource
    "Reference [#{options[0]}] refers to a contained resource that does not exist. Moving on."
  when :no_path
    "Unable to extract path from operation."
  when :no_reference
    "Reference element of reference object is nil. Can not get resource from reference."
  when :no_static_fixture_id
    "No ID for static fixture. Can not load."
  when :no_static_fixture_reference
    "No reference for static fixture. Can not load."
  when :no_static_fixture_resource
    "No resource for static fixture. Can not load."
  when :pass_execute_operation
    "Executed Operation: [#{options[0]}]"
  when :resource_extraction
    "Unable to extract resource referenced by [#{options[0]}]. Encountered: [#{options[1]}]."
  when :uncaught_error
    "Uncaught error: [#{options[0]}]."
  when :unsupported_ref
    "Remote reference: [#{options[0]}] not supported. No reference extracted."
  else
    "! unknown message type !"
  end
end

#newlineObject



20
21
22
# File 'lib/testscript_engine/message_handler.rb', line 20

def newline
  puts
end

#outcome_symbol(outcome) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/testscript_engine/message_handler.rb', line 175

def outcome_symbol(outcome)
  symbol = begin
    case outcome
    when "UNKNOWN"
      "?¿?"
    when "FATAL"
      [023042].pack("U*")
    when "ERROR"
      [10071].pack("U*")
    when "WARN"
      [023220].pack("U*")
    when "INFO"
      [10003].pack("U*")
    when "DEBUG"
      [0372415].pack("U*")
    when "FAIL"
      [10007].pack("U*")
    when "SKIP"
      "\u21BB".encode('utf-8')
    end
  end

  "(#{symbol})"
end

#pass(message_type, *options) ⇒ Object



117
118
119
120
121
# File 'lib/testscript_engine/message_handler.rb', line 117

def pass(message_type, *options)
  message = messages(message_type, *options)
  super()
  print_out "#{outcome_symbol("INFO")} #{message}"
end

#postprocessingObject



108
109
# File 'lib/testscript_engine/message_handler.rb', line 108

def postprocessing
end

#preprocessObject



84
85
86
87
88
# File 'lib/testscript_engine/message_handler.rb', line 84

def preprocess
  print_out messages(:begin_preprocess)
  super
  print_out messages(:finish_preprocess)
end


147
148
149
150
151
152
# File 'lib/testscript_engine/message_handler.rb', line 147

def print_action_header(action_type)
  return false if @previous_action_type == action_type

  @previous_action_type = action_type
  true
end


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/testscript_engine/message_handler.rb', line 24

def print_out(message)
  if message.start_with?("START")
    newline
    increase_space
  elsif message.start_with?("FINISH")
  else
    print unit_of_space
  end
  print space
  puts message

  if message.start_with?("FINISH")
    decrease_space
  end
  nil
end

#run(*args) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/testscript_engine/message_handler.rb', line 76

def run(*args)
  print_out messages(:begin_runnable_execution, script.id)
  result = super
  puts
  print_out messages(:finish_runnable_execution)
  result
end

#setupObject



90
91
92
93
94
# File 'lib/testscript_engine/message_handler.rb', line 90

def setup
  print_out messages(:begin_setup)
  super
  print_out messages(:finish_setup)
end

#skip(message_type, *options) ⇒ Object



129
130
131
132
133
# File 'lib/testscript_engine/message_handler.rb', line 129

def skip(message_type, *options)
  message = messages(message_type, *options)
  super(message) if modify_report
  print_out "#{outcome_symbol("SKIP")} #{message}"
end

#spaceObject



4
5
6
# File 'lib/testscript_engine/message_handler.rb', line 4

def space
  @space ||= ''
end

#teardownObject



102
103
104
105
106
# File 'lib/testscript_engine/message_handler.rb', line 102

def teardown
  print_out messages(:begin_teardown)
  super
  print_out messages(:finish_teardown)
end

#testObject



96
97
98
99
100
# File 'lib/testscript_engine/message_handler.rb', line 96

def test
  print_out messages(:begin_test)
  super
  print_out messages(:finish_test)
end

#unit_of_spaceObject



8
9
10
# File 'lib/testscript_engine/message_handler.rb', line 8

def unit_of_space
  "   "
end

#warning(message_type, *options) ⇒ Object



135
136
137
138
139
# File 'lib/testscript_engine/message_handler.rb', line 135

def warning(message_type, *options)
  message = messages(message_type, *options)
  super(message) if modify_report
  print_out "#{outcome_symbol("WARN")} #{message}"
end