#
# Testing OpenWFE
#
# John Mettraux at openwfe.org
#
# Mon Oct 9 22:19:44 JST 2006
#
require 'test/unit'
require 'openwfe/expressions/raw_prog'
class RawProgTest < Test::Unit::TestCase
#def setup
#end
#def teardown
#end
$EXPRESSION_NAMES = [
"process-definition",
"sequence",
"participant",
"set",
"if",
"equals",
"print"
]
XML_DEF = """
""".strip
#
# TEST 0
#
class TestDefinition < OpenWFE::ProcessDefinition
def make
process_definition :name => "test0", :revision => "0" do
sequence do
participant :ref => "a"
participant :ref => "b"
end
end
end
end
def test_prog_0
#s = TestDefinition.new($EXPRESSION_NAMES).make.to_s
s = TestDefinition.new().make.to_s
#puts
#puts s
assert \
s == XML_DEF,
"parsing failed (0)"
end
def test_prog_0b
#s = TestDefinition.new($EXPRESSION_NAMES).make.to_s
s = TestDefinition.do_make.to_s
#puts
#puts s
assert \
s == XML_DEF,
"parsing failed (0b)"
end
#
# TEST 1
#
def test_prog_1
#pg = OpenWFE::ProcessDefinition.new($EXPRESSION_NAMES)
pg = OpenWFE::ProcessDefinition.new()
class << pg
def my_proc
process_definition :name => "test0", :revision => "0" do
sequence do
participant :ref => "a"
participant :ref => "b"
end
end
end
end
pdef = pg.my_proc
s = pdef.to_s
#puts s
assert \
s == XML_DEF,
"parsing failed (1)"
end
#
# TEST 2
#
class TestDefinition2 < OpenWFE::ProcessDefinition
def make
process_definition :name => "test2", :revision => "0" do
sequence do
set :field => "toto" do
"nada"
end
participant :ref => "b"
end
end
end
end
XML_DEF2 = """
nada
""".strip
def test_prog_2
s = TestDefinition2.do_make.to_s
#puts s
assert \
s == XML_DEF2,
"parsing failed (2)"
#puts
#puts TestDefinition2.do_make.to_code_s
end
#
# TEST 3
#
class TestDefinition3 < OpenWFE::ProcessDefinition
def make
process_definition :name => "test3", :revision => "0" do
_if do
equals :field_value => "nada", :other_value => "surf"
participant :ref => "b"
end
end
end
end
XML_DEF3 = """
""".strip
CODE_DEF3 = """
process_definition :name => 'test3', :revision => '0' do
_if do
equals :field_value => 'nada', :other_value => 'surf'
participant :ref => 'b'
end
end""".strip
def test_prog_3
s = TestDefinition3.do_make.to_s
#puts s
assert \
s == XML_DEF3,
"parsing failed (3)"
#puts
#puts TestDefinition3.do_make.to_code_s
assert \
TestDefinition3.do_make.to_code_s == CODE_DEF3,
"to_code_s() not working properly (3)"
end
#
# TEST 4
#
class TestDefinition4 < OpenWFE::ProcessDefinition
def make
process_definition :name => "test4", :revision => "0" do
sequence do
3.times { participant :ref => "b" }
end
end
end
end
CODE_DEF4 = """
process_definition :name => 'test4', :revision => '0' do
sequence do
participant :ref => 'b'
participant :ref => 'b'
participant :ref => 'b'
end
end""".strip
def test_prog_4
#puts
#puts TestDefinition4.do_make.to_s
#puts
#puts TestDefinition4.do_make.to_code_s
assert \
TestDefinition4.do_make.to_code_s == CODE_DEF4,
"to_code_s() not working properly (4)"
end
end