Sha256: d836814bc7662a5bb1fbb09e0743be378ad22286340f5cbeebf91a16b2ee762b

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

#
# testing ruote
#
# Thu Apr 22 14:41:38 JST 2010
#

require File.join(File.dirname(__FILE__), 'base')

require 'ruote/part/local_participant'


class FtParticipantOnReplyTest < Test::Unit::TestCase
  include FunctionalBase

  class MyParticipant
    include Ruote::LocalParticipant
    def initialize (opts)
    end
    def consume (workitem)
      reply(workitem)
    end
    def on_reply (workitem)
      workitem.fields['message'] = 'hello'
    end
  end

  def test_participant_on_reply

    pdef = Ruote.process_definition do
      sequence do
        alpha
        echo '${f:message}'
      end
    end

    @engine.register_participant :alpha, MyParticipant

    #noisy

    assert_trace('hello', pdef)
  end

  def test_instantiated_participant_on_reply

    pdef = Ruote.process_definition do
      sequence do
        alpha
        echo '${f:message}'
      end
    end

    @engine.register_participant :alpha, MyParticipant.new(nil)
      # instantiated participant :-(

    #noisy

    assert_trace('hello', pdef)
  end

  class AwkwardParticipant
    include Ruote::LocalParticipant
    def initialize (opts)
    end
    def consume (workitem)
      reply(workitem)
    end
    def on_reply (workitem)
      return if workitem.fields['pass']
      raise "something went wrong"
    end
  end

  def test_participant_on_reply_error

    pdef = Ruote.process_definition do
      sequence do
        alpha
        echo 'over.'
      end
    end

    @engine.register_participant :alpha, AwkwardParticipant

    #noisy

    wfid = @engine.launch(pdef)

    wait_for(wfid)

    ps = @engine.process(wfid)

    assert_equal 1, ps.errors.size

    err = ps.errors.first
    err.fields['pass'] = true
    @engine.replay_at_error(err)

    wait_for(wfid)

    assert_equal 'over.', @tracer.to_s
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruote-2.1.11 test/functional/ft_43_participant_on_reply.rb