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 -r1.1 -r1.2
--- openacs-4/contrib/obsolete-packages/acs-workflow/sql/oracle/test/workflow-case-package-test.sql	5 Apr 2001 18:23:38 -0000	1.1
+++ openacs-4/contrib/obsolete-packages/acs-workflow/sql/oracle/test/workflow-case-package-test.sql	12 Apr 2001 04:38:52 -0000	1.2
@@ -1,516 +1,543 @@
-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
+-- create or replace package ut#workflow_case
+-- as
+-- 
+--     procedure setup;
+-- 
+--     procedure teardown;
+-- 
+--     procedure run;
+-- 
+-- end ut#workflow_case;
+-- /
+-- show errors
 
-    procedure setup;
+-- create or replace package body ut#workflow_case
 
-    procedure teardown;
+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 run;
+        return null;
 
-end ut#workflow_case;
-/
-show errors
+end;' language 'plpgsql';
 
-create or replace package body ut#workflow_case
-as
-
-    procedure setup
-    is
+create function setup() returns integer as '
+declare
 	wf_count number;
-    begin
-	teardown;
-        dbms_output.put_line('Setting up...');
+begin
+	PERFORM teardown();
+        raise NOTICE ''Setting up...'';
 
-	/* 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';
+	/* 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'';
+
 	if wf_count = 0 then
-	    raise_application_error(-20000, 'The sample-expenses workflow must be loaded (and unchanged from the original)');
+	    raise EXCEPTION ''-20000: The sample-expenses workflow must be loaded (and unchanged from the original)'';
 	end if;
-	
-	
 
-        utplsql.setpkg('workflow_case');
-	utplsql.addtest('run');
-    end;
+        return null;
 
-    procedure teardown
-    is
-    begin
-        dbms_output.put_line('Tearing down...');
+end;' language 'plpgsql';
+
+create functin teardown() returns integer as '
+begin
+        raise NOTICE ''Tearing down...'';
 	
-    end;
+end;' language 'plpgsql';
 
-    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';
+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'';
 	
-        dbms_output.put_line('Running test...');
+        raise NOTICE ''Running test...'';
 
 	/* Pick out a random object ... we just hope there is one somewhere */
-	select object_id into v_object_id from acs_objects where rownum = 1;
+	select object_id into v_object_id 
+        from acs_objects
+        limit 1;
 	
-        dbms_output.put_line('. new case');
+        raise NOTICE ''. new case'';
 
-	v_case_id := workflow_case.new(
-            workflow_key => v_workflow_key,
-            context_key => 'default',
-            object_id => v_object_id
+	v_case_id := workflow_case__new(
+            null,
+            v_workflow_key,
+            ''default'',
+            v_object_id,
+            now(),
+            null,
+            null
         );
 	
-	dbms_output.put_line('. manual assignments');
+	raise NOTICE ''. manual assignments'';
 
 	/* we need a random user_id */
 	select user_id into v_user_id
 	from   users
-	where  rownum = 1;
+	limit 1;
 
-	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,
+	    ''assign'',
+	    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,
+	    ''supervisor_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,
+	    ''other_approval'',
+	    v_user_id
 	);
 
