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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
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
7 changes: 6 additions & 1 deletion source/core/ut_expectation_processor.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ create or replace package body ut_expectation_processor as
begin
add_expectation_result(ut_expectation_result(ut_utils.gc_failure, null, a_message));
end;


procedure report_failure_no_caller(a_message in varchar2) is
Comment thread
lwasylow marked this conversation as resolved.
Outdated
begin
add_expectation_result(ut_expectation_result(ut_utils.gc_failure, null, a_message,false));
end;

function get_session_parameters return tt_nls_params is
l_session_params tt_nls_params;
begin
Expand Down
2 changes: 2 additions & 0 deletions source/core/ut_expectation_processor.pks
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ create or replace package ut_expectation_processor authid current_user as
procedure add_expectation_result(a_expectation_result ut_expectation_result);

procedure report_failure(a_message in varchar2);

procedure report_failure_no_caller(a_message in varchar2);

procedure set_xml_nls_params;

Expand Down
15 changes: 15 additions & 0 deletions source/core/ut_utils.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -737,5 +737,20 @@ create or replace package body ut_utils is
return l_results;
end;

function remove_error_from_stack(a_error_stack varchar2, a_ora_code number) return varchar2 is
l_caller_stack_line varchar2(4000);
l_ora_search_pattern varchar2(500) := '^ORA'||a_ora_code||': (.*)$';
begin
l_caller_stack_line := regexp_replace(srcstr => a_error_stack
,pattern => l_ora_search_pattern
,replacestr => null
,position => 1
,occurrence => 1
,modifier => 'm');
return l_caller_stack_line;
end;



end ut_utils;
/
15 changes: 14 additions & 1 deletion source/core/ut_utils.pks
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ create or replace package ut_utils authid definer is
gc_value_too_large constant pls_integer := -20217;
pragma exception_init (ex_value_too_large, -20217);

ex_xml_processing exception;
gc_xml_processing constant pls_integer := -19202;
pragma exception_init (ex_xml_processing, -19202);

ex_failed_open_cur exception;
gc_failed_open_cur constant pls_integer := -20218;
pragma exception_init (ex_failed_open_cur, -20218);

gc_max_storage_varchar2_len constant integer := 4000;
gc_max_output_string_length constant integer := 4000;
gc_more_data_string constant varchar2(5) := '[...]';
Expand Down Expand Up @@ -368,6 +376,11 @@ create or replace package ut_utils authid definer is
* Returns list of sub-type reporters for given list of super-type reporters
*/
function get_child_reporters(a_for_reporters ut_reporters_info := null) return ut_reporters_info;


/**
* Remove given ORA error from stack
*/
function remove_error_from_stack(a_error_stack varchar2, a_ora_code number) 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;
/
10 changes: 9 additions & 1 deletion source/expectations/data_values/ut_data_value_refcursor.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ create or replace type body ut_data_value_refcursor as
exception
when cursor_not_open then
raise_application_error(-20155, 'Cursor is not open');
when ut_utils.ex_xml_processing then
if l_cursor%isopen then
close l_cursor;
end if;
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 All @@ -111,7 +117,9 @@ create or replace type body ut_data_value_refcursor as
dbms_lob.createtemporary(l_result, true);
ut_utils.append_to_clob(l_result, 'Data-types:'||chr(10));

ut_utils.append_to_clob( l_result, self.cursor_details.get_xml_children().getclobval() );
if self.cursor_details.cursor_columns_info.count > 0 then
ut_utils.append_to_clob( l_result, self.cursor_details.get_xml_children().getclobval() );
end if;
ut_utils.append_to_clob(l_result,chr(10)||(self as ut_compound_data_value).to_string());
l_result_string := ut_utils.to_string(l_result,null);
dbms_lob.freetemporary(l_result);
Expand Down
53 changes: 45 additions & 8 deletions test/ut3_user/expectations/test_expectations_cursor.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -972,18 +972,16 @@ Rows: [ 4 differences ]
procedure reports_on_exception_in_cursor
as
l_actual sys_refcursor;
l_error_code integer := -19202; --Error occurred in XML processing
begin
--Act
open l_actual for select 1/0 as error_column from dual connect by level < 10;
begin
ut3.ut.expect(l_actual).to_be_empty();
--Assert
ut.fail('Expected '||l_error_code||' but nothing was raised');
exception
when others then
ut.expect(sqlcode).to_equal(l_error_code);
end;

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 @@ -2523,5 +2521,44 @@ Diff:%
ut.expect(l_actual_message).to_be_like(l_expected_message);
end;

procedure xml_error_actual is
c_price CONSTANT NUMBER(20,4):= 1357;
c_user CONSTANT varchar2(30):= 'TEST_USER';
v_actual sys_refcursor;
v_expected sys_refcursor;
begin
open v_actual for
select cast(null as number(10)) as usd_price_amt, c_user as update_id
from dual where dummy = 1;
open v_expected for
select c_price as usd_price_amt, c_user as update_id from dual;

ut3.ut.expect(v_actual).to_equal(v_expected);

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;
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);

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;
/
11 changes: 9 additions & 2 deletions test/ut3_user/expectations/test_expectations_cursor.pks
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,18 @@ create or replace package test_expectations_cursor is

--%test(Cursor to contain duplicates fail)
procedure to_contain_duplicates_fail;

--%test(Display a message with a uer defined type with only type name not structure on equal)
procedure udt_messg_format_eq;

--%test(Display a message with a uer defined type with only type name not structure on empty)
procedure udt_messg_format_empt;
procedure udt_messg_format_empt;

--%test(Fail to process a cursor for actual)
procedure xml_error_actual;

--%test(Fail to process a cursor for expected)
procedure xml_error_expected;

end;
/