|
| 1 | +create or replace package body test_ut_run is |
| 2 | + |
| 3 | + procedure create_test_suite is |
| 4 | + pragma autonomous_transaction; |
| 5 | + begin |
| 6 | + execute immediate q'[ |
| 7 | + create or replace package stateful_package as |
| 8 | + g_state varchar2(1) := 'A'; |
| 9 | + end; |
| 10 | + ]'; |
| 11 | + execute immediate q'[ |
| 12 | + create or replace package test_stateful as |
| 13 | + --%suite |
| 14 | + --%suitepath(test_state) |
| 15 | + |
| 16 | + --%test |
| 17 | + procedure stateful_success; |
| 18 | + |
| 19 | + --%test |
| 20 | + --%beforetest(recompile_in_background) |
| 21 | + procedure failing_stateful_test; |
| 22 | + |
| 23 | + procedure recompile_in_background; |
| 24 | + |
| 25 | + --%test |
| 26 | + procedure dummy_success; |
| 27 | + |
| 28 | + end; |
| 29 | + ]'; |
| 30 | + execute immediate q'{ |
| 31 | + create or replace package body test_stateful as |
| 32 | + |
| 33 | + procedure stateful_success is |
| 34 | + begin |
| 35 | + ut3.ut.expect(stateful_package.g_state).to_equal('A'); |
| 36 | + end; |
| 37 | + |
| 38 | + procedure failing_stateful_test is |
| 39 | + begin |
| 40 | + ut3.ut.expect(stateful_package.g_state).to_equal('abc'); |
| 41 | + end; |
| 42 | + |
| 43 | + procedure dummy_success is |
| 44 | + begin |
| 45 | + ut3.ut.expect(1).to_equal(1); |
| 46 | + end; |
| 47 | + |
| 48 | + procedure recompile_in_background is |
| 49 | + l_job_name varchar2(30) := 'recreate_stateful_package'; |
| 50 | + l_cnt integer := 1; |
| 51 | + pragma autonomous_transaction; |
| 52 | + begin |
| 53 | + dbms_scheduler.create_job( |
| 54 | + job_name => l_job_name, |
| 55 | + job_type => 'PLSQL_BLOCK', |
| 56 | + job_action => q'/ |
| 57 | + begin |
| 58 | + execute immediate q'[ |
| 59 | + create or replace package stateful_package as |
| 60 | + g_state varchar2(3) := 'abc'; |
| 61 | + end;]'; |
| 62 | + end;/', |
| 63 | + start_date => sysdate, |
| 64 | + enabled => TRUE, |
| 65 | + auto_drop => TRUE, |
| 66 | + comments => 'one-time job' |
| 67 | + ); |
| 68 | + dbms_lock.sleep(0.2); |
| 69 | + while l_cnt > 0 loop |
| 70 | + select count(1) into l_cnt |
| 71 | + from dba_scheduler_running_jobs srj |
| 72 | + where srj.job_name = l_job_name; |
| 73 | + end loop; |
| 74 | + end; |
| 75 | + end; |
| 76 | + }'; |
| 77 | + |
| 78 | + end; |
| 79 | + |
| 80 | + procedure raise_in_invalid_state is |
| 81 | + l_results ut3.ut_varchar2_list; |
| 82 | + l_expected varchar2(32767); |
| 83 | + begin |
| 84 | + --Arrange |
| 85 | + l_expected := 'test_state |
| 86 | + test_stateful |
| 87 | + stateful_success [% sec] |
| 88 | + failing_stateful_test [% sec] (FAILED - 1) |
| 89 | + dummy_success [% sec]% |
| 90 | +Failures:% |
| 91 | + 1) failing_stateful_test |
| 92 | + ORA-04061: existing state of package "UT3_TESTER.STATEFUL_PACKAGE" has been invalidated |
| 93 | + ORA-04065: not executed, altered or dropped package "UT3_TESTER.STATEFUL_PACKAGE" |
| 94 | + ORA-06508: PL/SQL: could not find program unit being called: "UT3_TESTER.STATEFUL_PACKAGE" |
| 95 | + ORA-06512: at "UT3_TESTER.TEST_STATEFUL", line 10% |
| 96 | + ORA-06512: at line 6% |
| 97 | +3 tests, 0 failed, 1 errored, 0 disabled, 0 warning(s)%'; |
| 98 | + |
| 99 | + --Act |
| 100 | + select * bulk collect into l_results from table(ut3.ut.run('test_stateful')); |
| 101 | + --Assert |
| 102 | + ut.fail('Expected exception but nothing was raised'); |
| 103 | + exception |
| 104 | + when others then |
| 105 | + ut.expect( ut3.ut_utils.table_to_clob(l_results) ).to_be_like( l_expected ); |
| 106 | + ut.expect(sqlcode).to_equal(-4068); |
| 107 | + end; |
| 108 | + |
| 109 | + procedure drop_test_suite is |
| 110 | + pragma autonomous_transaction; |
| 111 | + begin |
| 112 | + execute immediate 'drop package stateful_package'; |
| 113 | + execute immediate 'drop package test_stateful'; |
| 114 | + end; |
| 115 | + |
| 116 | +end; |
| 117 | +/ |
0 commit comments