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

Skip to content

Commit ad3ce10

Browse files
committed
Adding handling of xml error
1 parent 95d9507 commit ad3ce10

2 files changed

Lines changed: 24 additions & 37 deletions

File tree

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +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-
ut_expectation_processor.report_failure_no_caller('Failed to process ref_cursor with error'||chr(10)||
104-
ut_utils.remove_error_from_stack(sqlerrm,-19202));
103+
ut_expectation_processor.report_failure_no_caller('SQL exception thrown when fetching data from cursor: '||
104+
ut_utils.remove_error_from_stack(sqlerrm,-19202)||chr(10)||'Check the query and data for errors.');
105105
when others then
106106
if l_cursor%isopen then
107107
close l_cursor;
@@ -117,7 +117,9 @@ create or replace type body ut_data_value_refcursor as
117117
dbms_lob.createtemporary(l_result, true);
118118
ut_utils.append_to_clob(l_result, 'Data-types:'||chr(10));
119119

120-
ut_utils.append_to_clob( l_result, self.cursor_details.get_xml_children().getclobval() );
120+
if self.cursor_details.cursor_columns_info.count > 0 then
121+
ut_utils.append_to_clob( l_result, self.cursor_details.get_xml_children().getclobval() );
122+
end if;
121123
ut_utils.append_to_clob(l_result,chr(10)||(self as ut_compound_data_value).to_string());
122124
l_result_string := ut_utils.to_string(l_result,null);
123125
dbms_lob.freetemporary(l_result);

test/core/expectations/test_expectations_cursor.pkb

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -972,18 +972,21 @@ Rows: [ 4 differences ]
972972
procedure reports_on_exception_in_cursor
973973
as
974974
l_actual sys_refcursor;
975-
l_error_code integer := -19202; --Error occurred in XML processing
975+
l_expected_message varchar2(32767);
976+
l_actual_message varchar2(32767);
976977
begin
977978
--Act
978979
open l_actual for select 1/0 as error_column from dual connect by level < 10;
979-
begin
980980
ut3.ut.expect(l_actual).to_be_empty();
981981
--Assert
982-
ut.fail('Expected '||l_error_code||' but nothing was raised');
983-
exception
984-
when others then
985-
ut.expect(sqlcode).to_equal(l_error_code);
986-
end;
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.]';
986+
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);
987990
end;
988991

989992
procedure exception_when_closed_cursor
@@ -2481,15 +2484,9 @@ Diff:%
24812484

24822485
ut3.ut.expect(v_actual).to_equal(v_expected);
24832486
--Assert
2484-
l_expected_message := q'[%Failed to process ref_cursor with error
2485-
%ORA-01722: invalid number
2486-
%Actual: refcursor [ count = ] was expected to equal: refcursor [ count = 1 ]
2487-
%Diff:
2488-
%Columns:
2489-
%Column <USD_PRICE_AMT> [data-type: NUMBER] is missing. Expected column position: 1.
2490-
%Column <UPDATE_ID> [data-type: VARCHAR2] is missing. Expected column position: 2.
2491-
%Rows: [ 1 differences ]
2492-
%Row No. 1 - Missing: <USD_PRICE_AMT>1357</USD_PRICE_AMT><UPDATE_ID>TEST_USER</UPDATE_ID>]';
2487+
l_expected_message := q'[%SQL exception thrown when fetching data from cursor:%
2488+
%ORA-01722: invalid number%
2489+
%Check the query and data for errors.]';
24932490

24942491
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
24952492
--Assert
@@ -2512,15 +2509,9 @@ Diff:%
25122509

25132510
ut3.ut.expect(v_actual).to_equal(v_expected);
25142511
--Assert
2515-
l_expected_message := q'[%Failed to process ref_cursor with error
2516-
%ORA-01722: invalid number
2517-
%Actual: refcursor [ count = 1 ] was expected to equal: refcursor [ count = ]
2518-
%Diff:
2519-
%Columns:
2520-
%Column <USD_PRICE_AMT> [data-type: NUMBER] is missing. Expected column position: 1.
2521-
%Column <UPDATE_ID> [data-type: VARCHAR2] is missing. Expected column position: 2.
2522-
%Rows: [ 1 differences ]
2523-
%Row No. 1 - Extra: <USD_PRICE_AMT>1357</USD_PRICE_AMT><UPDATE_ID>TEST_USER</UPDATE_ID>]';
2512+
l_expected_message := q'[%SQL exception thrown when fetching data from cursor:%
2513+
%ORA-01722: invalid number%
2514+
%Check the query and data for errors.]';
25242515

25252516
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
25262517
--Assert
@@ -2544,15 +2535,9 @@ Diff:%
25442535

25452536
ut3.ut.expect(v_actual).to_equal(v_expected);
25462537
--Assert
2547-
l_expected_message := q'[%Failed to process ref_cursor with error
2548-
%ORA-01722: invalid number
2549-
%Actual: refcursor [ count = 1 ] was expected to equal: refcursor [ count = ]
2550-
%Diff:
2551-
%Columns:
2552-
%Column <USD_PRICE_AMT> [data-type: NUMBER] is missing. Expected column position: 1.
2553-
%Column <UPDATE_ID> [data-type: VARCHAR2] is missing. Expected column position: 2.
2554-
%Rows: [ 1 differences ]
2555-
%Row No. 1 - Extra: <USD_PRICE_AMT>1357</USD_PRICE_AMT><UPDATE_ID>TEST_USER</UPDATE_ID>]';
2538+
l_expected_message := q'[%SQL exception thrown when fetching data from cursor:%
2539+
%ORA-01722: invalid number%
2540+
%Check the query and data for errors.]';
25562541

25572542
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
25582543
--Assert

0 commit comments

Comments
 (0)