#_ # Testing OpenWFE # # John Mettraux at openwfe.org # # Sun Oct 29 15:41:44 JST 2006 # # somewhere between Philippina and the Japan # require 'test/unit' require 'openwfe/workitem' require 'openwfe/engine/engine' require 'openwfe/rudefinitions' require 'openwfe/participants/participants' require 'rutest_utils' include OpenWFE $WORKFLOW_ENGINE_CLASS = Engine persistence = ENV["__persistence__"] require "openwfe/engine/file_persisted_engine" if persistence if persistence == "pure-persistence" $WORKFLOW_ENGINE_CLASS = FilePersistedEngine elsif persistence == "cached-persistence" $WORKFLOW_ENGINE_CLASS = CachedFilePersistedEngine end puts puts "testing with engine of class " + $WORKFLOW_ENGINE_CLASS.to_s puts #class FlowTestBase < Test::Unit::TestCase module FlowTestBase attr_reader \ :engine, :tracer def setup @engine = $WORKFLOW_ENGINE_CLASS.new() @engine.application_context[:ruby_eval_allowed] = true @tracer = Tracer.new @engine.application_context["__tracer"] = @tracer @engine.register_participant('pp-workitem') do |workitem| puts require 'pp'; pp workitem puts end end def teardown @engine.stop end #def default_test () # assert true #end protected def print_exp_list (l) puts l.each do |fexp| puts " - #{fexp.fei.to_debug_s}" end puts end def name_of_test s = caller(1)[0] i = s.index('`') #s = s[i+1..s.length-2] s = s[i+6..s.length-2] return s end # # dotest() # def dotest (flowDef, expectedTrace, sleepTime=0, allowRemainingExpressions=false) @tracer.clear @engine.register_participant('test-.*', PrintParticipant.new()) @engine.register_participant('block-participant') do |workitem| @tracer << "the block participant received a workitem" @tracer << "\n" end @engine.register_participant('p-toto') do |workitem| @tracer << "toto" end # @engine.register_participant( # 'eno', # EmailNotificationParticipant.new( # "googlemail.l.google.com", # 25, # "eno@outoftheblue.co.jp", # """Subject: test 0 # #0 : ${r:Time.new} #1 : ${f:customer_name} # """)) # register unique tracing participant li = if flowDef.kind_of? OpenWFE::LaunchItem flowDef else OpenWFE::LaunchItem.new(flowDef) end fei = @engine.launch(li) sleep(sleepTime) trace = @tracer.to_s #puts "...'#{trace}' ?= '#{expectedTrace}'" if expectedTrace.kind_of? [].class result = false expectedTrace.each do |etrace| result = (result or (trace == etrace)) end unless result puts puts ">#{trace}<" puts end assert \ result, "flow failed : trace doesn't correspond to any expected traces" else assert \ trace == expectedTrace, \ """flow failed : '#{trace}' != '#{expectedTrace}' """ end if allowRemainingExpressions engine.get_expression_storages.each do |storage| storage.purge end return end exp_storage = engine.get_expression_storage if exp_storage.length != 1 puts puts " remaining expressions : #{exp_storage.length}" puts puts exp_storage.to_s puts end assert \ exp_storage.length == 1, "there are expressions remaining in the expression pool " + "(#{exp_storage.length})" return fei end end