-	workflow_case.add_manual_assignment (
-	    case_id => v_case_id,
-	    transition_key => 'buy',
-	    party_id => v_user_id
+	PERFORM workflow_case__add_manual_assignment (
+	    v_case_id,
+	    ''buy'',
+	    v_user_id
 	);
 
 
 
-	dbms_output.put_line('. start case');
+	raise NOTICE ''. start case'';
 
-	workflow_case.start_case(
-	    case_id => v_case_id
+	PERFORM workflow_case__start_case(
+	    v_case_id,
+            null,
+            null,
+            null
         );
 	
 	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'';
 
-	utassert.eq(
-	    msg_in => 'We should have exactly one ''assign'' task enabled',
-	    check_this_in => 1, 
-            against_this_in => v_count
+	PERFORM utassert__eq(
+	    ''We should have exactly one \\\'assign\\\' task enabled'',
+	    1, 
+            v_count
         );
 
 	select count(*) into v_count 
 	from   wf_tasks 
 	where  case_id = v_case_id;
 
-	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
+	PERFORM utassert__eq(
+	    ''The \\\'assign\\\' task should be the only task there is for this case yet.'',
+	    1,
+	    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'';
 
 
 
 
-	dbms_output.put_line('. start task ''assign''');
+	raise NOTICE ''. start 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'''
+	v_journal_id := workflow_case__begin_task_action(
+	    v_task_id,
+	    ''start'',
+	    ''0.0.0.0'',
+	    v_user_id,
+	    ''regression-test: started task \\\'assign\\\'''
 	);
 
-	workflow_case.end_task_action(
-	    journal_id => v_journal_id,
-	    action => 'start',
-	    task_id => v_task_id
+	PERFORM workflow_case__end_task_action(
+	    v_journal_id,
+	    ''start'',
+	    v_task_id
         );
 
 	select state into v_state
 	from   wf_tasks
 	where  task_id = v_task_id;
 	
-	utassert.eq(
-	    msg_in => 'The ''assign'' task should be in state ''started''.',
-	    check_this_in => 'started',
-	    against_this_in => v_state
+	PERFORM utassert__eq(
+	    ''The \\\'assign\\\' task should be in state \\\'started\\\'.'',
+	    ''started'',
+	    v_state
         );
 
 
 
 
-	dbms_output.put_line('. cancel task ''assign''');
+	raise NOTICE ''. cancel 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'''
+	v_journal_id := workflow_case__begin_task_action(
+	    v_task_id,
+	    ''cancel'',
+	    ''0.0.0.0'',
+	    v_user_id,
+	    ''regression-test: canceled task \\\'assign\\\'''
 	);
 
-	workflow_case.end_task_action(
-	    journal_id => v_journal_id,
-	    action => 'cancel',
-	    task_id => v_task_id
+	PERFORM workflow_case__end_task_action(
+	    v_journal_id,
+	    ''cancel'',
+	    v_task_id
         );
 
 	select state into v_state
 	from   wf_tasks
 	where  task_id = v_task_id;
 	
-	utassert.eq(
-	    msg_in => 'The ''assign'' task should be in state ''canceled''.',
-	    check_this_in => 'canceled',
-	    against_this_in => v_state
+	PERFORM utassert__eq(
+	    ''The \\\'assign\\\' task should be in state \\\'canceled\\\'.'',
+	    ''canceled'',
+	    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'';
 
-	utassert.eq(
-	    msg_in => 'We should have exactly one ''assign'' task enabled',
-	    check_this_in => 1,
-            against_this_in => v_count
+	PERFORM utassert__eq(
+	    ''We should have exactly one \\\'assign\\\' task enabled'',
+	    1,
+            v_count
         );
 
 	select count(*) into v_count 
 	from   wf_tasks 
 	where  case_id = v_case_id;
 
-	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
+	PERFORM utassert__eq(
+	    ''There should be exactly two tasks for this case, one enabled and one canceled.'',
+	    2,
+	    v_count
         );
 
 
+	raise NOTICE ''. finish task \\\'assign\\\''';
 
-
-	dbms_output.put_line('. finish task ''assign''');
-
-	/* Get that task_id for the 'assign' task */
+	/* 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(
-	    task_id => v_task_id,
-	    action => 'finish',
-	    action_ip => '0.0.0.0',
-	    user_id => v_user_id,
-	    msg => 'regression-test: finished task ''assign'''
+	v_journal_id := workflow_case__begin_task_action(
+	    v_task_id,
+	    ''finish'',
+	    ''0.0.0.0'',
+	    v_user_id,
+	    ''regression-test: finished task \\\'assign\\\'''
 	);
 
-	workflow_case.end_task_action(
-	    journal_id => v_journal_id,
-	    action => 'finish',
-	    task_id => v_task_id
+	PERFORM workflow_case__end_task_action(
+	    v_journal_id,
+	    ''finish'',
+	    v_task_id
         );
 	
 	select state into v_state
 	from   wf_tasks
 	where  task_id = v_task_id;
 
-	utassert.eq(
-	    msg_in => 'The ''assign'' task should be in state ''finished''.',
-	    check_this_in => 'finished',
-	    against_this_in => v_state
+	PERFORM utassert__eq(
+	    ''The \\\'assign\\\' task should be in state \\\'finished\\\'.'',
+	    ''finished'',
+	    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'';
 
-	utassert.eq(
-	    msg_in => 'We should have exactly one ''supervisor_approval'' task enabled',
-	    check_this_in => 1,
-            against_this_in => v_count
+	PERFORM utassert__eq(
+	    ''We should have exactly one \\\'supervisor_approval\\\' task enabled'',
+	    1,
+            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'';
 
-	utassert.eq(
-	    msg_in => 'We should have exactly one ''other_approval'' task enabled',
-	    check_this_in => 1,
-            against_this_in => v_count
+	PERFORM utassert__eq(
+	    ''We should have exactly one \\\'other_approval\\\' task enabled'',
+	    1,
+            v_count
         );
 
 	select count(*) into v_count 
 	from   wf_tasks 
 	where  case_id = v_case_id;
 
-	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
+	PERFORM utassert__eq(
+	    ''There should be exactly five tasks for this case, one canceled, two finished, and two enabled.'',
+	    5,
+	    v_count
         );
 
 	
-	dbms_output.put_line('. finish task ''supervisor_approval'' without starting it first (saying okay)');
+	raise NOTICE ''. 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(
-	    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'''
+	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\\\'''
 	);
 
-	workflow_case.set_attribute_value(
-	    journal_id => v_journal_id,
-	    attribute_name => 'supervisor_ok',
-	    value => 't'
+	PERFORM workflow_case__set_attribute_value(
+	    v_journal_id,
+	    ''supervisor_ok'',
+	    ''t''
         );
 
-	workflow_case.end_task_action(
-	    journal_id => v_journal_id,
-	    action => 'finish',
-	    task_id => v_task_id
+	PERFORM workflow_case__end_task_action(
+	    v_journal_id,
+	    ''finish'',
+	    v_task_id
         );
 	
 	select state into v_state
 	from   wf_tasks
 	where  task_id = v_task_id;
 
-	utassert.eq(
-	    msg_in => 'The ''supervisor_approval'' task should be in state ''finished''.',
-	    check_this_in => 'finished',
-	    against_this_in => v_state
+	PERFORM utassert__eq(
+	    ''The \\\'supervisor_approval\\\' task should be in state \\\'finished\\\.'',
+	    ''finished'',
+	    v_state
         );
 	
 
 
-	dbms_output.put_line('. finish task ''other_approval'' without starting it first (saying okay)');
+	raise NOTICE ''. 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(
-	    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'''
+	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\\\'''
 	);
 
-	workflow_case.set_attribute_value(
-	    journal_id => v_journal_id,
-	    attribute_name => 'other_ok',
-	    value => 't'
+	PERFORM workflow_case__set_attribute_value(
+	    v_journal_id,
+	    ''other_ok'',
+	    ''t''
         );
 
-	workflow_case.end_task_action(
-	    journal_id => v_journal_id,
-	    action => 'finish',
-	    task_id => v_task_id
+	PERFORM workflow_case__end_task_action(
+	    v_journal_id,
+	    ''finish'',
+	    v_task_id
         );
 	
 	select state into v_state
 	from   wf_tasks
 	where  task_id = v_task_id;
 
-	utassert.eq(
-	    msg_in => 'The ''other_approval'' task should be in state ''finished''.',
-	    check_this_in => 'finished',
-	    against_this_in => v_state
+	PERFORM utassert__eq(
+	    ''The \\\'other_approval\\\' task should be in state \\\'finished\\\'.'',
+	    ''finished'',
+	    v_state
         );
 	
 	select count(*) into v_count 
 	from   wf_tasks 
 	where  case_id = v_case_id
-	and    state = 'enabled';
+	and    state = ''enabled'';
 
-	utassert.eq(
-	    msg_in => 'We should have exactly one task enabled',
-	    check_this_in => 1,
-            against_this_in => v_count
+	PERFORM utassert__eq(
+	    ''We should have exactly one task enabled'',
+	    1,
+            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'';
 
-	utassert.eq(
-	    msg_in => 'We should have the ''buy'' task enabled',
-	    check_this_in => 1,
-            against_this_in => v_count
+	PERFORM utassert__eq(
+	    ''We should have the \\\'buy\\\' task enabled'',
+	    1,
+            v_count
         );
 
 	select count(*) into v_count 
 	from   wf_tasks 
 	where  case_id = v_case_id;
 
-	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
+	PERFORM utassert__eq(
+	    ''There should be exactly seven tasks for this case, one canceled, six finished, and one enabled.'',
+	    7,
+	    v_count
         );
 
 	select count(*) into v_count 
 	from   wf_tasks 
 	where  case_id = v_case_id
-	and    state = 'finished';
+	and    state = ''finished'';
 
-	utassert.eq(
-	    msg_in => 'There should be exactly five finished tasks',
-	    check_this_in => 5,
-	    against_this_in => v_count
+	PERFORM utassert__eq(
+	    ''There should be exactly five finished tasks'',
+	    5,
+	    v_count
         );
 
 	select count(*) into v_count 
 	from   wf_tasks 
 	where  case_id = v_case_id
-	and    state = 'canceled';
+	and    state = ''canceled'';
 
-	utassert.eq(
-	    msg_in => 'There should be exactly one canceled task',
-	    check_this_in => 1,
-	    against_this_in => v_count
+	PERFORM utassert__eq(
+	    ''There should be exactly one canceled task'',
+	    1,
+	    v_count
         );
 	
 
-	dbms_output.put_line('. finish task ''buy''');
+	raise NOTICE ''. 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(
-	    task_id => v_task_id,
-	    action => 'finish',
-	    action_ip => '0.0.0.0',
-	    user_id => v_user_id,
-	    msg => 'regression-test: finished task ''buy'''
+	v_journal_id := workflow_case__begin_task_action(
+	    v_task_id,
+	    ''finish'',
+	    ''0.0.0.0'',
+	    v_user_id,
+	    ''regression-test: finished task \\\'buy\\\'''
 	);
 
-	workflow_case.end_task_action(
-	    journal_id => v_journal_id,
-	    action => 'finish',
-	    task_id => v_task_id
+	PERFORM workflow_case__end_task_action(
+	    v_journal_id,
+	    ''finish'',
+	    v_task_id
         );
 	
 	select state into v_state
 	from   wf_tasks
 	where  task_id = v_task_id;
 
-	utassert.eq(
-	    msg_in => 'The ''buy'' task should be in state ''finished''.',
-	    check_this_in => 'finished',
-	    against_this_in => v_state
+	PERFORM utassert__eq(
+	    ''The ''''buy'''' task should be in state \\\'finished\\\'.'',
+	    ''finished'',
+	    v_state
         );
 
 	select count(*) into v_count 
 	from   wf_tasks 
 	where  case_id = v_case_id;
 
-	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
+	PERFORM utassert__eq(
+	    ''There should be exactly seven tasks for this case, one canceled, six finished, and one enabled.'',
+	    7,
+	    v_count
         );
 
 	select count(*) into v_count 
 	from   wf_tasks 
 	where  case_id = v_case_id
-	and    state = 'finished';
+	and    state = ''finished'';
 
-	utassert.eq(
-	    msg_in => 'There should be exactly six finished tasks',
-	    check_this_in => 6,
-	    against_this_in => v_count
+	PERFORM utassert__eq(
+	    ''There should be exactly six finished tasks'',
+	    6,
+	    v_count
         );
 
 	select count(*) into v_count 
 	from   wf_tasks 
 	where  case_id = v_case_id
-	and    state = 'canceled';
+	and    state = ''canceled'';
 
-	utassert.eq(
-	    msg_in => 'There should be exactly one canceled task',
-	    check_this_in => 1,
-	    against_this_in => v_count
+	PERFORM utassert__eq(
+	    ''There should be exactly one canceled task'',
+	    1,
+	    v_count
         );
 	
 	select state into v_state
 	from   wf_cases
 	where  case_id = v_case_id;
 
-	utassert.eq(
-	    msg_in => 'The case should be finished',
-	    check_this_in => 'finished',
-	    against_this_in => v_state
+	PERFORM utassert__eq(
+	    ''The case should be finished'',
+	    ''finished'',
+	    v_state
 	);
 
-	utresult.show;
-    end;
+	--utresult.show;
 
-end ut#workflow_case;
-/
-show errors
+        return null;
 
-exec utplsql.test('workflow_case');
\ No newline at end of file
+end;' language 'plpgsql';
+
+SELECT setup ();
+SELECT run ();
+
+drop function setup();
+drop function run();
+drop function teardown();
