Index: openacs-4/contrib/obsolete-packages/acs-workflow/sql/oracle/test/workflow-case-package-test.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/acs-workflow/sql/oracle/test/workflow-case-package-test.sql,v diff -u -N -r1.2 -r1.3 --- openacs-4/contrib/obsolete-packages/acs-workflow/sql/oracle/test/workflow-case-package-test.sql 12 Apr 2001 04:38:52 -0000 1.2 +++ openacs-4/contrib/obsolete-packages/acs-workflow/sql/oracle/test/workflow-case-package-test.sql 2 Sep 2001 17:35:44 -0000 1.3 @@ -1,543 +1,516 @@ --- set serveroutput on size 1000000 format wrapped +set serveroutput on size 1000000 format wrapped -- requires the utPLSQL system -- -- modify this line to suit your needs -- -- exec utplsql.setdir('/web/lars-dev2/packages/acs-kernel/sql'); --- exec utplsql.autocompile (false); +exec utplsql.autocompile (false); --- create or replace package ut#workflow_case --- as --- --- procedure setup; --- --- procedure teardown; --- --- procedure run; --- --- end ut#workflow_case; --- / --- show errors +create or replace package ut#workflow_case +as --- create or replace package body ut#workflow_case + procedure setup; -create function ut_assert__eq(varchar,integer,integer) returns integer as ' -declare - msg alias for $1; - v_in alias for $2; - v_chk alias for $3; -begin - if v_in != v_chk then - raise NOTICE ''%'', v_msg; - end if; + procedure teardown; - return null; + procedure run; -end;' language 'plpgsql'; +end ut#workflow_case; +/ +show errors -create function setup() returns integer as ' -declare +create or replace package body ut#workflow_case +as + + procedure setup + is wf_count number; -begin - PERFORM teardown(); - raise NOTICE ''Setting up...''; + begin + teardown; + dbms_output.put_line('Setting up...'); - /* We assume that the sample-expenses workflow is loaded and - unchanged from the original */ - - select case when count(*) = 0 then 0 else 1 end - into wf_count - from wf_workflows - where workflow_key = ''expenses_wf''; - + /* We assume that the sample-expenses workflow is loaded and unchanged from the original */ + select decode(count(*),0,0,1) into wf_count from wf_workflows where workflow_key = 'expenses_wf'; if wf_count = 0 then - raise EXCEPTION ''-20000: The sample-expenses workflow must be loaded (and unchanged from the original)''; + raise_application_error(-20000, 'The sample-expenses workflow must be loaded (and unchanged from the original)'); end if; + + - return null; + utplsql.setpkg('workflow_case'); + utplsql.addtest('run'); + end; -end;' language 'plpgsql'; - -create functin teardown() returns integer as ' -begin - raise NOTICE ''Tearing down...''; + procedure teardown + is + begin + dbms_output.put_line('Tearing down...'); -end;' language 'plpgsql'; + end; -create function run() returns integer as ' -declare - v_workflow_key wf_workflows.workflow_key%TYPE; - v_object_id acs_objects.object_id%TYPE; - v_case_id wf_cases.case_id%TYPE; - v_count number; - v_task_id number; - v_journal_id number; - v_user_id number; - v_state varchar(100); -begin - v_workflow_key := ''expenses_wf''; + procedure run + is + v_workflow_key wf_workflows.workflow_key%TYPE; + v_object_id acs_objects.object_id%TYPE; + v_case_id wf_cases.case_id%TYPE; + v_count number; + v_task_id number; + v_journal_id number; + v_user_id number; + v_state varchar2(100); + begin + v_workflow_key := 'expenses_wf'; - raise NOTICE ''Running test...''; + dbms_output.put_line('Running test...'); /* Pick out a random object ... we just hope there is one somewhere */ - select object_id into v_object_id - from acs_objects - limit 1; + select object_id into v_object_id from acs_objects where rownum = 1; - raise NOTICE ''. new case''; + dbms_output.put_line('. new case'); - v_case_id := workflow_case__new( - null, - v_workflow_key, - ''default'', - v_object_id, - now(), - null, - null + v_case_id := workflow_case.new( + workflow_key => v_workflow_key, + context_key => 'default', + object_id => v_object_id ); - raise NOTICE ''. manual assignments''; + dbms_output.put_line('. manual assignments'); /* we need a random user_id */ select user_id into v_user_id from users - limit 1; + where rownum = 1; - PERFORM workflow_case__add_manual_assignment ( - v_case_id, - ''assign'', - v_user_id + workflow_case.add_manual_assignment ( + case_id => v_case_id, + transition_key => 'assign', + party_id => v_user_id ); - PERFORM workflow_case__add_manual_assignment ( - v_case_id, - ''supervisor_approval'', - v_user_id + workflow_case.add_manual_assignment ( + case_id => v_case_id, + transition_key => 'supervisor_approval', + party_id => v_user_id ); - PERFORM workflow_case__add_manual_assignment ( - v_case_id, - ''other_approval'', - v_user_id + workflow_case.add_manual_assignment ( + case_id => v_case_id, + transition_key => 'other_approval', + party_id => v_user_id ); - PERFORM workflow_case__add_manual_assignment ( - v_case_id, - ''buy'', - v_user_id + workflow_case.add_manual_assignment ( + case_id => v_case_id, + transition_key => 'buy', + party_id => v_user_id ); - raise NOTICE ''. start case''; + dbms_output.put_line('. start case'); - PERFORM workflow_case__start_case( - v_case_id, - null, - null, - null + workflow_case.start_case( + case_id => v_case_id ); select count(*) into v_count from wf_tasks where case_id = v_case_id - and transition_key = ''assign'' - and state = ''enabled''; + and transition_key = 'assign' + and state = 'enabled'; - PERFORM utassert__eq( - ''We should have exactly one \\\'assign\\\' task enabled'', - 1, - v_count + utassert.eq( + msg_in => 'We should have exactly one ''assign'' task enabled', + check_this_in => 1, + against_this_in => v_count ); select count(*) into v_count from wf_tasks where case_id = v_case_id; - PERFORM utassert__eq( - ''The \\\'assign\\\' task should be the only task there is for this case yet.'', - 1, - v_count + utassert.eq( + msg_in => 'The ''assign'' task should be the only task there is for this case yet.', + check_this_in => 1, + against_this_in => v_count ); /* Get that task_id */ select task_id into v_task_id from wf_tasks where case_id = v_case_id - and transition_key = ''assign'' - and state = ''enabled''; + and transition_key = 'assign' + and state = 'enabled'; - raise NOTICE ''. start task \\\'assign\\\'''; + dbms_output.put_line('. start task ''assign'''); - v_journal_id := workflow_case__begin_task_action( - v_task_id, - ''start'', - ''0.0.0.0'', - v_user_id, - ''regression-test: started task \\\'assign\\\''' + v_journal_id := workflow_case.begin_task_action( + task_id => v_task_id, + action => 'start', + action_ip => '0.0.0.0', + user_id => v_user_id, + msg => 'regression-test: started task ''assign''' ); - PERFORM workflow_case__end_task_action( - v_journal_id, - ''start'', - v_task_id + workflow_case.end_task_action( + journal_id => v_journal_id, + action => 'start', + task_id => v_task_id ); select state into v_state from wf_tasks where task_id = v_task_id; - PERFORM utassert__eq( - ''The \\\'assign\\\' task should be in state \\\'started\\\'.'', - ''started'', - v_state + utassert.eq( + msg_in => 'The ''assign'' task should be in state ''started''.', + check_this_in => 'started', + against_this_in => v_state ); - raise NOTICE ''. cancel task \\\'assign\\\'''; + dbms_output.put_line('. cancel task ''assign'''); - v_journal_id := workflow_case__begin_task_action( - v_task_id, - ''cancel'', - ''0.0.0.0'', - v_user_id, - ''regression-test: canceled task \\\'assign\\\''' + v_journal_id := workflow_case.begin_task_action( + task_id => v_task_id, + action => 'cancel', + action_ip => '0.0.0.0', + user_id => v_user_id, + msg => 'regression-test: canceled task ''assign''' ); - PERFORM workflow_case__end_task_action( - v_journal_id, - ''cancel'', - v_task_id + workflow_case.end_task_action( + journal_id => v_journal_id, + action => 'cancel', + task_id => v_task_id ); select state into v_state from wf_tasks where task_id = v_task_id; - PERFORM utassert__eq( - ''The \\\'assign\\\' task should be in state \\\'canceled\\\'.'', - ''canceled'', - v_state + utassert.eq( + msg_in => 'The ''assign'' task should be in state ''canceled''.', + check_this_in => 'canceled', + against_this_in => v_state ); select count(*) into v_count from wf_tasks where case_id = v_case_id - and transition_key = ''assign'' - and state = ''enabled''; + and transition_key = 'assign' + and state = 'enabled'; - PERFORM utassert__eq( - ''We should have exactly one \\\'assign\\\' task enabled'', - 1, - v_count + utassert.eq( + msg_in => 'We should have exactly one ''assign'' task enabled', + check_this_in => 1, + against_this_in => v_count ); select count(*) into v_count from wf_tasks where case_id = v_case_id; - PERFORM utassert__eq( - ''There should be exactly two tasks for this case, one enabled and one canceled.'', - 2, - v_count + utassert.eq( + msg_in => 'There should be exactly two tasks for this case, one enabled and one canceled.', + check_this_in => 2, + against_this_in => v_count ); - raise NOTICE ''. finish task \\\'assign\\\'''; - /* Get that task_id for the assign task */ + + dbms_output.put_line('. finish task ''assign'''); + + /* Get that task_id for the 'assign' task */ select task_id into v_task_id from wf_tasks where case_id = v_case_id - and transition_key = ''assign'' - and state = ''enabled''; + and transition_key = 'assign' + and state = 'enabled'; - v_journal_id := workflow_case__begin_task_action( - v_task_id, - ''finish'', - ''0.0.0.0'', - v_user_id, - ''regression-test: finished task \\\'assign\\\''' + v_journal_id := workflow_case.begin_task_action( + task_id => v_task_id, + action => 'finish', + action_ip => '0.0.0.0', + user_id => v_user_id, + msg => 'regression-test: finished task ''assign''' ); - PERFORM workflow_case__end_task_action( - v_journal_id, - ''finish'', - v_task_id + workflow_case.end_task_action( + journal_id => v_journal_id, + action => 'finish', + task_id => v_task_id ); select state into v_state from wf_tasks where task_id = v_task_id; - PERFORM utassert__eq( - ''The \\\'assign\\\' task should be in state \\\'finished\\\'.'', - ''finished'', - v_state + utassert.eq( + msg_in => 'The ''assign'' task should be in state ''finished''.', + check_this_in => 'finished', + against_this_in => v_state ); select count(*) into v_count from wf_tasks where case_id = v_case_id - and transition_key = ''supervisor_approval'' - and state = ''enabled''; + and transition_key = 'supervisor_approval' + and state = 'enabled'; - PERFORM utassert__eq( - ''We should have exactly one \\\'supervisor_approval\\\' task enabled'', - 1, - v_count + utassert.eq( + msg_in => 'We should have exactly one ''supervisor_approval'' task enabled', + check_this_in => 1, + against_this_in => v_count ); select count(*) into v_count from wf_tasks where case_id = v_case_id - and transition_key = ''other_approval'' - and state = ''enabled''; + and transition_key = 'other_approval' + and state = 'enabled'; - PERFORM utassert__eq( - ''We should have exactly one \\\'other_approval\\\' task enabled'', - 1, - v_count + utassert.eq( + msg_in => 'We should have exactly one ''other_approval'' task enabled', + check_this_in => 1, + against_this_in => v_count ); select count(*) into v_count from wf_tasks where case_id = v_case_id; - PERFORM utassert__eq( - ''There should be exactly five tasks for this case, one canceled, two finished, and two enabled.'', - 5, - v_count + utassert.eq( + msg_in => 'There should be exactly five tasks for this case, one canceled, two finished, and two enabled.', + check_this_in => 5, + against_this_in => v_count ); - raise NOTICE ''. finish task \\\'supervisor_approval\\\' without starting it first (saying okay)''; + dbms_output.put_line('. finish task ''supervisor_approval'' without starting it first (saying okay)'); /* Get the task_id for the supervisor_approval task */ select task_id into v_task_id from wf_tasks where case_id = v_case_id - and transition_key = ''supervisor_approval'' - and state = ''enabled''; + and transition_key = 'supervisor_approval' + and state = 'enabled'; - v_journal_id := workflow_case__begin_task_action( - v_task_id, - ''finish'', - ''0.0.0.0'', - v_user_id, - ''regression-test: finished task \\\'supervisor_approval\\\''' + v_journal_id := workflow_case.begin_task_action( + task_id => v_task_id, + action => 'finish', + action_ip => '0.0.0.0', + user_id => v_user_id, + msg => 'regression-test: finished task ''supervisor_approval''' ); - PERFORM workflow_case__set_attribute_value( - v_journal_id, - ''supervisor_ok'', - ''t'' + workflow_case.set_attribute_value( + journal_id => v_journal_id, + attribute_name => 'supervisor_ok', + value => 't' ); - PERFORM workflow_case__end_task_action( - v_journal_id, - ''finish'', - v_task_id + workflow_case.end_task_action( + journal_id => v_journal_id, + action => 'finish', + task_id => v_task_id ); select state into v_state from wf_tasks where task_id = v_task_id; - PERFORM utassert__eq( - ''The \\\'supervisor_approval\\\' task should be in state \\\'finished\\\.'', - ''finished'', - v_state + utassert.eq( + msg_in => 'The ''supervisor_approval'' task should be in state ''finished''.', + check_this_in => 'finished', + against_this_in => v_state ); - raise NOTICE ''. finish task \\\'other_approval\\\' without starting it first (saying okay)''; + dbms_output.put_line('. finish task ''other_approval'' without starting it first (saying okay)'); /* Get the task_id for the other_approval task */ select task_id into v_task_id from wf_tasks where case_id = v_case_id - and transition_key = ''other_approval'' - and state = ''enabled''; + and transition_key = 'other_approval' + and state = 'enabled'; - v_journal_id := workflow_case__begin_task_action( - v_task_id, - ''finish'', - ''0.0.0.0'', - v_user_id, - ''regression-test: finished task \\\'other_approval\\\''' + v_journal_id := workflow_case.begin_task_action( + task_id => v_task_id, + action => 'finish', + action_ip => '0.0.0.0', + user_id => v_user_id, + msg => 'regression-test: finished task ''other_approval''' ); - PERFORM workflow_case__set_attribute_value( - v_journal_id, - ''other_ok'', - ''t'' + workflow_case.set_attribute_value( + journal_id => v_journal_id, + attribute_name => 'other_ok', + value => 't' ); - PERFORM workflow_case__end_task_action( - v_journal_id, - ''finish'', - v_task_id + workflow_case.end_task_action( + journal_id => v_journal_id, + action => 'finish', + task_id => v_task_id ); select state into v_state from wf_tasks where task_id = v_task_id; - PERFORM utassert__eq( - ''The \\\'other_approval\\\' task should be in state \\\'finished\\\'.'', - ''finished'', - v_state + utassert.eq( + msg_in => 'The ''other_approval'' task should be in state ''finished''.', + check_this_in => 'finished', + against_this_in => v_state ); select count(*) into v_count from wf_tasks where case_id = v_case_id - and state = ''enabled''; + and state = 'enabled'; - PERFORM utassert__eq( - ''We should have exactly one task enabled'', - 1, - v_count + utassert.eq( + msg_in => 'We should have exactly one task enabled', + check_this_in => 1, + against_this_in => v_count ); select count(*) into v_count from wf_tasks where case_id = v_case_id - and transition_key = ''buy'' - and state = ''enabled''; + and transition_key = 'buy' + and state = 'enabled'; - PERFORM utassert__eq( - ''We should have the \\\'buy\\\' task enabled'', - 1, - v_count + utassert.eq( + msg_in => 'We should have the ''buy'' task enabled', + check_this_in => 1, + against_this_in => v_count ); select count(*) into v_count from wf_tasks where case_id = v_case_id; - PERFORM utassert__eq( - ''There should be exactly seven tasks for this case, one canceled, six finished, and one enabled.'', - 7, - v_count + utassert.eq( + msg_in => 'There should be exactly seven tasks for this case, one canceled, six finished, and one enabled.', + check_this_in => 7, + against_this_in => v_count ); select count(*) into v_count from wf_tasks where case_id = v_case_id - and state = ''finished''; + and state = 'finished'; - PERFORM utassert__eq( - ''There should be exactly five finished tasks'', - 5, - v_count + utassert.eq( + msg_in => 'There should be exactly five finished tasks', + check_this_in => 5, + against_this_in => v_count ); select count(*) into v_count from wf_tasks where case_id = v_case_id - and state = ''canceled''; + and state = 'canceled'; - PERFORM utassert__eq( - ''There should be exactly one canceled task'', - 1, - v_count + utassert.eq( + msg_in => 'There should be exactly one canceled task', + check_this_in => 1, + against_this_in => v_count ); - raise NOTICE ''. finish task \\\'buy\\\'''; + dbms_output.put_line('. finish task ''buy'''); - /* Get that task_id for the ''buy'' task */ + /* Get that task_id for the 'buy' task */ select task_id into v_task_id from wf_tasks where case_id = v_case_id - and transition_key = ''buy'' - and state = ''enabled''; + and transition_key = 'buy' + and state = 'enabled'; - v_journal_id := workflow_case__begin_task_action( - v_task_id, - ''finish'', - ''0.0.0.0'', - v_user_id, - ''regression-test: finished task \\\'buy\\\''' + v_journal_id := workflow_case.begin_task_action( + task_id => v_task_id, + action => 'finish', + action_ip => '0.0.0.0', + user_id => v_user_id, + msg => 'regression-test: finished task ''buy''' ); - PERFORM workflow_case__end_task_action( - v_journal_id, - ''finish'', - v_task_id + workflow_case.end_task_action( + journal_id => v_journal_id, + action => 'finish', + task_id => v_task_id ); select state into v_state from wf_tasks where task_id = v_task_id; - PERFORM utassert__eq( - ''The ''''buy'''' task should be in state \\\'finished\\\'.'', - ''finished'', - v_state + utassert.eq( + msg_in => 'The ''buy'' task should be in state ''finished''.', + check_this_in => 'finished', + against_this_in => v_state ); select count(*) into v_count from wf_tasks where case_id = v_case_id; - PERFORM utassert__eq( - ''There should be exactly seven tasks for this case, one canceled, six finished, and one enabled.'', - 7, - v_count + utassert.eq( + msg_in => 'There should be exactly seven tasks for this case, one canceled, six finished, and one enabled.', + check_this_in => 7, + against_this_in => v_count ); select count(*) into v_count from wf_tasks where case_id = v_case_id - and state = ''finished''; + and state = 'finished'; - PERFORM utassert__eq( - ''There should be exactly six finished tasks'', - 6, - v_count + utassert.eq( + msg_in => 'There should be exactly six finished tasks', + check_this_in => 6, + against_this_in => v_count ); select count(*) into v_count from wf_tasks where case_id = v_case_id - and state = ''canceled''; + and state = 'canceled'; - PERFORM utassert__eq( - ''There should be exactly one canceled task'', - 1, - v_count + utassert.eq( + msg_in => 'There should be exactly one canceled task', + check_this_in => 1, + against_this_in => v_count ); select state into v_state from wf_cases where case_id = v_case_id; - PERFORM utassert__eq( - ''The case should be finished'', - ''finished'', - v_state + utassert.eq( + msg_in => 'The case should be finished', + check_this_in => 'finished', + against_this_in => v_state ); - --utresult.show; + utresult.show; + end; - return null; +end ut#workflow_case; +/ +show errors -end;' language 'plpgsql'; - -SELECT setup (); -SELECT run (); - -drop function setup(); -drop function run(); -drop function teardown(); +exec utplsql.test('workflow_case'); \ No newline at end of file