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
Adding handling of xml error
  • Loading branch information
lwasylow committed Mar 16, 2019
commit ad3ce1074ac0eb35516e581f4a44f3335fb69bfe
8 changes: 5 additions & 3 deletions source/expectations/data_values/ut_data_value_refcursor.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ create or replace type body ut_data_value_refcursor as
if l_cursor%isopen then
close l_cursor;
end if;
ut_expectation_processor.report_failure_no_caller('Failed to process ref_cursor with error'||chr(10)||
ut_utils.remove_error_from_stack(sqlerrm,-19202));
ut_expectation_processor.report_failure_no_caller('SQL exception thrown when fetching data from cursor: '||
ut_utils.remove_error_from_stack(sqlerrm,-19202)||chr(10)||'Check the query and data for errors.');
when others then
if l_cursor%isopen then
close l_cursor;
Expand All @@ -117,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: 19 additions & 34 deletions test/core/expectations/test_expectations_cursor.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -972,18 +972,21 @@ Rows: [ 4 differences ]
procedure reports_on_exception_in_cursor
as
l_actual sys_refcursor;
l_error_code integer := -19202; --Error occurred in XML processing
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;
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;
--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);
end;

procedure exception_when_closed_cursor
Expand Down Expand Up @@ -2481,15 +2484,9 @@ Diff:%

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

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

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

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

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

l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
--Assert
Expand Down