Sha256: 7de01bad160d2d58a899e7f65aac58e32c73b908d0990813278f95716c21f885

Contents?: true

Size: 1.96 KB

Versions: 1

Compression:

Stored size: 1.96 KB

Contents

#
# testing ruote
#
# Fri Apr 15 09:49:10 JST 2011
#
# over Canada, between SFO and FRA
#


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

require_json
Rufus::Json.detect_backend


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

  def test_read_text_file

    dir = "t_rtf_#{$$}_#{self.object_id}_#{Time.now.to_f}"
    fname = File.join(dir, 'message.txt')
    FileUtils.mkdir(dir)

    File.open(fname, 'wb') { |f| f.write('kilroy was here') }

    pdef = Ruote.process_definition do
      read fname, :to => 'x'
      read :from => fname, :to => 'f:y'
      read fname, :to => 'v:z'
      set 'f:z' => '$v:z'
    end

    #@engine.noisy = true

    wfid = @engine.launch(pdef)

    fields = @engine.wait_for(wfid)['workitem']['fields']

    assert_equal(
      [ 'kilroy was here' ],
      %w[ x y z ].collect { |k| fields[k] }.uniq)

  ensure
    FileUtils.rm_rf(dir)
  end

  def test_read_json_file

    dir = "t_rjf_#{$$}_#{self.object_id}_#{Time.now.to_f}"
    fname = File.join(dir, 'message.json')
    FileUtils.mkdir(dir)

    File.open(fname, 'wb') do |f|
      f.puts(Rufus::Json.encode('kilroy' => 'here'))
    end

    pdef = Ruote.process_definition do
      read fname, :to => 'x'
      read :from => fname, :to => 'f:y'
      read fname, :to => 'v:z'
      set 'f:z' => '$v:z'
    end

    #@engine.noisy = true

    wfid = @engine.launch(pdef)

    fields = @engine.wait_for(wfid)['workitem']['fields']

    assert_equal(
      [ { 'kilroy' => 'here' } ],
      %w[ x y z ].collect { |k| fields[k] }.uniq)

  ensure
    FileUtils.rm_rf(dir)
  end

  def test_read_http

    pdef = Ruote.process_definition do
      read 'http://ruote.s3.amazonaws.com/eft_36_read.txt', :to => :x
      read 'http://ruote.s3.amazonaws.com/eft_36_read.json', :to => :y
    end

    wfid = @engine.launch(pdef)

    fields = @engine.wait_for(wfid)['workitem']['fields']

    assert_equal("kilroy was here\n", fields['x'])
    assert_equal({ 'kilroy' => 'here' }, fields['y'])
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruote-maestrodev-2.2.1 test/functional/eft_36_read.rb