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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update tests for handling usr friendly error
  • Loading branch information
lwasylow committed Apr 4, 2019
commit b56b8efd81a2ee731822cec13f0ad882f5f8b550
8 changes: 1 addition & 7 deletions source/core/ut_utils.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -750,13 +750,7 @@ create or replace package body ut_utils is
return l_caller_stack_line;
end;

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


end ut_utils;
/
4 changes: 1 addition & 3 deletions source/core/ut_utils.pks
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,6 @@ create or replace package ut_utils authid definer is
* Remove given ORA error from stack
*/
function remove_error_from_stack(a_error_stack varchar2, a_ora_code number) return varchar2;

function create_err_cursor_msg(a_error_stack varchar2) return varchar2;


end ut_utils;
/
8 changes: 8 additions & 0 deletions source/expectations/data_values/ut_compound_data_helper.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,14 @@ create or replace package body ut_compound_data_helper is
open l_diff_cursor for a_diff_cursor_text using a_self_id, a_other_id;
return l_diff_cursor;
end;

function create_err_cursor_msg(a_error_stack varchar2) return varchar2 is
begin
return 'SQL exception thrown when fetching data from cursor: '||
ut_utils.remove_error_from_stack(sqlerrm,-19202)||chr(10)||
Comment thread
lwasylow marked this conversation as resolved.
Outdated
ut_expectation_processor.who_called_expectation(a_error_stack)||
'Check the query and data for errors.';
end;

begin
g_anytype_name_map(dbms_types.typecode_date) := 'DATE';
Expand Down
2 changes: 2 additions & 0 deletions source/expectations/data_values/ut_compound_data_helper.pks
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,7 @@ create or replace package ut_compound_data_helper authid definer is

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

function create_err_cursor_msg(a_error_stack varchar2) return varchar2;

end;
/
3 changes: 2 additions & 1 deletion source/expectations/data_values/ut_data_value_refcursor.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ create or replace type body ut_data_value_refcursor as
if l_cursor%isopen then
close l_cursor;
end if;
raise_application_error(ut_utils.gc_failed_open_cur,ut_utils.create_err_cursor_msg(dbms_utility.format_call_stack()));
raise_application_error(ut_utils.gc_failed_open_cur,
ut_compound_data_helper.create_err_cursor_msg(dbms_utility.format_call_stack()));
when others then
if l_cursor%isopen then
close l_cursor;
Expand Down
43 changes: 15 additions & 28 deletions test/ut3_user/expectations/test_expectations_cursor.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -972,21 +972,16 @@ Rows: [ 4 differences ]
procedure reports_on_exception_in_cursor
as
l_actual sys_refcursor;
l_expected_message varchar2(32767);
l_actual_message varchar2(32767);
begin
--Act
open l_actual for select 1/0 as error_column from dual connect by level < 10;
ut3.ut.expect(l_actual).to_be_empty();
--Assert
--Assert
l_expected_message := q'[%SQL exception thrown when fetching data from cursor:%
%ORA-01476: divisor is equal to zero%
%Check the query and data for errors.]';

l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
--Assert
ut.expect(l_actual_message).to_be_like(l_expected_message);
ut.fail('Expected exception on cursor fetch');
exception
when others then
ut.expect(sqlerrm).to_be_like('%ORA-20218: SQL exception thrown when fetching data from cursor:%
%ORA-01476: divisor is equal to zero%Check the query and data for errors%');
Comment thread
lwasylow marked this conversation as resolved.
end;

procedure exception_when_closed_cursor
Expand Down Expand Up @@ -2531,8 +2526,6 @@ Diff:%
c_user CONSTANT varchar2(30):= 'TEST_USER';
v_actual sys_refcursor;
v_expected sys_refcursor;
l_expected_message varchar2(32767);
l_actual_message varchar2(32767);
begin
open v_actual for
select cast(null as number(10)) as usd_price_amt, c_user as update_id
Expand All @@ -2541,36 +2534,30 @@ Diff:%
select c_price as usd_price_amt, c_user as update_id from dual;

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

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

procedure xml_error_expected is
v_actual sys_refcursor;
v_expected sys_refcursor;
l_expected_message varchar2(32767);
l_actual_message varchar2(32767);
begin
open v_expected for
select 1/0 as test from dual;
open v_actual for
select 1 as test from dual;

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

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

end;
Expand Down