#_ # 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 persistence = ENV["__persistence__"] $WORKFLOW_ENGINE_CLASS = Engine if persistence == "FilePersistedEngine" require "openwfe/engine/file_persisted_engine" $WORKFLOW_ENGINE_CLASS = FilePersistedEngine end puts puts "testing with engine of class " + $WORKFLOW_ENGINE_CLASS.to_s #puts "testing with engine of class " + ENV["workflow_engine_class"] puts class FlowTestBase < Test::Unit::TestCase attr_reader \ :engine, :tracer def setup @engine = eval("#{$WORKFLOW_ENGINE_CLASS}").new() @tracer = Tracer.new @engine.application_context["__tracer"] = @tracer end def teardown @engine.stop end def default_test () assert true end protected def test_name s = caller(1)[0] i = s.index('`') #s = s[i+1..s.length-2] s = s[i+6..s.length-2] return s end def dotest (flowDef, expectedTrace, sleepTime=0, allowRemainingExpressions=false) @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 = OpenWFE::LaunchItem.new(flowDef) @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 assert \ result, "flow failed : trace doesn't correspond to any expected traces" else assert \ trace == expectedTrace, \ """flow failed : '#{trace}' != '#{expectedTrace}' """ end #exp_storage = \ # engine.application_context[S_EXPRESSION_STORAGE] exp_storage = engine.get_expression_storage if allowRemainingExpressions exp_storage.purge return end 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})" end end