Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b56b8ef

Browse files
committed
Update tests for handling usr friendly error
1 parent 4ec49aa commit b56b8ef

6 files changed

Lines changed: 29 additions & 39 deletions

File tree

source/core/ut_utils.pkb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -750,13 +750,7 @@ create or replace package body ut_utils is
750750
return l_caller_stack_line;
751751
end;
752752

753-
function create_err_cursor_msg(a_error_stack varchar2) return varchar2 is
754-
begin
755-
return 'SQL exception thrown when fetching data from cursor: '||
756-
remove_error_from_stack(sqlerrm,-19202)||chr(10)||
757-
ut_expectation_processor.who_called_expectation(a_error_stack)||chr(10)||
758-
'Check the query and data for errors.';
759-
end;
753+
760754

761755
end ut_utils;
762756
/

source/core/ut_utils.pks

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,6 @@ create or replace package ut_utils authid definer is
381381
* Remove given ORA error from stack
382382
*/
383383
function remove_error_from_stack(a_error_stack varchar2, a_ora_code number) return varchar2;
384-
385-
function create_err_cursor_msg(a_error_stack varchar2) return varchar2;
386-
384+
387385
end ut_utils;
388386
/

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,14 @@ create or replace package body ut_compound_data_helper is
595595
open l_diff_cursor for a_diff_cursor_text using a_self_id, a_other_id;
596596
return l_diff_cursor;
597597
end;
598+
599+
function create_err_cursor_msg(a_error_stack varchar2) return varchar2 is
600+
begin
601+
return 'SQL exception thrown when fetching data from cursor: '||
602+
ut_utils.remove_error_from_stack(sqlerrm,-19202)||chr(10)||
603+
ut_expectation_processor.who_called_expectation(a_error_stack)||
604+
'Check the query and data for errors.';
605+
end;
598606

599607
begin
600608
g_anytype_name_map(dbms_types.typecode_date) := 'DATE';

source/expectations/data_values/ut_compound_data_helper.pks

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,7 @@ create or replace package ut_compound_data_helper authid definer is
9292

9393
function get_compare_cursor(a_diff_cursor_text in clob,a_self_id raw, a_other_id raw) return sys_refcursor;
9494

95+
function create_err_cursor_msg(a_error_stack varchar2) return varchar2;
96+
9597
end;
9698
/

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ create or replace type body ut_data_value_refcursor as
100100
if l_cursor%isopen then
101101
close l_cursor;
102102
end if;
103-
raise_application_error(ut_utils.gc_failed_open_cur,ut_utils.create_err_cursor_msg(dbms_utility.format_call_stack()));
103+
raise_application_error(ut_utils.gc_failed_open_cur,
104+
ut_compound_data_helper.create_err_cursor_msg(dbms_utility.format_call_stack()));
104105
when others then
105106
if l_cursor%isopen then
106107
close l_cursor;

test/ut3_user/expectations/test_expectations_cursor.pkb

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -972,21 +972,16 @@ Rows: [ 4 differences ]
972972
procedure reports_on_exception_in_cursor
973973
as
974974
l_actual sys_refcursor;
975-
l_expected_message varchar2(32767);
976-
l_actual_message varchar2(32767);
977975
begin
978976
--Act
979977
open l_actual for select 1/0 as error_column from dual connect by level < 10;
980978
ut3.ut.expect(l_actual).to_be_empty();
981-
--Assert
982-
--Assert
983-
l_expected_message := q'[%SQL exception thrown when fetching data from cursor:%
984-
%ORA-01476: divisor is equal to zero%
985-
%Check the query and data for errors.]';
986979

987-
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
988-
--Assert
989-
ut.expect(l_actual_message).to_be_like(l_expected_message);
980+
ut.fail('Expected exception on cursor fetch');
981+
exception
982+
when others then
983+
ut.expect(sqlerrm).to_be_like('%ORA-20218: SQL exception thrown when fetching data from cursor:%
984+
%ORA-01476: divisor is equal to zero%Check the query and data for errors%');
990985
end;
991986

992987
procedure exception_when_closed_cursor
@@ -2531,8 +2526,6 @@ Diff:%
25312526
c_user CONSTANT varchar2(30):= 'TEST_USER';
25322527
v_actual sys_refcursor;
25332528
v_expected sys_refcursor;
2534-
l_expected_message varchar2(32767);
2535-
l_actual_message varchar2(32767);
25362529
begin
25372530
open v_actual for
25382531
select cast(null as number(10)) as usd_price_amt, c_user as update_id
@@ -2541,36 +2534,30 @@ Diff:%
25412534
select c_price as usd_price_amt, c_user as update_id from dual;
25422535

25432536
ut3.ut.expect(v_actual).to_equal(v_expected);
2544-
--Assert
2545-
l_expected_message := q'[%ORA-20218: SQL exception thrown when fetching data from cursor:
2546-
%ORA-01722: invalid number%
2547-
at%ut.expect(v_actual).to_equal(v_expected)%]';
25482537

2549-
l_actual_message := ut3_tester_helper.main_helper.get_failed_expectations(1);
2550-
--Assert
2551-
ut.expect(l_actual_message).to_be_like(l_expected_message);
2538+
ut.fail('Expected exception on cursor fetch');
2539+
exception
2540+
when others then
2541+
ut.expect(sqlerrm).to_be_like('%ORA-20218: SQL exception thrown when fetching data from cursor:%
2542+
%ORA-01722: invalid number%%Check the query and data for errors%');
25522543
end;
25532544

25542545
procedure xml_error_expected is
25552546
v_actual sys_refcursor;
25562547
v_expected sys_refcursor;
2557-
l_expected_message varchar2(32767);
2558-
l_actual_message varchar2(32767);
25592548
begin
25602549
open v_expected for
25612550
select 1/0 as test from dual;
25622551
open v_actual for
25632552
select 1 as test from dual;
25642553

25652554
ut3.ut.expect(v_actual).to_equal(v_expected);
2566-
--Assert
2567-
l_expected_message := q'[%ORA-20218: SQL exception thrown when fetching data from cursor:
2568-
%ORA-01476: divisor is equal to zero%
2569-
%at % ut.expect(v_actual).to_equal(v_expected)%]';
25702555

2571-
l_actual_message := ut3_tester_helper.main_helper.get_failed_expectations(1);
2572-
--Assert
2573-
ut.expect(l_actual_message).to_be_like(l_expected_message);
2556+
ut.fail('Expected exception on cursor fetch');
2557+
exception
2558+
when others then
2559+
ut.expect(sqlerrm).to_be_like('%ORA-20218: SQL exception thrown when fetching data from cursor:%
2560+
%ORA-01476: divisor is equal to zero%Check the query and data for errors%');
25742561
end;
25752562

25762563
end;

0 commit comments

Comments
 (0)